SKlearn has a couple naive bayes classifiers, namely BinomialNB, and MultinomialNB. In both cases, the coef_ variable returns the importance weights for each feature. When there are 3 classes, coef_ is of size 3xn, 4 classes, 4xn, etc.. However, when it is a 2 class problem coef_ is 1xn. Here is the code snippet:
return (self.feature_log_prob_[1:]
if len(self.classes_) == 2 else self.feature_log_prob_)
The returned coefficients are only the ones pertaining to the second class. We can obviously get the coefficients by going to feature_log_prob
directly, but it shouldn't be necessary.
Why is this??