Model_WIR

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值