无法克隆对象<;0x7f9d95dd50f0处的keras.wrappers.scikit_learn.KerasClassifier对象>;,因为构造函数没有设置

无法克隆对象<;0x7f9d95dd50f0处的keras.wrappers.scikit_learn.KerasClassifier对象>;,因为构造函数没有设置,keras,scikit-learn,grid-search,gridsearchcv,Keras,Scikit Learn,Grid Search,Gridsearchcv,我得到这个运行时错误:无法克隆对象,因为构造函数没有设置或修改参数batch\u size 在深度学习中执行gridsearch时,Jason Bownley # MLP for Pima Indians Dataset with grid search via sklearnfrom keras.models import Sequential from keras.layers import Dense from keras.wrappers.scikit_learn import Kera

我得到这个运行时错误:无法克隆对象,因为构造函数没有设置或修改参数batch\u size 在深度学习中执行gridsearch时,Jason Bownley

# MLP for Pima Indians Dataset with grid search via sklearnfrom keras.models import Sequential
from keras.layers import Dense
from keras.wrappers.scikit_learn import KerasClassifier
from sklearn.model_selection import StratifiedKFold
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import GridSearchCV
import numpy
# MLP for Pima Indians Dataset with 10-fold cross validation via sklearn
from keras.models import Sequential
from keras.layers import Dense
from keras.wrappers.scikit_learn import KerasClassifier
from sklearn.model_selection import StratifiedKFold
from sklearn.model_selection import cross_val_score
import numpy
# MLP for Pima Indians Dataset with 10-fold cross validation via sklearn
from keras.models import Sequential
from keras.layers import Dense
from keras.wrappers.scikit_learn import KerasClassifier
from sklearn.model_selection import StratifiedKFold
from sklearn.model_selection import cross_val_score
import numpy
# Function to create model, required for KerasClassifier
def create_model(optimizer= 'rmsprop' , init= 'glorot_uniform'):
    # create model
    model = Sequential()
    model.add(Dense(12, input_dim=8, kernel_initializer= 'uniform' , activation= 'relu' )) 
    model.add(Dense(8, kernel_initializer = 'uniform' , activation= 'relu' )) 
    model.add(Dense(1, kernel_initializer = 'uniform' , activation= 'sigmoid' )) 
    # Compile model
    model.compile(loss= 'binary_crossentropy' , optimizer= 'adam' , metrics=['accuracy'])
    return model
# fix random seed for reproducibility
seed = 7
numpy.random.seed(seed)
# load pima indians dataset
from google.colab import drive
drive.mount('/content/drive')
dataset = numpy.loadtxt("/content/drive/My Drive/Colab Notebooks/pima-indians-diabetes.csv", delimiter=",", skiprows=1)
# split into input (X) and output (Y) variables
X = dataset[:,0:8]
Y = dataset[:,8]
# create model
model = KerasClassifier(build_fn=create_model, verbose=0)
# grid search epochs, batch size and optimizer
optimizers = [ 'rmsprop' , 'adam']
init = [ 'glorot_uniform' , 'normal' , 'uniform']
epochs = numpy.array([50, 100, 150])
batches = numpy.array([5, 10, 20])
param_grid = dict(optimizer=optimizers, nb_epoch=epochs, batch_size=batches, init=init)
grid = GridSearchCV(estimator=model, param_grid=param_grid)
grid_result = grid.fit(X, Y)
# summarize results
print("Best: %f using %s" % (grid_result.best_score_, grid_result.best_params_))
for params, mean_score, scores in grid_result.grid_scores_:
    print("%f (%f) with: %r" % (scores.mean(), scores.std(), params))
运行时错误回溯(最近一次调用)
....
--->56网格结果=网格拟合(X,Y)
RuntimeError:无法克隆对象,因为构造函数未设置或修改参数nb_

我遇到了这个问题,通过将numpy.array更改为列表解决了这个问题。e、 g

batches = [5, 10, 20]

总之,使用列表(就像您对优化器、init等所做的那样)而不是numpy.array

我遇到了这个问题,通过将numpy.array更改为列表解决了这个问题。e、 g

batches = [5, 10, 20]
总之,使用列表(如优化器、init等)而不是numpy.array