# "n_estimators": [1000, 1500], # "max_depth": [5, 10], # "max_features": [0.3, "sqrt"] # } cv_i = False param_grid = { "loss": "huber", "learning_rate": 0.01, "n_estimators": 1000, "max_depth": 5, "max_features": 10, "warm_start": True, } gbm_CV, pred_test = gbm_fun.train_and_test_gradboost(training_features, traj_testing, param_grid=param_grid, cv=cv_i) np.save(saving_path + "predicted_test_set.npy", pred_test) joblib.dump(gbm_CV, saving_path + "clf.pkl") # predictions if cv_i is True: alg = gbm_CV.best_estimator_ ml.write_to_file_cv_results(saving_path + "cv_results.txt", gbm_CV) else: alg = gbm_CV ada_r2_train = np.zeros(len(alg.estimators_), ) for i, y_pred in enumerate(alg.staged_predict(training_features[:, :-1])): ada_r2_train[i] = r2_score(log_halo_training, y_pred)
# param_grid = {"loss": ["huber"], # "learning_rate": [0.2], # "n_estimators": [500, 800], # "max_depth":[5, 100], # "max_features":[0.3, "sqrt"] # } param_grid = {"loss": ["huber"], "learning_rate": [0.1, 0.15, 0.2], "n_estimators": [800, 1000], "max_depth":[5], "max_features":[0.3, "sqrt"] } ada_CV, pred_test = gbm_fun.train_and_test_gradboost(tr_features_07_04, testing_signal_07_corr, param_grid=param_grid, cv=cv_i) np.save(saving_path + "predicted_test_set.npy", pred_test) ml.write_to_file_cv_results(saving_path + "cv_results.txt", ada_CV) joblib.dump(ada_CV, saving_path + "clf.pkl") # predictions if cv_i is True: alg = ada_CV.best_estimator_ else: alg = ada_CV ada_r2_train = np.zeros(len(alg.estimators_), ) for i, y_pred in enumerate(alg.staged_predict(tr_features_07_04[:, :-1])): ada_r2_train[i] = r2_score(log_mass_training, y_pred)
"loss": ["huber"], "learning_rate": [0.1], "n_estimators": [800], "max_depth": [5], "max_features": [0.3, 0.2] } param_grid = { "loss": "huber", "learning_rate": 1, "n_estimators": 800, "max_depth": 5, "max_features": 0.2 } gbm, pred_test = gbm_fun.train_and_test_gradboost(training_features, testing_features, param_grid=param_grid, cv=False) np.save(saving_path + "predicted_test_set.npy", pred_test) joblib.dump(gbm, saving_path + "clf.pkl") np.save(saving_path + "importances.pdf", gbm.best_estimator_.feature_importances_) ml.write_to_file_cv_results(saving_path + "cv_results.txt", gbm) # predictions if cv_i is True: alg = gbm.best_estimator_ else: alg = gbm
z0_den_testing = z0_den_features[testing_set] log_halo_testing = np.log10(halo_mass[testing_set]) np.save(saving_path_z0 + "log_halo_testing_set.npy", log_halo_testing) # training z=0 param_grid = { "loss": "lad", "learning_rate": 0.06, "n_estimators": 2000, "max_depth": 5, "max_features": "sqrt" } clf_z0, pred_test = gbm_fun.train_and_test_gradboost(training_features, z0_den_testing, param_grid=param_grid, cv=False) np.save(saving_path_z0 + "predicted_test_set.npy", pred_test) joblib.dump(clf_z0, saving_path_z0 + "clf.pkl") ################# GBT VS RF ##################### pred_z0 = np.load( "/Users/lls/Documents/mlhalos_files/regression/gradboost/random_sampled_training/z0_den" "/nest_2000_lr006/predicted_test_set.npy") true_z0 = np.load( "/Users/lls/Documents/mlhalos_files/regression/gradboost/random_sampled_training/z0_den" "/nest_2000_lr006/log_halo_testing_set.npy") pred_RF_z0 = np.load( "/Users/lls/Documents/mlhalos_files/regression/lowz_density/z0/z0_only/predicted_log_halo_mass.npy"