鏀寔鍚戦噺鏈?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))
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的主要内容,如果未能解决你的问题,请参考以下文章

鍏充簬璁粌闆?楠岃瘉闆?娴嬭瘯闆嗙殑鍒掑垎

鏈哄櫒瀛︿範瀹炴垬锛?锛夛細鏀寔鍚戦噺鏈猴紙涓嬶級

鍩轰簬璇嶅吀鍜屾湸绱犺礉鍙舵柉涓枃鎯呮劅鍊惧悜鍒嗘瀽绠楁硶

Python澶氱嚎绋嬩箣姝婚攣

璁﹔pc鏀寔鍙屽悜閫氫俊

寰俊app鏀粯python浠g爜瀹炵幇