问答详情
源自:3-5 神经网络对数据实现分类(下)

error

IndexError: boolean index did not match indexed array along dimension 0; dimension is 100 but corresponding boolean dimension is 101

提问者:qq_慕无忌9118984 2021-06-03 17:38

个回答

  • weixin_慕尼黑7100639
    2022-05-27 15:14:26

    #注意看我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()