How to fix "ValueError: Expected 2D array, got 1D array instead"?
How to fix "ValueError: Expected 2D array, got 1D array instead"?
当运行:
scaler = StandardScaler().fit(train)
我收到这个错误:
enter image description here
之后我尝试了:
train = train.array.reshape(-1, 1)
我得到了:
AttributeError: 'list' object has no attribute 'array'
如何通过数据整形来修复值错误?
尝试train = np.array(train).reshape(-1, 1)
。
看来train
原来是一个列表。所以你必须使用 np.array()
将它转换成一个数组。然后,您可以使用 .reshape()
方法更改尺寸。 .reshape(-1, 1)
要求 numpy
创建一个只有一列的二维矩阵。 numpy
可以推断出该矩阵中的行数,因为您只需要一列。 -1
参数要求 numpy
推断第一个维度的长度。请参阅 this answer for a more complete understanding。
当运行:
scaler = StandardScaler().fit(train)
我收到这个错误:
enter image description here
之后我尝试了:
train = train.array.reshape(-1, 1)
我得到了:
AttributeError: 'list' object has no attribute 'array'
如何通过数据整形来修复值错误?
尝试train = np.array(train).reshape(-1, 1)
。
看来train
原来是一个列表。所以你必须使用 np.array()
将它转换成一个数组。然后,您可以使用 .reshape()
方法更改尺寸。 .reshape(-1, 1)
要求 numpy
创建一个只有一列的二维矩阵。 numpy
可以推断出该矩阵中的行数,因为您只需要一列。 -1
参数要求 numpy
推断第一个维度的长度。请参阅 this answer for a more complete understanding。