请有人说明以下代码为什么会出现属性错误?

from sklearn.model_selection import cross_val_score
from keras.models import Sequential
from keras.layers import Dense

def build_classifier():   #one of the parameter for KerasClassifier
    classifier = Sequential() #initialising ANN by defining sequence of layers
    classifier.add(Dense(units=6,activation='relu',kernel_initializer='uniform',input_dim=11))
    classifier.add(Dense(units=6,activation='relu',kernel_initializer='uniform'))
    classifier.add(Dense(units=1,activation='sigmoid',kernel_initializer='uniform'))
    #compiling the ANN
    classifier.compile(optimizer = 'adam',loss = 'binary_crossentropy',
                      metrics=['accuracy'])
    return classifier

#fitting model for k-fold cross validation
classifier = KerasClassifier(buil_fn = build_classifier,nb_epochs = 100,
                            batch_size=10)  ```

最佳答案

您有错字:buil_fn应该是build_fn

另外,nb_epochs应该是nb_epoch

#fitting model for k-fold cross validationclassifier = KerasClassifier(build_fn = build_classifier,nb_epoch = 100, batch_size=10)

关于python - 为什么会出现“AttributeError:'KerasClassifier'对象没有属性'__call__'?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59345295/

10-11 10:54