How To Use One-hot Encode While Using Naivebayes Algorithm?
I'm trying to use Naive Bayes algorithm for one of my requirements. In this, I have planned to use 'One-hot Encode' for hyper plane. I have used the following code for running my a
Solution 1:
try using CountVectorizer
from sklearn.feature_extraction.text import CountVectorizer
clf = CountVectorizer()
X_train_one_hot = clf.fit(X_train)
X_test_one_hot = clf.transform(X_test)
bnbc = BernoulliNB(binarize=None)
bnbc.fit(X_train_one_hot, y_train)
score = bnbc.score(X_test_one_hot, y_test)
print("score of Naive Bayes algo is :" , score)
Also you can try using TfidfVectorizer in case if you are going to use TfIdf featurization of text.
Post a Comment for "How To Use One-hot Encode While Using Naivebayes Algorithm?"