예제 #1
0
def rs_svm(train_file, test_file, kernel):
    xTrain, yTrain = datasets.load_svmlight_file(train_file)
    xTest, yTest = datasets.load_svmlight_file(test_file)
    
    nTestingCore = [1, 2, 4, 8, 16]
    RS_SVM = RandomSamplingSVM(kernel)

    for iTestingCore in range(5):
        start_time = time.time()
        
        model = RS_SVM.train(xTrain, yTrain, beta=0.01, g=1, nCore=nTestingCore[iTestingCore])

        print("Remain SVs: " + str(model.n_support_), flush=True)
        print("Training time: %s" % (time.time() - start_time), flush=True)
        
        testRatio = model.score(xTest, yTest)

        print("Accuracy %f" % testRatio, flush=True)
        print("Total time: %s" % (time.time() - start_time), flush=True)
        print(flush=True)