Order n_classes at LinearSVC.coef_
I am working with LinearSVC to classify text data into 3 classes. The inputs are tfidf word scores. I'm interested in seeing the "contribution" that words make to the classification. First question: can I use coef_ for this? The documentation states:
coef_: array, shape = [n_features] if n_classes == 2 else [n_classes, n_features]
So my guess is that "n_classes" corresponds to each of the three classes that documents can be classified into, and n_features corresponds to the coefficient values ββfor my tfidf functions. Assuming this is the case, what is the order of the classes in coef_? How can I match each string in an array to one of my classes?
thank,
Nick
source to share
Without digging into the source code, I believe there are two answers to your questions:
-
The classes are sorted. So, if you have classes ['a', 'b', 'C'] then your class order will be ['C', 'a', 'b']. (It might look strange, but do this list in Python and .sort (). That's the order.)
-
In most cases, an undocumented member of a class
LinearSVC().classes_
that contains the ordering used by the class (see this method documentation ).
source to share