dimension is 100 but corresponding boolean dimension is 101
IndexError? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Traceback (most recent call last)?
<ipython-input-45-a65b21b8df17> in <module>
?----> 1 plot_decision_regions(X,y,ppn,resolution=0.02)? ? ? ?
2 plt.xlabel('花徑長(zhǎng)度')? ? ? ?
3 plt.ylabel('花瓣長(zhǎng)度') ? ? ?
4 plt.legend(loc='upper left') ? ? ?
5 plt.show()
<ipython-input-44-85f310d48d44> in plot_decision_regions(X, y, classifier, resolution) ? ??
30 ?? ??
31 ? ? for idx,cl in enumerate(np.unique(y)):
---> 32 ? ? ? ? plt.scatter(x=X[y==cl,0],y=X[y==cl,1],alpha=0.8,c=cmap(idx),marker=marker[idx],label=cl)
IndexError: boolean index did not match indexed array along dimension 0; dimension is 100 but corresponding boolean dimension is 101
2020-07-20
望采納~~
2019-03-28
將y = df.loc[0:100, 4].values改為y = df.iloc[0:100, 4].values
看出區(qū)別了嗎?loc前面多個(gè)i。不然y的維度為101。
當(dāng)然你也可以直接改成y = df.loc[0:99, 4].values