KerasRegression模型中的“ TypeError:无法腌制NotImplementedType对象”

时间:2018-07-17 21:38:49

标签: python machine-learning keras regression

我正在Keras中创建一个简单的回归神经网络。但是,当我尝试按以下方式运行

   seed = 7
   numpy.random.seed(seed)

   dataset = numpy.loadtxt("instancesFipo.txt", delimiter=", ")
   #testset = numpy.loadtxt("instancesFipo6.txt", delimiter=", ")

   Xtrain = dataset[:,0:8] #All rows, first 8 columns
   Ytrain = dataset[:,8]  #All rows, 9th column

   model = Sequential()

   #Create layers of neural net
   model.add(Dense(50, input_dim=8, kernel_initializer='normal', 
   activation='relu'))
   model.add(Dense(50, kernel_initializer='normal', activation='relu'))
   model.add(Dense(1, kernel_initializer='normal'))

   #Create loss function and algorithm
   model.compile(loss='mean_squared_error', optimizer='adam') 

   estimator = KerasRegressor(build_fn=model, epochs=100, batch_size=10, verbose=0)

   kfold = KFold(n_splits=10, random_state=seed)

   results = cross_val_score(estimator, Xtrain, Ytrain, cv=kfold)
   print("Results: %.2f (%.2f) MSE" % (results.mean(), results.std()))

我收到“ TypeError:无法腌制NotImplementedType对象”,这是由于调用cross_val_score引起的。不知道发生了什么。任何帮助将不胜感激,谢谢!

0 个答案:

没有答案