예제 #1
0
    float(line.rstrip('\n')) for line in open('csvData/test_label.data')
]

filename = 'ensembleResult/test' + '_ensemble_SVM_Perceptron'

predictTest = [
    1 if s == 1 and p == 1 else -1
    for p, s in zip(predict_labels_Perceptron, predict_labels_SVM)
]
predictEval = [
    1 if s == 1 and p == 1 else -1
    for p, s in zip(eval_labels_Perceptron, eval_labels_SVM)
]

print("Accuracy for test set")
print(Stat.Accuracy(predictTest, test_labels))

print("F1 score for test set")
print(Stat.F1_Score(predictTest, test_labels))

print("Precision for test set")
print(Stat.Precision(predictTest, test_labels))

print("Recall for test set")
print(Stat.Recall(predictTest, test_labels))

# filename = 'results/eval_Ensemble_SVM_Perceptron'
#
# with open(filename, 'wb') as thefile:
#     for item in predictEval:
#         thefile.write("%s\n" % item)
예제 #2
0
print("best gamma0:", best_g0)  
'''
###

sgd = SGD_SVM.SGDSVM(C=best_C,
                     ro=best_ro,
                     epochs=best_epoch,
                     W0=[0] * len(data[0]),
                     gamma0=best_g0)
sgd.fit(data, data_labels)

predictTrain = sgd.predict(data)
predictTest = sgd.predict(testset)

print("Accuracy for training set:")
print(Stat.Accuracy(predictTrain, data_labels))

print("F1 score for training set:")
print(Stat.F1_Score(predictTrain, data_labels))

print("Precision for training set:")
print(Stat.Precision(predictTrain, data_labels))

print("Recall for training set:")
print(Stat.Recall(predictTrain, data_labels))

print("Accuracy for test set")
print(Stat.Accuracy(predictTest, test_labels))

print("F1 score for test set")
print(Stat.F1_Score(predictTest, test_labels))
예제 #3
0
         for epoch in [20]:#,10,15,25]:
             for g0 in [1.1,1.01,1.001]:
                 tmp = []
           
                 sgd = SGD_SVM.SGDSVM(C=C,ro=ro,epochs=epoch,W0=[0]*len(phiTrain[0]),gamma0=g0)
                 kfold = KFold.KFold(n_splits=5)
           
                 for kf in kfold.split(phiTrain): 
                     train2 = [phiTrain[i] for i in kf[0]]
                     train_label2 = [data_labels[i] for i in kf[0]]
                     test2 = [phiTrain[i] for i in kf[1]]
                     test_label2 = [data_labels[i] for i in kf[1]]
                                   
                     sgd.fit(train2, train_label2)
                     predict_tmp = sgd.predict(test2)
                     tmp.append(Stat.Accuracy(predict_tmp,test_label2))
                   
                 if np.mean(tmp) > best_accuracy:
                     best_accuracy = np.mean(tmp)
                     best_C = C
                     best_epoch = epoch
                     best_g0 = g0
                     best_ro = ro
 
 ###
 
 print("mid cross-validation")
 
 sgd = SGD_SVM.SGDSVM(C=best_C,ro=best_ro,epochs=best_epoch,W0=[0]*len(phiTrain[0]),gamma0=best_g0)
 sgd.fit(phiTrain,train_label)