Python Forum
Random Forest high R2 Score but poor prediction
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Random Forest high R2 Score but poor prediction
#3
Thanks for your response !
Instead of coding a loop which goes through different estimators, couldn't I run a RandomSearch with ranges for relevant RF parameters and looking for the best one with the best.paras_ command? Because I already did that a couple of times now and the R2 and MAE got even worse, surprisingly. I might have to drop some features and try the random serch again.

e.g. the code would look something like this :

# Number of trees in random forest
n_estimators = [int(x) for x in np.linspace(start = 200, stop = 5000)]
# Number of features to consider at every split
max_features = ['auto', 'sqrt', 'log2']
# Maximum number of levels in tree
max_depth = [int(x) for x in np.linspace(10, 110)]
max_depth.append(None)
# Minimum number of samples required to split a node
min_samples_split = [2, 5, 10, 15, 20]
# Minimum number of samples required at each leaf node
min_samples_leaf = [1, 2, 5, 10, 15]
# Method of selecting samples for training each tree
bootstrap = [True, False]# Create the random grid
random_grid = {'n_estimators': n_estimators,
               'max_features': max_features,
               'max_depth': max_depth,
               'min_samples_split': min_samples_split,
               'min_samples_leaf': min_samples_leaf,
               'bootstrap': bootstrap}


rf_random = RandomizedSearchCV(estimator = rf, param_distributions = random_grid, n_iter = 100, cv = 3, verbose=2, random_state=42, n_jobs = -1)
search = rf_random.fit(X_train, y_train)
search.best_params_
Reply


Messages In This Thread
RE: Random Forest high R2 Score but poor prediction - by donnertrud - Jan-13-2020, 04:45 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Random Forest to Identify Page: Feature Selection JaneTan 0 1,319 Oct-14-2021, 09:40 AM
Last Post: JaneTan
  Can't make Random Forest Prediction work donnertrud 0 1,643 May-23-2020, 12:26 PM
Last Post: donnertrud
  Prediction of Coal Fire Power Plant Pollutants Emission Dalpi 2 2,171 May-08-2020, 06:28 PM
Last Post: Dalpi
  prediction using linear regression (extrapolation?) in a loop karlito 0 3,239 Feb-05-2020, 10:56 AM
Last Post: karlito
  Random Forest Hyperparamter Optimization donnertrud 1 1,951 Jan-17-2020, 06:30 AM
Last Post: scidam
  Difference between R^2 and .score donnertrud 1 6,923 Jan-08-2020, 05:14 PM
Last Post: jefsummers
  AUCPR of individual features using Random Forest (Error: unhashable Type) melissa 1 3,327 Jul-10-2017, 12:48 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020