Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from sklearn.model_selection import train_test_split
- from sklearn.feature_extraction.text import CountVectorizer
- from sklearn.naive_bayes import MultinomialNB
- df['mixed_feature'] = df['Text'] +' '+ df['Topic']
- X_train, X_test, y_train, y_test = train_test_split(df['mixed_feature'], df['Sentiment'], test_size=0.2)
- count_vect = CountVectorizer()
- X_train_counts = count_vect.fit_transform(X_train)
- tfidf_transformer = TfidfTransformer()
- X_train_tfidf = tfidf_transformer.fit_transform(X_train_counts)
- clf = MultinomialNB().fit(X_train_tfidf, y_train)
- clf.predict(count_vect.transform([df['Text][i]])) ## For whatever text is in row i
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement