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)
# 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) # using matchmaker.csv # Step1. the output into terminal, type "matches, features = [your output]" 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) matches = [] features = [] for r in rescaled_data: 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_matchmaker = svm_parameter('-t 2') # indicates using radial-basis function m = svm_train(prob, pm_matchmaker)