def rs_svm_large_file(train_file, test_file, kernel): print("Ramdom Sampling SVM for large dataset") start_time = time.time() RS_SVM = RandomSamplingSVM(kernel) model = RS_SVM.train_large_file(train_file, debug=True, temp_folder='./') print("Remain SVs: " + str(model.n_support_)) print("Training time: %s" % (time.time() - start_time)) X_test, y_test = datasets.load_svmlight_file(test_file) ratio = model.score(X_test,y_test) print("Accuracy %f" % ratio) print("Total time: %s" % (time.time() - start_time))
def signle_svm(train_file, test_file, kernel): print("Single SVM", flush=True) start_time = time.time() RS_SVM = RandomSamplingSVM(kernel) model = RS_SVM.train_single(train_file) print("Remain SVs: " + str(model.n_support_), flush=True) print("Training time: %s" % (time.time() - start_time), flush=True) X_test, y_test = datasets.load_svmlight_file(test_file) ratio = model.score(X_test,y_test) print("Accuracy %f" % ratio, flush=True) print("Total time: %s" % (time.time() - start_time), flush=True)
def rs_svm_ratio(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.trainWithRatio(0.5, xTrain, yTrain, beta=0.01, 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)