IndexError: boolean index did not match indexed array along dimension 0; dimension is 100 but corresponding boolean dimension is 101
#注意看我y和X这两行的注释:要么全是df.loc,要么全是df.iloc,核对一下自己代码
import matplotlib.pyplot as plt
import numpy as np
y = df.loc[0:100, 4].values #loc/iloc得统一
y = np.where(y == 'Iris-setosa', -1, 1)
#抽出第0列和第2列
X = df.loc[0:100, [0, 2]].values # loc/iloc得统一
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')
plt.xlabel('花瓣长度')
plt.ylabel('花茎长度')
plt.legend(loc='upper left')
#plt.show()