基本:
http://sklearn.apachecn.org/#/docs/5
超参数设置:
参考:
https://www.cnblogs.com/nwpuxuezha/p/6618205.html
https://www.cnblogs.com/huanping/p/9330849.html
def trysvm(trainx, trainy, testx, testy):
c_range = np.logspace(-5, 15, 11, base=2)
gamma_range = np.logspace(-9, 3, 13, base=2)
svc = SVC(kernel='rbf', class_weight='balanced' )
parameters=[{'kernel': ['rbf'], 'C': c_range, 'gamma': gamma_range}]
clf = GridSearchCV(svc, parameters, n_jobs=-1,cv=5)
clf.fit(trainx, trainy)
#把测试的超参数以及结果写入文件
cv_result = pd.DataFrame.from_dict(clf.cv_results_)
with open('cv_result.csv', 'w') as f:
cv_result.to_csv(f)