为了账号安全,请及时绑定邮箱和手机立即绑定

网格搜索和交叉验证 SVM

网格搜索和交叉验证 SVM

qq_花开花谢_0 2021-08-14 13:41:48
我正在使用网格搜索的最佳参数对 10 倍交叉验证实施支持向量机,我需要了解预测结果为什么不同我在训练集上得到了两个准确度结果测试通知我需要训练集上最佳参数的预测结果以供进一步分析代码和结果如下所述。任何解释from __future__ import print_functionfrom sklearn import datasetsfrom sklearn.model_selection import train_test_splitfrom sklearn.model_selection import GridSearchCVfrom sklearn.metrics import classification_reportfrom sklearn.svm import SVCfrom sklearn.metrics import accuracy_scorefrom time import *from sklearn import metricsX=datascaled.iloc[:,0:13]y=datascaled['num']np.random.seed(1)# Split the dataset in two equal partsX_train, X_test, y_train, y_test = train_test_split(    X, y, test_size=0.3, random_state=0)# Set the parameters by cross-validationtuned_parameters =  [{'kernel': ['rbf'], 'gamma': [1e-2, 1e-3, 1e-4, 1e-5],                     'C': [0.001, 0.10, 0.1, 10, 25, 50, 100, 1000]},                    {'kernel': ['sigmoid'], 'gamma': [1e-2, 1e-3, 1e-4, 1e-5],                     'C': [0.001, 0.10, 0.1, 10, 25, 50, 100, 1000] },{'kernel': ['linear'], 'C': [0.001, 0.10, 0.1, 10, 25, 50, 100, 1000]}]              print()clf = GridSearchCV(SVC(), tuned_parameters, cv=10,                       scoring='accuracy')t0 = time()clf.fit(X_train, y_train)t = time() - t0print("Best parameters set found on development set:")print()print(clf.best_params_)print()print('Training accuracy')print(clf.best_score_)print(clf.best_estimator_)print()print()print('****Results****')svm_pred=clf.predict(X_train)#print("\t\taccuracytrainkfold: {}".format(metrics.accuracy_score(y_train, svm_pred)))print("=" * 52)print("time cost: {}".format(t))print()print("confusion matrix\n", metrics.confusion_matrix(y_train, svm_pred))print()print("\t\taccuracy: {}".format(metrics.accuracy_score(y_train, svm_pred)))print("\t\troc_auc_score: {}".format(metrics.roc_auc_score(y_train, svm_pred)))print("\t\tcohen_kappa_score: {}".format(metrics.cohen_kappa_score(y_train, svm_pred)))print()
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 250 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号