How to obtain feature weights of a trained LDA classifier

scikit-learn

Solution

You're right, `coef_` holds the weights (aka the coefficients), but the decision function is actually a bit more complicated than `w.T * x`, it's (paraphrasing from the source code):

X = np.dot(X - self.xbar_, self.scalings_)
return np.dot(X, self.coef_.T) + self.intercept_

so `X` is first centered and projected onto a smaller subspace (computed with a singular value decomposition in `fit`) before the linear threshold function is computed.

Problem

An LDA classifier multiplies an object feature vector with a feature weight vector, and with the resulting value the object class is predicted using a fixed threshold. Or w.x(o) > c, in which w is a feature weight vector, x(o) the feature vector of object o, and c the threshold. I would like to obtain the feature weights (w) from a trained LDA classifier using scikit-learn, and I was wondering if there is a function available for this? Looking at the code, I see two attributes, coef_ and scalings_, that mention feature weights. The description of coef_, "Coefficients of the features in the linear decision function", seems to correspond to what I am looking for, but I am not sure if this is correct. Does anyone now if this is the attribute I should use?

Original source