我正在尝试拟合 numberOne
和 numberTwo
中的值,以便它符合 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
正如@Kevin评论中所说,fit
将列表作为输入,或者最好是 NumPy 数组,而不是标量。