Created
May 21, 2017 15:17
-
-
Save Tathagatd96/fd616f734bce299f5b7f1502046a9127 to your computer and use it in GitHub Desktop.
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
#Classifier Training | |
clf=MultinomialNB().fit(X_train_tfidf,twenty_train.target) | |
docs_new=['God is love','OpenGL on the GPU is fast'] | |
X_new_counts=count_vect.transform(docs_new) | |
X_new_tfidf=tfidf_transformer.transform(X_new_counts) | |
predicted=clf.predict(X_new_tfidf) | |
for doc,category in zip(docs_new,predicted): | |
print('%r=>%s'%(doc,twenty_train.target_names[category])) | |
#Building a pipeline | |
text_clf=Pipeline([('vect',CountVectorizer()),('tfidf',TfidfTransformer()),('clf',MultinomialNB())]) | |
text_clf=text_clf.fit(twenty_train.data,twenty_train.target) | |
clf = Pipeline([ | |
('vec', CountVectorizer(analyzer=analyzer)), | |
('tfidf', TfidfTransformer(use_idf=False)), | |
('clf', LinearSVC(loss='l2', penalty='l1', dual=False, C=100)), | |
]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment