我正在使用 Perceptron 训练 iris 数据集并发现以下错误。
ValueError: The number of class labels must be greater than one.
下面的代码
y = df.iloc[0:100, 4].values
y = np.where(y== 'Iris-setosa', -1,1)
X = df.iloc[0:100, [0,2]].values
ppn = Perceptron(eta0=0.1, n_iter=10)
ppn.fit(X,y)
目标是使用物种类型的萼片长度和花瓣长度来拟合数据。 我不明白这个错误。我该如何纠正?
df.head() #for reference
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
0 5.1 3.5 1.4 0.2 setosa
1 4.9 3.0 1.4 0.2 setosa
2 4.7 3.2 1.3 0.2 setosa
3 4.6 3.1 1.5 0.2 setosa
最佳答案
您正在尝试预测在您的示例中只有一个值“setosa”的物种。您至少需要有不同的值(value)观。
关于python-3.x - 类标签的数量必须大于 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40821627/