示例#1
0
#scale the dataset
from sklearn.preprocessing import StandardScaler
stdsc = StandardScaler()
AB_train_std = stdsc.fit_transform(AB_train)
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)
示例#2
0
y_AB = np.hstack((y_A, y_B))
AB_train, AB_test, y_train, y_test = train_test_split(AB,
                                                      y_AB,
                                                      test_size=0.1,
                                                      random_state=1000)

## 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' %
示例#3
0
### scale the data set
from sklearn.preprocessing import StandardScaler
stdsc = StandardScaler()
AB_train_std = stdsc.fit_transform(AB_train)
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': 0.0001, 'c3': 0.0001}
from WS_SVM_class import WS_SVM
start_time = time.time()
clf2 = WS_SVM(c1=1, c2=0.0001, c3=0.0001)
clf2.fit(AB_train, 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)
print('accuracy of WS_SVM: %s' % (100 * np.mean(y_pred_WS_SVM == y_test)),
      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' %