【发布时间】:2018-01-14 04:43:25
【问题描述】:
我正在尝试使用此example 的 NN 模型。我正在将值列表拟合到 NN 模型。但是,我收到了AttributeError。以前有人问过这个问题并得到了回答。不幸的是,它对我不起作用。如示例所示,我创建了以下内容,
from keras.models import Sequential
from keras.wrappers.scikit_learn import KerasRegressor
from sklearn.model_selection import KFold
from sklearn.model_selection import cross_val_score
from keras.layers import Dense
def neuralnetmodel():
#Crete model
model = Sequential()
model.add(Dense(13, input_dim = 13, kernel_initializer = 'normal', activation = 'relu'))
model.add(Dense(1, kernel_initializer = 'normal', activation = 'relu'))
model.add(Dense(1, kernel_initializer = 'normal', activation = 'relu'))
## Output layer
model.add(Dense(1, kernel_initializer = 'normal'))
#Compile model
model.compile(loss = 'mean_squared_error', optimizer = 'adam')
return model
fit 训练数据,
NNmodelList = []
for i,j in zip(X_train_scaled,y_train):
nn_model = KerasRegressor(build_fn= neuralnetmodel, nb_epoch = 50, batch_size = 10, verbose = 0)
NNmodelList.append(nn_model.fit(i,j))
predict来自测试数据,
PredList = []
for val in X_test_scaled:
for mod in NNmodelList:
pred = mod.predict(val)
PredList.append(pred)
现在,我得到了错误:
AttributeError: 'History' 对象没有属性 'predict'
在之前的threads 中,似乎是训练集不是fit 到predict 之前的模型。但是,在我的情况下,我将它们放入第二个代码 sn-p 中。任何想法我正在犯什么其他可能的错误?
【问题讨论】:
-
我找到了github.com/fchollet/keras/issues/2379 这个,我在函数里面有我的
model.compile,我猜它正在做这项工作。仍然无法理解,我正在犯什么其他可能的错误。
标签: python list machine-learning neural-network keras