# -*- coding: utf-8 -*- """ Created on Tue Mar 6 19:30:05 2018 @author: Erik """ import get_data as gd import part2b_code as p2b import part1c_code as p1c import gradient_calculation as gc X_test, y_test = gd.read_data_formatted('test_struct.txt') X_train, y_train = gd.read_data_formatted('train_struct_1000.txt') params = gd.get_params() p2b.optimize(params, X_train, y_train, 1000, 'solution_1000_distortion') params = p2b.get_optimal_params('solution_1000_distortion') w = gc.w_matrix(params) t = gc.t_matrix(params) print("Function value: ") print(p2b.func_to_minimize(params, X_train, y_train, 1000)) y_pred = p2b.predict(X_test, w, t) print(p2b.accuracy(y_pred, y_test))
""" import part2b_code as p2b import gradient_calculation as gc import get_data as gd import part2b_code as p2b X_train, y_train = gd.read_data_formatted('train_struct.txt') X_test, y_test = gd.read_data_formatted('test_struct.txt') params = gd.get_params() #Run optimization, should take 3+ hours so commented out. ''' cvals = [1, 10, 100, 1000] for elt in cvals: p2b.optimize(params, X_train, y_train, elt, 'solution' + str(elt)) print("done with" + str(elt)) ''' #check accuracy cvals = [1, 10, 100, 1000] for elt in cvals: params = p2b.get_optimal_params('solution' + str(elt)) w = gc.w_matrix(params) t = gc.t_matrix(params) prediction = p2b.predict(X_test, w, t) print("Accuracy for: " + str(elt)) print(p2b.accuracy(prediction, y_test))