I know there is a library in python
from sklearn.naive_bayes import MultinomialNB
but I want to know how to create one from scratch without using libraries like TfIdfVectorizer and MultinomialNB?
I know there is a library in python
from sklearn.naive_bayes import MultinomialNB
but I want to know how to create one from scratch without using libraries like TfIdfVectorizer and MultinomialNB?
Here is the step-by-step about how to make simple MNB Classifier with TF-IDF
First, you need to import the method TfIdfVectorizer to tokenize the terms inside the dataset, the MultinomialNB as the classifier, and the train_test_split for splitting the dataset. (Both are available in sklearn).
Split the dataset into train and test sets.
Initialize the constructor of TfIdfVectorizer, then Vectorize/Tokenize the train set by the method fit_transform.
Vectorize/Fit the test set with the method fit.
Initialize the classifier by calling the constructor MultinomialNB().
model = MultinomialNB() # with default hyperparameters
model.fit(X_train, y_train)
model.predict(X_test, y_test)
Those 7 steps above are the simple steps. Apparently you can also do the text preprocessing and also model evaluation.