0

I need to get the projection matrix from lda, which has been supplied the train data, so that I can use that to project the train data in the lda space.

I have done the following :

def get_projection(features,label):

    transformer = LDA(store_covariance=True)
    transformer.fit_transform(features,label)   
    cov_mat = transformer.covariance_

    return cov_mat

I have then extracted the eigen vectors of the covariance matrix. But that doesn't seem to give correct solution. Even the .scalings_ attribute doesn't seem to be helpful. Kindly help me find the projection matrix from this method, so that I can apply it on test data, which don't have labels.

rj dj
  • 260
  • 1
  • 5
  • 22

1 Answers1

0

You can apply the transformer directly on test data by transformer.transform(test_data). See documentation of LDA here.

Note: LDA has been deprecated and now its recommended to use LinearDiscriminantAnalysis.

Vivek Kumar
  • 35,217
  • 8
  • 109
  • 132
  • Can you please tell me which attribute gives the projection matrix? – rj dj Mar 20 '18 at 11:52
  • The tranform() method internally uses dot product between the data and the `scalings_` to find the projection. Since you are using default LDA, you also need to subtract the means of the data before dot product. See the [source here](https://github.com/scikit-learn/scikit-learn/blob/ab93d65/sklearn/discriminant_analysis.py#L482) – Vivek Kumar Mar 20 '18 at 12:12