当我试图将GridSearchCV
用于MLPClassifier
时:
from sklearn.neural_network import MLPClassifier
from sklearn.model_selection import GridSearchCV
from sklearn.datasets import make_classification
from numpy import logspace
X, y = make_classification(random_state=42)
mlp = MLPClassifier(solver="lbfgs", hidden_layer_sizes=(100,), random_state=1)
paramgrid = {
"estimator__alpha": logspace(-3, 2, 20),
}
mlpcv = GridSearchCV(mlp, paramgrid, cv=5)
mlpcv.fit(X, y)
print(mlpcv.best_params_)
但是我得到了这个消息:
ValueError: Invalid parameter 'estimator' for estimator
MLPClassifier(random_state=1, solver='lbfgs').
Valid parameters are: ['activation', 'alpha', 'batch_size',
'beta_1', 'beta_2', 'early_stopping', 'epsilon',
'hidden_layer_sizes', 'learning_rate', 'learning_rate_init',
'max_fun', 'max_iter', 'momentum', 'n_iter_no_change',
'nesterovs_momentum', 'power_t', 'random_state', 'shuffle', 'solver',
'tol', 'validation_fraction', 'verbose', 'warm_start'].
哪个参数有错误?
您正在对包含参数estimator__alpha
的paramgrid
进行网格搜索。
但是MLPClassifier没有这个参数。你应该改变你的paramgrid
.