X, y = make_moons(n_samples=100, noise=0.25, random_state=3)
X_train, X_test, y_train, y_test = train_test_split(X, y, stratify=y, random_state=42)
mlp = MLPClassifier(solver='lbfgs', random_state=0).fit(X_train, y_train)
mglearn.plots.plot_2d_separator(mlp, X_train, fill=True, alpha=.3)
mglearn.discrete_scatter(X_train[:, 0], X_train[:, 1], y_train)
plt.xlabel("Feature 0")
plt.ylabel("Feature 1")
提示错误,但是很难理解。MLPClassifier怎么可能没有decision_function()呢,不应该啊。求解。
Traceback (most recent call last):
File "C:\pycharm_project\myproject\lib\site-packages\mglearn\plot_2d_separator.py", line 86, in plot_2d_separator
decision_values = classifier.decision_function(X_grid)
AttributeError: 'MLPClassifier' object has no attribute 'decision_function'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/pycharm_project/ai_algorithm/p83_mlp_paras_moons.py", line 13, in <module>
mglearn.plots.plot_2d_separator(mlp, X_train, fill=True, alpha=.3)
File "C:\pycharm_project\myproject\lib\site-packages\mglearn\plot_2d_separator.py", line 92, in plot_2d_separator
decision_values = classifier.predict_proba(X_grid)[:, 1]
File "C:\pycharm_project\myproject\lib\site-packages\sklearn\neural_network\_multilayer_perceptron.py", line 1072, in predict_proba
y_pred = self._predict(X)
File "C:\pycharm_project\myproject\lib\site-packages\sklearn\neural_network\_multilayer_perceptron.py", line 685, in _predict
self._forward_pass(activations)
File "C:\pycharm_project\myproject\lib\site-packages\sklearn\neural_network\_multilayer_perceptron.py", line 103, in _forward_pass
activations[i + 1] = safe_sparse_dot(activations[i],
File "C:\pycharm_project\myproject\lib\site-packages\sklearn\utils\extmath.py", line 151, in safe_sparse_dot
ret = a @ b
MemoryError: Unable to allocate 763. MiB for an array with shape (1000000, 100) and data type float64