str_to_write = "lr.gradient_descent_linear_regression_alg W = \n" + str(W) + "\n" str_to_write += "elapsed_time = " + str(elapsed_time) + "\n" fout_t2r.write(str_to_write) print(str_to_write) """ str_to_write = "\n\n\n\n\n\n\n\n" + "for training and validation \n\n ===========!!!!===========\n\n" fout_t2r.write(str_to_write) print(str_to_write) start_time = time.time() W_cf, str_to_write = lr.least_squares_estimate_linear_regression_alg( X_training_set_Adv, Y_training_set_Adv) #print("lr.least_squares_estimate_linear_regression_alg W = \n", W) fout_t2r.write(str_to_write) print(str_to_write) str_to_write = "lr.least_squares_estimate_linear_regression_alg W_cf = \n" + str( W_cf) + "\n" elapsed_time = time.time() - start_time str_to_write += "least_squares_estimate_linear_regression_alg elapsed_time = " + str( elapsed_time) + "\n" fout_t2r.write(str_to_write) print(str_to_write) #print("elapsed_time = ", elapsed_time)
with open("../training_set.json", "r") as rf_training_set: data = json.load(rf_training_set) X_training_set_Adv, Y_training_set_Adv, str_output = pf.generate_wordfeature_and_output(wordcount, data, False, 0, False, 0) with open("../validation_set.json", "r") as rf_validation_set: data = json.load(rf_validation_set) X_validation_set_Adv, Y_validation_set_Adv, str_output = pf.generate_wordfeature_and_output(wordcount, data, False, 0, False, 0) #測試Closed form的性能 start_time = time.time() W_closed, str_to_write = lr.least_squares_estimate_linear_regression_alg(X_validation_set_Adv, Y_validation_set_Adv) closed_running_time = time.time() - start_time est_Y = np.dot(X_training_set_Adv, W_closed) trn_mse_closed, diff_AB, Sigma_Square_of_diff_AB = lr.mean_squared_error(est_Y, Y_training_set_Adv) est_Y = np.dot(X_validation_set_Adv, W_closed) val_mse_closed, diff_AB, Sigma_Square_of_diff_AB = lr.mean_squared_error(est_Y, Y_validation_set_Adv) #測試Gradient Descent的性能 list_T_Robbins_Monroe_pow = [] list_trn_mse = [] list_val_mse = [] list_elapsed_time = [] list_W_MSE = []
Y_training_set, Y_validation_set = np.split(Y, [8]) #print("Y_training_set = \n", Y_training_set) #print("Y_validation_set = \n", Y_validation_set) str_to_write = "Y_training_set = \n" + str(Y_training_set) + "\n" str_to_write += "Y_validation_set = \n" + str(Y_validation_set) + "\n" fout_t2r.write(str_to_write) print(str_to_write) start_time = time.time() # your code W, str_to_write = lr.least_squares_estimate_linear_regression_alg(X, Y) fout_t2r.write(str_to_write) print(str_to_write) elapsed_time = time.time() - start_time #print("lr.least_squares_estimate_linear_regression_alg W = \n", W) #print("elapsed_time = ", elapsed_time) str_to_write = "lr.least_squares_estimate_linear_regression_alg W = \n" + str( W) + "\n" str_to_write += "elapsed_time = " + str(elapsed_time) + "\n\n\n\n\n" fout_t2r.write(str_to_write) print(str_to_write) """