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

+3


source to share


2 answers


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 ).

0


source


I would like to know what does [n_classes, n_features] mean? The "coef_" results are a matrix with 3 * n_features if n_classes is 3. But how do I understand each row of a matrix with 3 * n_features? Many thanks.



0


source







All Articles