Пример #1
0
      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)
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)))
###Cross validation score of S_TWSVM
#from sklearn.model_selection import cross_val_score
scores = cross_val_score(estimator=clf3,
                         X=AB_train_mms,
                         y=y_train,
                         cv=10,
                         n_jobs=1)
#print('CV accuracy scores of S_TWSVM: %s' %scores)
print('CV accuracy of S_TWSVM: %.3f +/- %.3f' %
      (np.mean(scores), np.std(scores)))
Пример #2
0
      clf2.score(AB_test, 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,
                         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': 10.0, 'c2': 100.0, 'c3': 1000.0}
from S_TWSVM_class import S_TWSVM
start_time = time.time()
clf3 = S_TWSVM(c1=10, c2=100, c3=1000)
clf3.fit(AB_train, y_train)
end_time = time.time()
print('Total runtime of S_TWSVM: %s' % ((end_time - start_time)))
y_S_TWSVM = clf3.predict(AB_test)
print('Accuracy of S_TWSVM %.3f' % (100 * np.mean(y_S_TWSVM == y_test)))
###Cross validation score of S_TWSVM
#from sklearn.model_selection import cross_val_score
scores = cross_val_score(estimator=clf3,
                         X=AB_train,
                         y=y_train,
                         cv=10,
                         n_jobs=1)
#print('CV accuracy scores of S_TWSVM: %s' %scores)
print('CV accuracy of S_TWSVM: %.3f +/- %.3f' %
      (np.mean(scores), np.std(scores)))