为什么我会收到这个错误,LabelEncoder?

时间:2014-10-02 16:21:24

标签: python scikit-learn

我正在尝试调整来自numberOnenumberTwo的值,以便它适合LabelEncoder,我稍后将其用于train_test_split数据。但是我收到以下错误:

  

'bad input shape ()' It seems that the problem is on line le.fit(X)

我的代码:

from sklearn.cross_validation import train_test_split
from sklearn.preprocessing import LabelEncoder

numberOne = 9
numberTwo = 1

X = numberOne
y = numberTwo

le = preprocessing.LabelEncoder()
le.fit(X)
X = le.transform
print X

le = preprocessing.LabelEncoder()
le.fit(y)
y = le.transform
print y

1 个答案:

答案 0 :(得分:1)

正如@Kevin在评论中所说,fit将列表作为输入,或者最好是NumPy数组,而不是标量。