我刚刚安装了scikit-learn v0.18开发包。
当我在iPython上调用以下内容时;
>>> from sklearn.neural_network import MLPClassifier
>>> clf = MLPClassifier(algorithm='l-bfgs', alpha=1e-5, hidden_layer_sizes=(5, 2), random_state=1)
没有错误。但是当我编写python脚本文件并在其上运行代码时,出现以下错误:
clf = MLPClassifier(algorithm='l-bfgs', alpha=1e-5, hidden_layer_sizes=(5, 2), random_state=1, warm_start=True)
TypeError: MLPClassifier() got an unexpected keyword argument 'algorithm'
我不知道问题出在哪里。如何修复此错误?
您需要
将algorithm
参数更改为solver
。请参阅该估算器的文档和 dev 存储库。
from sklearn.neural_network import MLPClassifier
clf = MLPClassifier(solver='l-bfgs', alpha=1e-5, hidden_layer_sizes=(5, 2), random_state=1, warm_start=True)
只需将algorithm
替换为solver
但是,当您将数据拟合在一行中时:
X,y = make_moons(n_samples=100, noise=0.25, random_state=3)
X_trian, X_test, y_train, y_test = train_test_split(X,y, stratify=y, random_state=42)
mlpc = MLPClassifier(solver='lbfgs', random_state=0).fit(X_train, y_train)
将l-bfgs
替换为lbfgs