def main(): agesonly_path = '[your own agesonly.csv path]' # download agesonly.csv and change to your own path agesonly_rows = load_match_data.load_csv(agesonly_path, True) print 'class cenetrs' averages = train_data(agesonly_rows) for k,v in averages.items(): print k, v print 'classify new points' print classify_dp([18,30], averages) print classify_dp([27,30], averages) print classify_dp([30,27], averages) print classify_dp([25,80], averages)
def main(): agesonly_path = '[your own agesonly.csv path]' # download agesonly.csv and change to your own path agesonly_rows = load_match_data.load_csv(agesonly_path, True) print 'class cenetrs' averages = train_data(agesonly_rows) for k, v in averages.items(): print k, v print 'classify new points' print classify_dp([18, 30], averages) print classify_dp([27, 30], averages) print classify_dp([30, 27], averages) print classify_dp([25, 80], averages)
def main(): print "use agesonly.csv to predict:" agesonly_path = "[your agesonly.csv path]" # change to your agesonly.csv path agesonly_rows = load_match_data.load_csv(agesonly_path, True) offset1 = get_offset(agesonly_rows) print nlclassify([27, 30], agesonly_rows, offset1) print nlclassify([30, 27], agesonly_rows, offset1) print "use scaled matchmaker.csv to predict:" matchmaker_path = "[your matchmaker.csv path]" # change to your matchmaker.csv path ls = file(matchmaker_path) numerical_rows = preprocess_data.to_numerical(ls) rescaled_data = preprocess_data.rescale_data(numerical_rows) offset2 = get_offset(rescaled_data) new_p1 = [28.0, -1, -1, 26.0, -1, 1, 2, 0.8] # man doesn't want children, women wants new_p2 = [28.0, -1, 1, 26.0, -1, 1, 2, 0.8] # both want children print nlclassify(new_p1, rescaled_data, offset2) print nlclassify(new_p2, rescaled_data, offset2)
''' Created on Feb 9, 2016 @author: hanhanwu Most of the code here should be operated in the terminal, under the libsvm/python path ''' import preprocess_data import load_match_data # using agesonly.csv # Step1. the output into terminal, type "matches, features = [your output]" agesonly_path = '[change to your agesonly.csv path]' # change to your agesonly.csv path agesonly_rows = load_match_data.load_csv(agesonly_path, True) matches = [] features = [] for r in agesonly_rows: matches.append(r.match) features.append(r.data) print matches,',',features # Step2. In the terminal, type following code line by line from svmutil import * prob = svm_problem(matches, features) pm_ages = svm_parameter('-t 2') # indicates using radial-basis function m = svm_train(prob, pm_ages) # [1] is the the ground truth, used for calculating the accuracy ; [28.0, 26.0] is the new point p_labels, p_acc, p_vals = svm_predict([1], [[28.0, 26.0]], m)