简体   繁体   中英

Predicting values using trained MNB Classifier

I am trying to train a model for sentiment analysis and below is my trained Multinomial Naive Bayes Classifier returning an accuracy of 84%.

I have been unable to figure out how to use the trained model to predict the sentiment of a sentence. For example, I now want to use the trained model to predict the sentiment of the phrase "I hate you".

I am new to this area and any help is highly appreciated.

I don't know the dataset and what is semantic of individual dictionaries, but you are training your model on a dataset which has form as follows:

[[{"word":True, "word2": False}, 'neg'], [{"word":True, "word2": False}, 'pos']]

  • That means your input is in form of a dictionary, and output in form of 'neg' label. If you want to predict you need to input a dictionary in a form:

{"I": True, "Hate": False, "you": True} .

  • Then:

MNB_classifier.classify({"love": True})

>> 'neg'

or MNB_classifier.classify_many([{"love": True}])

>> ['neg']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM