這是什么原因???
F:\Program Files\Python\lib\site-packages\ipykernel\__main__.py:26: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 100 but corresponding boolean dimension is 101
---------------------------------------------------------------------------IndexError ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Traceback (most recent call last)<ipython-input-116-caffccb593cb> in <module>()----> 1 plot_decision_regions(X,y,ppn,resolution=0.02) ? ? ?2 plt.xlabel('len1') ? ? ?3 plt.ylabel('len2') ? ? ?4 plt.legend(loc='upper left') ? ? ?5 plt.show()<ipython-input-115-d79b122b313a> in plot_decision_regions(X, y, classifier, resolution) ? ? 24 ?? ? 25 ? ? for idx,c1 in enumerate(np.unique(y)):---> 26 ? ? ? ? plt.scatter(x=X[y==c1,0],y=X[y==c1,1],alpha=0.8,c=cmap(idx),marker=markers[idx],label=c1) ? ? 27 IndexError: index 100 is out of bounds for axis 0 with size 100
2018-07-23
請問解決了嗎?
2018-07-12
我是這樣改的:
import matplotlib.pyplot as plt
import numpy as np
y = df.loc[0:99, 4].values
y = np.where(y == 'Iris-setosa', -1, 1)
#print(y)
X = df.iloc[0:100, [0, 2]].values
#print(X)
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='vericolor')
plt.rcParams['font.sans-serif']=['SimHei']
plt.xlabel('花瓣長度')
plt.ylabel('花莖長度')
plt.legend(loc='upper left')
plt.show()
另外,還有一處會報錯,makers這,改成maker:
?for idx, cl in enumerate(np.unique(y)):
? ? ? ? plt.scatter(x=X[y==cl, 0], y=X[y==cl, 1], alpha=0.8, c=cmap(idx), marker=marker[idx], label=cl)
2017-12-14
目前找到的問題是X[y==cl, 0]報的錯,X的數(shù)據(jù)是[[ 5.1 ?1.4]...[ 5.7 ?4.1]]這種類型的
y的如果cl的值[-1,1],當(dāng)循環(huán)第一次的時候 cl = -1
y==-1 得到了一組boolean [true...flase]的數(shù)據(jù)
最終的數(shù)據(jù)應(yīng)該是X[boolean, -1]這樣的
以上僅為猜測,我也碰到這個問題,目前真正尋找解決辦法。
2017-11-21
你參考一下這個,希望對你有幫助。https://stackoverflow.com/questions/32198064/pandas-indexerror-for-large-dataframe