There are two main topics here. One is the basic models, the other is model seletion part.
Naive bayes
# fit the training dataset on the NB classifier
Naive = naive_bayes.MultinomialNB()
Naive.fit(Train_X_Tfidf,Train_Y)
# predict the labels on validation dataset
predictions_NB = Naive.predict(Test_X_Tfidf)
# Use accuracy_score function to get the accuracy
print("Naive Bayes Accuracy Score -> ",accuracy_score(predictions_NB, Test_Y)*100)
SVM
SVM = svm.SVC(kernel='sigmoid',C=10,gamma=1)
SVM.fit(Train_X_Tfidf,Train_Y)
# predict the labels on validation dataset
predictions_SVM = SVM.predict(Test_X_Tfidf)
# Use accuracy_score function to get the accuracy
print("SVM Accuracy Score -> ",accuracy_score(predictions_SVM, Test_Y)*100)
Model Selection
from sklearn import svm
from sklearn.model_selection import GridSearchCV
X, y, nfolds = Train_X_Tfidf,Train_Y,10
Cs = [0.001, 0.01, 0.1, 1, 10]
kernel = ['linear','rbf', 'sigmoid']
gammas = [0.001, 0.01, 0.1, 1]
param_grid = {'C': Cs, 'gamma' : gammas,'kernel':kernel}
grid_search = GridSearchCV(svm.SVC(), param_grid, cv=nfolds)
grid_search.fit(X, y)
grid_search.best_params_
param_grid contains all the possible pre-defined hyperparameters for model seletion.
We will get the best hyperparameters for our model.