1
$\begingroup$

I am trying to run multinomial naive bayes on a series of examples in python using sci kit learn. I am consitently getting all examples classified as negative. (The ratio of positives to negatives in my training set is ~1:3) Is there a way in sklearn to bias toward positive examples? I have coded it as follows:

from sklearn.datasets import load_svmlight_file
from sklearn.naive_bayes import MultinomialNB
from sklearn.metrics import accuracy_score
from sklearn.metrics import recall_score
from sklearn.metrics import precision_score
X_train, y_train= load_svmlight_file("POS.train")
x_test, y_test = load_svmlight_file("POS.val")
clf = MultinomialNB()
clf.fit(X_train, y_train)
preds = clf.predict(x_test)
print('accuracy: ' + str(accuracy_score(y_test, preds)))
 print('precision: ' + str(precision_score(y_test, preds)))
 print('recall: ' + str(recall_score(y_test, preds)))
$\endgroup$
2
$\begingroup$

Check out the preprocessing module in sklearn link

Specifically see the scaling and centering features.

Alternatively, you could try setting the class_prior argument.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.