4

以下代码

print "X type", type(X_all2)
print "X shape", np.shape(X_all2)

print "Y type", type(y_all2)
print "Y shape", np.shape(y_all2)

y_all2 = np.reshape(y_all2, (395, 1))

print "Y type", type(y_all2)
print "Y shape", np.shape(y_all2)

from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
lda = LinearDiscriminantAnalysis(n_components=2)
X_r = lda.fit(X_all2, y_all2).transform(X_all2)

print "R type", type(X_r)
print "R shape", np.shape(X_r)

返回以下内容:

X type <type 'numpy.ndarray'>
X shape (395, 48)
Y type <type 'numpy.ndarray'>
Y shape (395,)
Y type <type 'numpy.ndarray'>
Y shape (395, 1)
R type <type 'numpy.ndarray'>
R shape (395, 1)

lda.fit()返回 1 列,尽管它说n_components=2

为什么以及如何强制返回 2 列?

文档在这里:http ://scikit-learn.org/stable/modules/generated/sklearn.discriminant_analysis.LinearDiscriminantAnalysis.html#sklearn.discriminant_analysis.LinearDiscriminantAnalysis

4

0 回答 0