无法在适合 SVC 的情况下运行代码不知道是什么导致了问题,正在寻找适合 SVC 的解决方案,没有挂起或超时和跳过的方法。如果我做更多的评估,它就会挂起的可能性就越大。我必须重新启动 Jupyter notebook 内核才能再次运行代码。
def objective_func_svc(args):
if args['model']==SVC:
C = args['param']['C']
kernel = args['param']['kernel']
clf = SVC(C=C,kernel=kernel,gamma='auto')
clf.fit(X_train,y_train)
loss =1-clf.score(X_train,y_train)
return loss
space_svc = hp.choice('classifier',[
{'model': SVC,
'param':{'C':hp.lognormal('C',0.0,1),
'kernel':hp.choice('kernel',['poly', 'rbf', 'sigmoid'])}}])
print('\nKernel + C choice Score')
best_classifier = fmin(objective_func_svc,space_svc,algo=algoused,max_evals=max_evals)
if best_classifier.get('kernel')==0:
kernel='poly'
elif best_classifier.get('kernel')==1:
kernel='rbf'
elif best_classifier.get('kernel')==2:
kernel='sigmoid'
clf = SVC(C=best_classifier.get("C"),kernel=kernel,gamma='auto')
print('\nC=',best_classifier.get("C"))
print('kernel=',kernel)
print('\nBest_classifier Score ')
clf.fit(X_train,y_train)
y_pred=clf.predict(X_test)
clf.score(X_test,y_test)
a,p,n=print_confusion_matrix(y_test, y_pred)