简体   繁体   中英

GPU for Random Forest Regressor

I am still new to Machine Learning and have been using a CPU for all my previous machine learning projects. Now, I developed a Random Forest Regressor and used Optuna to optimize the hyperparameters for 18 target variables (each model trained separately). However this seems to take soo long time to finish running, despite the fact that the number of rows in my dataset is just about 2,000. I tried to speedup the training using the GPU of Google Colab, however I found it useless for my model. Is there a way I can use a GPU for my Random Forest model?

target_vars = df_crime.columns.tolist()[-18:]
predictor_vars = df_crime.columns.tolist()[:-18]

def otimize_RF(trial, x, y):
   criterion = trial.suggest_categorical('criterion', ['mse', 'mae'])
   n_estimators = trial.suggest_int('n_estimators', 10, 1500)
   max_depth = trial.suggest_int('max_depth', 3, 20)
   max_features = trial.suggest_uniform('max_features', 0.01, 1)

   model = RandomForestRegressor(
       criterion= criterion,
       n_estimators=n_estimators,
       max_depth=max_depth,
    max_features=max_features,
   )

   cv = RepeatedKFold(n_splits=10, n_repeats=3, random_state=1)
   scores = cross_val_score(model, x, y, cv=cv, 
   scoring='neg_mean_squared_error')

   return -1 * np.mean(scores)


dict_ = dict()

for crime in target_vars:
   X = predictor_df_stand[df_crime[crime].notnull()]
   y = df_crime[crime][df_crime[crime].notnull()].values

   optimization_function = partial(otimize_RF, x=X, y=y)
   study = optuna.create_study(direction='minimize')
   study.optimize(optimization_function, n_trials=100)

   dict_2 = study.best_params 
   dict_2['mse'] = study.best_value
   dict_[crime] = dict_2

   print(dict_)

If you use sklearn random forest implementation, no: you can read this doc if needed.

But a little bit of code would be much simpler to understand the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM