Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么我会犯这个错误,LabelEncoder?_Python_Scikit Learn - Fatal编程技术网

Python 为什么我会犯这个错误,LabelEncoder?

Python 为什么我会犯这个错误,LabelEncoder?,python,scikit-learn,Python,Scikit Learn,我试图拟合numberOne和numberTwo中的值,以便它与LabelEncoder相匹配,稍后我将使用它来训练测试\u分割数据。但是,我得到以下错误: 'bad input shape()'问题似乎出在le.fit(X)行上。 我的代码: from sklearn.cross_validation import train_test_split from sklearn.preprocessing import LabelEncoder numberOne = 9 numberTwo =

我试图拟合
numberOne
numberTwo
中的值,以便它与
LabelEncoder
相匹配,稍后我将使用它来
训练测试\u分割数据。但是,我得到以下错误:

'bad input shape()'问题似乎出在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数组,而不是标量。

我对scikit了解不多,但我猜
fit
应该是一个列表。你给它一个整数。