How can we get the class labels (e.g., ['business','lifestyle','sports','tech']) from a classifier object? The classifier method predict
is able to produce the labels, so I guess it should be stored somewhere inside the classifier object.
I can't find it in the documentation (http://scikit-learn.org/stable/modules/generated/sklearn.svm.LinearSVC.html)
Anyone knows how to get the class labels?
Thanks!
There is a classes_
field.
>>> from sklearn import svm
>>> clt = svm.SVC()
>>> clt.fit( [[1],[2],[3]], ["a","b","a"] )
SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0, degree=3, gamma=0.0,
kernel='rbf', max_iter=-1, probability=False, shrinking=True, tol=0.001,
verbose=False)
>>> clt.classes_
array(['a', 'b'],
dtype='|S2')
I found it, it's hidden in the classes_
attribute of the object.
Found it after reading the source code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With