示例#1
0
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)))

# TWSVM: best params of TWSVM {'c': 1.0, 'c_': 1.0}
from TWSVM_class import TWSVM
start_time = time.time()
clf4 = TWSVM(c=1, c_=1)
clf4.fit(AB_train_mms, y_train)
end_time = time.time()
print('total run time of TWSVM: %f ' % ((end_time - start_time)))
y_TWSVM = clf4.predict(AB_test_mms)
print('Accuracy of TWSVM %.3f ' % (100 * np.mean(y_TWSVM == y_test)))
###Cross validation score of TWSVM
#from sklearn.model_selection import cross_val_score
scores = cross_val_score(estimator=clf4,
                         X=AB_train_mms,
                         y=y_train,
                         cv=10,
                         n_jobs=1)
#print('CV accuracy scores of TWSVM: %s' %scores)
print('CV accuracy of TWSVM: %.3f +/- %.3f' %
      (np.mean(scores), np.std(scores)))
示例#2
0
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)))

# TWSVM best params of TWSVM {'c': 0.1, 'c_': 0.1}
from TWSVM_class import TWSVM
start_time = time.time()
clf4 = TWSVM(c=0.1, c_=0.1)
clf4.fit(AB_train, y_train)
end_time = time.time()
print('total run time of TWSVM: %f ' % ((end_time - start_time)))
y_TWSVM = clf4.predict(AB_test)
print('Accuracy of TWSVM %.3f ' % (100 * np.mean(y_TWSVM == y_test)))
###Cross validation score of TWSVM
#from sklearn.model_selection import cross_val_score
scores = cross_val_score(estimator=clf4,
                         X=AB_train,
                         y=y_train,
                         cv=10,
                         n_jobs=1)
#print('CV accuracy scores of TWSVM: %s' %scores)
print('CV accuracy of TWSVM: %.3f +/- %.3f' %
      (np.mean(scores), np.std(scores)))