Created
February 25, 2013 12:40
-
-
Save oyvindse/5029559 to your computer and use it in GitHub Desktop.
Describe_me
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
#!/usr/bin/python | |
import sys | |
from numpy import loadtxt | |
import numpy as np | |
from sklearn.feature_extraction.text import CountVectorizer | |
from sklearn.feature_extraction.text import TfidfTransformer | |
from sklearn.naive_bayes import MultinomialNB | |
from sklearn.pipeline import Pipeline | |
my_data = loadtxt(sys.argv[1], delimiter='\t', dtype='S') | |
my_test_data = loadtxt(sys.argv[2], delimiter='\t', dtype='S') | |
text_clf = Pipeline([ | |
('vect', CountVectorizer()), | |
('tfidf', TfidfTransformer()), | |
('clf', MultinomialNB()), | |
]) | |
print("Training...") | |
my_clf = text_clf.fit(my_data[:,4], my_data[:,3]) | |
print("Done! \nClassifying test set...") | |
predicted = my_clf.predict(my_test_data[:,4]) | |
print(np.mean(predicted == my_test_data[:,3])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment