When fitting an MLP neural network with scikit-learn’s MLPCLassifier
to the dataset iris this super-classic way:
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn import datasets
from sklearn.neural_network import MLPClassifier
iris = datasets.load_iris()
df = pd.DataFrame(data= np.c_[iris['data'], iris['target']],
columns= list(iris['feature_names']) + ['target'])
df.rename(columns={'sepal length (cm)': 'sepal length', 'sepal width (cm)': 'sepal width',
'petal length (cm)': 'petal length','petal width (cm)': 'petal width'}, inplace=True)
predictors = ['sepal length','sepal width','petal length','petal width']
outcome = 'target'
X = df[predictors]
y = df[outcome]
train_X, valid_X, train_y, valid_y = train_test_split(X, y, test_size=0.4, random_state=1)
clf = MLPClassifier(hidden_layer_sizes=(5), activation='relu', solver='lbfgs',
random_state=1, max_iter=200,
early_stopping=True) # <-- the required parameter!!
clf.fit(train_X, train_y)
clf.best_validation_score_
I get the following error message:
AttributeError: 'MLPClassifier' object has no attribute 'best_validation_score_'
as the attribute best_validation_score_
is NOT available.
According to the latest stable scikit-learn documentation here, the attribute best_validation_score_
should be available when the network’s instantiation is done with the parameter early_stopping=True
, as before.
Any explanation for that? Thanks.