亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

最后結果圖像不一樣呀

https://img1.sycdn.imooc.com//5c9f73140001092505930456.jpg


最后結果下面多了一條線?請問這種情況是怎么回事呀

正在回答

2 回答

from matplotlib.colors import ListedColormap

from?matplotlib.colors?import?ListedColormap

def?plot_decision_region(X,?y,?classifier,?resolution=0.02):
????colors?=?('red',?'blue',?'lightgreen',?'gray',?'cyan')
????cmap?=?ListedColormap(colors[:len(np.unique(y))])
????x1_min,?x1_max?=?X[:,?0].min()?-?1,?X[:,?0].max()
????x2_min,?x2_max?=?X[:,?1].min()?-?1,?X[:,?1].max()

????xx1,?xx2?=?np.meshgrid(np.arange(x1_min,?x1_max,?resolution),?np.arange(x2_min,?x2_max,?resolution))
????z?=?classifier.predict(np.array([xx1.ravel(),xx2.ravel()]).T)
????z?=?z.reshape(xx1.shape)
????plt.contourf(xx1,?xx2,?z,?alpha=0.4,?cmap=cmap)
????plt.xlim(xx1.min(),?xx1.max())
????plt.xlim(xx2.min(),?xx2.max())
????plt.scatter(X[:50,0],X[:50,1],color='red',marker='o',label='setosa')?????????
????plt.scatter(X[50:100,0],X[50:100,1],color='blue',marker='x',label='versicolor')
#?執行語句
plot_decision_regions(X,y,ppn,resolution=0.02)
plt.rcParams['font.sans-serif']?=?['SimHei']
plt.xlabel('花莖長度')
plt.ylabel('花瓣長度')
plt.legend(loc='upper?left')
plt.show()


1 回復 有任何疑惑可以回復我~
#?plt.plot(range(1,len(ppn.errors_)+1),ppn.errors_,marker='o')
#?plt.xlabel('Epochs')
#?plt.ylabel('錯誤分類次數')
#plt.show()

這些代碼注釋掉

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

最后結果圖像不一樣呀

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號