Python Sklearn变换错误:应为2D数组,改为1D数组
我使用sklearn使用此代码转换数据Python Sklearn变换错误:应为2D数组,改为1D数组,python,arrays,scikit-learn,Python,Arrays,Scikit Learn,我使用sklearn使用此代码转换数据 sc = MinMaxScaler() test= df['outcome'] y = sc.fit_transform(test) 它显示这样的错误 ValueError: Expected 2D array, got 1D array instead: array=[ 21000. 36000. 5000. ... 7000. 12000. 11000.]. Reshape your data either using array.res
sc = MinMaxScaler()
test= df['outcome']
y = sc.fit_transform(test)
它显示这样的错误
ValueError: Expected 2D array, got 1D array instead:
array=[ 21000. 36000. 5000. ... 7000. 12000. 11000.].
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.
如何修复它?MinMaxScaler要求numpy输入形状为(num\u示例,1)但您正在以形状(num\u示例,1)的形式进行输入。请尝试以下代码:
sc = MinMaxScaler()
test= df['outcome'].values #convert to numpy array
y = sc.fit_transform(test.reshape(-1,1))
如果我没记错的话,
MinMaxScalar
可以接受pandas数据帧
,但不能接受series
,所以只要做test=df[[['output']]
(一列数据帧)而不是test=df['output']
(一个系列)。尝试测试。重塑(len(test),1)
,然后应用fit\u变换。