0

I’m running LDA on a dataset and the outcome was good across all metrics. However I can’t seem to extract the top features or loadings like I can for PCA.

Is anyone familiar with extracting top features / loadings from LDA when using sklearn python3?

Ed_
  • 69
  • 8

1 Answers1

0

try this:

import numpy as np

from sklearn.discriminant_analysis import LinearDiscriminantAnalysis as LDA

X = training_input

y = training_label.ravel()

clf = LDA(n_components=1)

clf.fit(X, y)

clf.coef_

beste_Merkmal = np.argsort(clf.coef_)[0][::-1][0:25]

print('beste_Merkmal =', beste_Merkmal)
haxor789
  • 604
  • 6
  • 18
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 23 '22 at 02:49
  • @haxor789 Ausgezeichnet danke. My result for best feature is a little different than what I expected. I got [128 174 219 157 116 158 113 159 32 165 148 193 26 177 95 163 88 75 224 60 48 15 63 185 127]. Where I expected explicit string named variables. Would these be index numbers / or column numbers? thanks again – Ed_ Oct 21 '22 at 22:04