Created
August 24, 2013 14:14
-
-
Save sloria/6328382 to your computer and use it in GitHub Desktop.
textblob classification example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from text.classifiers import NaiveBayesClassifier | |
train = [ | |
('I love this sandwich.', 'pos'), | |
('This is an amazing place!', 'pos'), | |
('I feel very good about these beers.', 'pos'), | |
('This is my best work.', 'pos'), | |
("What an awesome view", 'pos'), | |
('I do not like this restaurant', 'neg'), | |
('I am tired of this stuff.', 'neg'), | |
("I can't deal with this", 'neg'), | |
('He is my sworn enemy!', 'neg'), | |
('My boss is horrible.', 'neg') | |
] | |
test = [ | |
('The beer was good.', 'pos'), | |
('I do not enjoy my job', 'neg'), | |
("I ain't feeling dandy today.", 'neg'), | |
("I feel amazing!", 'pos'), | |
('Gary is a friend of mine.', 'pos'), | |
("I can't believe I'm doing this.", 'neg') | |
] | |
cl = NaiveBayesClassifier(train) | |
print(cl.classify("This is an amazing library!")) | |
print(cl.accuracy(test)) | |
cl.update(test) | |
print(cl.accuracy(test)) | |
from text.blob import TextBlob | |
blob = TextBlob("I love the drinks here. However, the hangover is horrible.", | |
classifier=cl) | |
blob.classify() | |
for sen in blob.sentences: | |
print(sen.classify()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment