-2

I am using TextBlob i am training my classifier on a training set after that i am successfully able to get the classified out put

Bit how can i get the score of a particular text in terms of positive or negativity should i put scores of sentiments in my training data

here is what i have tried

from textblob import TextBlob
from textblob.classifiers import NaiveBayesClassifier
train = [
     ('I love this sandwich.', 'pos'),
     ('This is an amazing place!', 'pos'),
     ('I feel very good about these beers.', 'pos'),
     ('I do not like this restaurant', 'neg'),
     ('I am tired of this stuff.', 'neg'),
     ("I can't deal with this", 'neg'),
     ("My boss is horrible.", "neg")
 ]
cl = NaiveBayesClassifier(train)
 cl.classify("I feel amazing!")

Here is the output

'pos'

How can i get the score of this like pos .7 or in any other format

Mohd Maaz
  • 267
  • 5
  • 20

2 Answers2

1

You can do something like the following: source here

>>> prob_dist = cl.prob_classify("I feel amazing!")
>>> prob_dist.max()
'pos'
>>> round(prob_dist.prob("pos"), 2)
0.63
>>> round(prob_dist.prob("neg"), 2)
0.37
Jeril
  • 7,858
  • 3
  • 52
  • 69
1

You could also use the native texblob functionality with your own classifier:

blob = TextBlob('I feel amazing!', classifier=cl)
print (blob.sentiment.polarity)

output: 0.7500000000000001

Stein
  • 719
  • 7
  • 9