【发布时间】:2017-04-10 20:05:06
【问题描述】:
我正在使用 Perceptron 训练 iris 数据集并发现以下错误。
ValueError: 类标签的数量必须大于一。
代码如下
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
【问题讨论】:
-
请贴一个可重现的例子(我们不知道这个类
Perceptron来自哪里)。 -
问题出在你的数据框上。发布的代码很好。 @CarlosCordoba 它是来自 scipy.linear_model 的感知器类
-
是的@LukaszTracewski,数据框 y 具有所有相同的值,因为 y = np.where(y== 'Iris-setosa', -1,1) 并且没有像 'Iris- 这样的值setosa' 在我下载的新数据集中。愚蠢的我!!。谢谢
标签: python-3.x machine-learning anaconda spyder perceptron