# %% Best Hyper-parameters Training alg = SVD() alg.biased = Grid_Search_Result.best_params['rmse']['biased'] alg.n_epochs = Grid_Search_Result.best_params['rmse']['n_epochs'] alg.n_factors = Grid_Search_Result.best_params['rmse']['n_factors'] alg.reg_pu = Grid_Search_Result.best_params['rmse']['reg_all'] alg.reg_qi = Grid_Search_Result.best_params['rmse']['reg_all'] alg.lr_pu = Grid_Search_Result.best_params['rmse']['lr_all'] alg.lr_qi = Grid_Search_Result.best_params['rmse']['lr_all'] alg.fit(data_train.build_full_trainset()) # %% Loading Test Data file_path = "Data/sample_submission.csv" data_test = utils.load_data_desired(file_path) # %% Prediction Predict_Test = [] for line in data_test: Predict_Test.append(alg.predict(str(line[1]), str(line[0])).est) # %% Save Prediction file = open("testfile.csv", "w") file.write("Id,Prediction\n") for i in range(len(Predict_Test)): line = data_test[i] temp = 'r' + str(line[0]) + '_c' + str(line[1]) + ',' + str( int(round(Predict_Test[i]))) + '\n'
alg.reg_pu = 0.1 alg.reg_qi = 0.1 alg.verbose = True start = time.time() alg.fit(data_train.build_full_trainset()) end = time.time() print("***********************************************") print("Exe time:") print(end - start) # %% Loading train data file_path = "Data/data_train.csv" data_train = utils.load_data_desired(file_path) # %% Overall Labels for training Pred_NotCliped_label = [] Real_label = [] Clip = False for line in data_train: Real_label.append(line[2]) Pred_NotCliped_label.append( alg.predict(str(line[1]), str(line[0]), clip=False).est) Pred_NotCliped_label = np.array(Pred_NotCliped_label) Real_label = np.array(Real_label)