鏀寔鍚戦噺鏈?SVM - Wenjing
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了鏀寔鍚戦噺鏈?SVM - Wenjing相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/cloud' title='cloud'>cloud libs ccf tle 鍥炲綊 绌洪棿 mod 璺濈
姒傚康
- 灏嗗悜閲忔槧灏勫埌涓€涓洿楂樼淮鐨勭┖闂撮噷锛屽湪杩欎釜绌洪棿閲屽缓绔嬫湁涓€涓渶澶ч棿闅旇秴骞抽潰銆傚湪鍒嗗紑鏁版嵁鐨勮秴骞抽潰鐨勪袱杈瑰缓鏈変袱涓簰鐩稿钩琛岀殑瓒呭钩闈紝鍒嗛殧瓒呭钩闈娇涓や釜骞宠瓒呭钩闈㈢殑璺濈鏈€澶у寲銆傚亣瀹氬钩琛岃秴骞抽潰闂寸殑璺濈鎴栧樊璺濊秺澶э紝鍒嗙被鍣ㄧ殑鎬昏宸秺灏忋€?/li>
- 鍩烘湰妯″瀷鏄畾涔夊湪鐗瑰緛绌洪棿涓婄殑闂撮殧鏈€澶х殑绾挎€у垎绫诲櫒
- SVM鐨勭殑瀛︿範绠楁硶灏辨槸姹傝В鍑镐簩娆¤鍒掔殑鏈€浼樺寲绠楁硶銆?/li>
鏁板鐞嗚
璇勪及鎸囨爣
1
2
3
4
5
6
7
8
9
10
11
12
13
from sklearn.model_selection import train_test_split
from sklearn.svm import SVC
X = df_feat
y = cancer['target']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)
model = SVC()
model.fit(X_train, y_train)
pred = model.predict(X_test)
from sklearn.metrics import classification_report, confusion_matrix
print(classification_report(y_test, pred))
print(confusion_matrix(y_test, pred))
- 浣跨敤Gri 澶т笓鏍?/a> 鏀寔鍚戦噺鏈?SVM - WenjingdSearchCV杩涜鑷姩璋冨弬
1
2
3
4
5
6
7
8
9
10
11
12
13
14
from sklearn.model_selection import train_test_split
from sklearn.svm import SVC
from sklearn.model_selection import GridSearchCV
param_grid = {'C': [0.1, 1, 10, 100, 1000], 'gamma': [1, 0.1, 0.01, 0.001, 0.0001]}
grid = GridSearchCV(SVC(), param_grid, verbose=3)
grid.fit(X_train, y_train)
grid.best_params_
grid.best_estimator_
grid_pred = grid.predict(X_test)
print(classification_report(y_test, grid_pred))
print(confusion_matrix(y_test, grid_pred))
鏁板鐭ヨ瘑琛ュ厖
以上是关于鏀寔鍚戦噺鏈?SVM - Wenjing的主要内容,如果未能解决你的问题,请参考以下文章
1
2
3
4
5
6
7
8
9
10
11
12
13
from sklearn.model_selection import train_test_split
from sklearn.svm import SVC
X = df_feat
y = cancer['target']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)
model = SVC()
model.fit(X_train, y_train)
pred = model.predict(X_test)
from sklearn.metrics import classification_report, confusion_matrix
print(classification_report(y_test, pred))
print(confusion_matrix(y_test, pred))
1 | from sklearn.model_selection import train_test_split |