ValueError: Expected 2D array, got 1D array instead: array=[0. 2. 4. ... 2. 4. 3.]
ValueError: Expected 2D array, got 1D array instead: array=[0. 2. 4. ... 2. 4. 3.]
Test_train拆分:
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.30, random_state = 10)
测试列车值为:X_train = (36201, 32) X_test = (15516, 32) y_ train = (36201,) y_test = (15516,)
*
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
model_lda = LinearDiscriminantAnalysis()
model_lda.fit(y_train, X_train)
我得到的错误:
ValueError: Expected 2D array, got 1D array instead:
array=[0. 2. 4. ... 2. 4. 3.].
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.
尽量写一个最小的、可重现的例子。它对解决错误有很大帮助。
查看您的 model_lda.fit
,X 和 y 应该倒置:
model_lda.fit(X_train, y_train)
.
您可以查看 LinearDiscriminantAnalysis
here 的文档。
Test_train拆分:
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.30, random_state = 10)
测试列车值为:X_train = (36201, 32) X_test = (15516, 32) y_ train = (36201,) y_test = (15516,)
*
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
model_lda = LinearDiscriminantAnalysis()
model_lda.fit(y_train, X_train)
我得到的错误:
ValueError: Expected 2D array, got 1D array instead: array=[0. 2. 4. ... 2. 4. 3.].
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.
尽量写一个最小的、可重现的例子。它对解决错误有很大帮助。
查看您的 model_lda.fit
,X 和 y 应该倒置:
model_lda.fit(X_train, y_train)
.
您可以查看 LinearDiscriminantAnalysis
here 的文档。