## Scale the data from sklearn.preprocessing import MinMaxScaler mms = MinMaxScaler() AB_train_mms = mms.fit_transform(AB_train) AB_test_mms = mms.transform(AB_test) ###WS_SVM: best params of WS_SVM {'c1': 0.1, 'c2': 0.0001, 'c3': 10.0} from WS_SVM_class import WS_SVM start_time = time.time() clf2 = WS_SVM(c1=0.1, c2=0.0001, c3=10) clf2.fit(AB_train_mms, y_train) end_time = time.time() print('Total runtime of WS_SVM: %s' % ((end_time - start_time))) y_pred_WS_SVM = clf2.predict(AB_test_mms) print('accuracy of WS_SVM: %s' % (100 * np.mean(y_pred_WS_SVM == y_test)), clf2.score(AB_test_mms, y_test)) ###Cross validation score of WS_SVM from sklearn.model_selection import cross_val_score scores = cross_val_score(estimator=clf2, X=AB_train_mms, y=y_train, cv=10, n_jobs=1) #print('CV accuracy scores of WS_SVM: %s' %scores) print('CV accuracy of WS_SVM: %.3f +/- %.3f' % (np.mean(scores), np.std(scores))) ### S_TWSVM: best params of S_TWSVM {'c1': 0.1, 'c2': 10.0, 'c3': 10.0} from S_TWSVM_class import S_TWSVM start_time = time.time() clf3 = S_TWSVM(c1=0.1, c2=10, c3=10)
AB_test_std = stdsc.transform(AB_test) from sklearn.preprocessing import MinMaxScaler mms = MinMaxScaler() AB_train_mms = mms.fit_transform(AB_train) AB_test_mms = mms.transform(AB_test) ###WS_SVM best params of WS_SVM {'c1': 1.0, 'c2': 10.0, 'c3': 10.0} from WS_SVM_class import WS_SVM start_time = time.time() clf2 = WS_SVM(c1 = 1, c2 = 10, c3 = 10) clf2.fit(AB_train_mms, y_train) end_time = time.time() print('Total runtime of WS_SVM: %s' %((end_time - start_time))) y_pred_WS_SVM = clf2.predict(AB_test_mms) print('accuracy of WS_SVM: %s' %(100*np.mean(y_pred_WS_SVM==y_test)), clf2.score(AB_test_mms, y_test)) ###Cross validation score of WS_SVM from sklearn.model_selection import cross_val_score scores = cross_val_score(estimator = clf2, X = AB_train_mms, y = y_train, cv = 10, n_jobs =1) #print('CV accuracy scores of WS_SVM: %s' %scores) print('CV accuracy of WS_SVM: %.3f +/- %.3f' % (np.mean(scores), np.std(scores))) ### S_TWSVM best params of S_TWSVM {'c1': 0.1, 'c2': 1.0, 'c3': 10.0} from S_TWSVM_class import S_TWSVM start_time = time.time() clf3 = S_TWSVM(c1 = 0.1, c2 = 1, c3 = 10) clf3.fit(AB_train_mms, y_train) end_time = time.time() print('Total runtime of S_TWSVM: %s' %((end_time - start_time))) y_S_TWSVM = clf3.predict(AB_test_mms) print('Accuracy of S_TWSVM %.3f' %(100*np.mean(y_S_TWSVM == y_test)))