赞
踩
成功解决AttributeError: 'function' object has no attribute 'fit'
目录
- sns.distplot(data_frame[cols[0]],
- ax = axes[0],
- kde = False, norm_hist = False,
- rug = True,
- # fit=norm, # fit 可结合scipy库在图像上做拟合,拟合标准正态分布
- vertical = False,
- label='dis',
- )
-
- File "F:\Python36\lib\site-packages\seaborn\distributions.py", line 2641, in distplot
- params = fit.fit(a)
- AttributeError: 'function' object has no attribute 'fit'
属性错误:“function”对象没有“fit”属性
经过查看库版本,发现并非包版本问题导致!
相关文章:Python编程语言学习:输出一个类或者实例化对象的所有属性和方法名_一个处女座的程序猿的博客-CSDN博客_python输出类的实例
经过查询,当前model不支持该方法,故需要对当前model进行修改,或者添加该属性!
因为本代码时自定义的model,故添加了以下代码即可!
model.fit(x_train, y_train, epochs=1, batch_size=1, verbose=1)
- def fit():
- global batch_size
- pred,_=lstm(batch_size) #调用的构建的lstm变量
- loss=tf.reduce_mean(tf.square(tf.reshape(pred,[-1])-tf.reshape(Y, [-1])))
- train_op=tf.train.AdamOptimizer(lr).minimize(loss)
-
- saver=tf.train.Saver(tf.global_variables())
- print('saver:',saver)
- with tf.Session() as sess:
- sess.run(tf.global_variables_initializer())
- for i in range(10000):
- step=0
- start=0
- end=start+batch_size
- while(end<len(train_x)):
- _,loss_=sess.run([train_op,loss],feed_dict={X:train_x[start:end],Y:train_y[start:end]})
- start+=batch_size
- end=start+batch_size
- if step%10==0:
- saver.save(sess,'model/stock.model') # model/ checkpoint
- # print("已保存模型:",i,step,loss_)
- step+=1
- if i%100==0:
- print("当前步数:",i)
'运行
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。