4

The following code

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)

Returns following:

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)

I.e. lda.fit() returns 1 column despite it is said n_components=2.

Why and how to force to return 2 columns?

Doc is here: http://scikit-learn.org/stable/modules/generated/sklearn.discriminant_analysis.LinearDiscriminantAnalysis.html#sklearn.discriminant_analysis.LinearDiscriminantAnalysis

Dims
  • 47,675
  • 117
  • 331
  • 600
  • Is there a reason for the first y to have a shape like this: `Y shape (395,)`? – ahajib Jul 21 '16 at 21:38
  • It is generated from `pandas` object and appears this way. I don't know why, this is precondition. Anyway I eliminate this property by `reshape`. – Dims Jul 22 '16 at 13:23
  • There might be something wrong with that. Have you tried to print its elements just to make sure everything is fine with that array? – ahajib Jul 22 '16 at 13:46
  • I experience the same error but I also get a warning `Variables are collinear`, ie the _within-scatter_ matrix does not have full rank. Maybe, its coming from there. – romeasy Feb 10 '17 at 12:36

0 Answers0