Matplotlib 利用make_分类数据集从mlpclassizer绘制三维决策边界

Matplotlib 利用make_分类数据集从mlpclassizer绘制三维决策边界,matplotlib,scikit-learn,Matplotlib,Scikit Learn,我使用sklearn的make_分类库和MLP分类器。然而,我不能像上一篇那样把我的观点分开。这就是我的情节。你能帮我把要点分开吗?还是有什么问题 我的代码是: from sklearn.datasets import make_classification X,y=make_classification(n_samples=550, n_features=10, n_informative=2,random_state=0) from sklearn.model_selection impo

我使用sklearn的make_分类库和MLP分类器。然而,我不能像上一篇那样把我的观点分开。这就是我的情节。你能帮我把要点分开吗?还是有什么问题

我的代码是:

from sklearn.datasets import make_classification
X,y=make_classification(n_samples=550, n_features=10, n_informative=2,random_state=0)

from sklearn.model_selection import train_test_split
X_train,X_test , y_train , y_test = train_test_split(X, y, test_size=0.3, random_state=1)


from sklearn.neural_network import MLPClassifier
mlp= MLPClassifier(hidden_layer_sizes=(), max_iter=300, random_state=0)
    
clf = mlp.fit(X_test, y_test)

z = lambda x,y: (-clf.intercepts_[0]-clf.coefs_[0][0]*x -clf.coefs_[0][1]*y) / clf.coefs_[0][2]
                  
tmp = np.linspace(-5,5,30)
x,y = np.meshgrid(tmp,tmp)

fig = plt.figure()
ax  = fig.add_subplot(111, projection='3d')

ax.scatter(X_test[y_test==0,0]+2, X_test[y_test==0,1]-2, X_test[y_test==0,2]-5, c='b', marker='^')
ax.scatter(X_test[y_test==1,0]-2, X_test[y_test==1,1]+2, X_test[y_test==1,2]+5, c='r', marker='o')

ax.plot_surface(x, y, z(x,y))
ax.view_init(30, 60)
plt.show()
你的代码没有(严重)错误。你需要设置一些参数来得到你想要的。首先,你可能需要更大的数字

# To set figure size other than the default value, specify width and height
fig = plt.figure( figsize=(8,8) )
其次,对于
scatter()
函数中标记的大小:

# To set marker size, use `s=number` as an option
ax.scatter(X_test[y_test==0,0]+2, X_test[y_test==0,1]-2, X_test[y_test==0,2]-5, \
    c='b', marker='^', s=3)
ax.scatter(X_test[y_test==1,0]-2, X_test[y_test==1,1]+2, X_test[y_test==1,2]+5, \
    c='r', marker='o', s=3)
绘图应与此类似:

您的代码没有(严重)错误。你需要设置一些参数来得到你想要的。首先,你可能需要更大的数字

# To set figure size other than the default value, specify width and height
fig = plt.figure( figsize=(8,8) )
其次,对于
scatter()
函数中标记的大小:

# To set marker size, use `s=number` as an option
ax.scatter(X_test[y_test==0,0]+2, X_test[y_test==0,1]-2, X_test[y_test==0,2]-5, \
    c='b', marker='^', s=3)
ax.scatter(X_test[y_test==1,0]-2, X_test[y_test==1,1]+2, X_test[y_test==1,2]+5, \
    c='r', marker='o', s=3)
绘图应与此类似: