Why am i getting AttributeError: 'KerasClassifier' object has no attribute 'model'?

前端 未结 2 1469
时光说笑
时光说笑 2021-01-11 22:51

This is the code and I\'m getting the error in the last line only which is y_pred = classifier.predict(X_test). The error I\'m getting is AttributeError:

2条回答
  •  Happy的楠姐
    2021-01-11 23:31

    Because you haven't fitted the classifier yet. For classifier to have the model variable available, you need to call

    classifier.fit(X_train, y_train)
    

    Although you have used cross_val_score() over the classifier, and found out accuracies, but the main point to note here is that the cross_val_score will clone the supplied model and use them for cross-validation folds. So your original estimator classifier is untouched and untrained.

    You can see the working of cross_val_score in my other answer here

    So put the above mentioned line just above y_pred = classifier.predict(X_test) line and you are all set. Hope this makes it clear.

提交回复
热议问题