Home > Blockchain >  Random Forest with RandomSearch
Random Forest with RandomSearch

Time:02-01

Im trying to create a Random Forest model with RandomSearch but am getting an error pertaining to Invalid parameter learning_rate

Here's the error,

ValueError: Invalid parameter learning_rate for estimator RandomForestClassifier(max_depth=1100, n_estimators=300). 
Check the list of available parameters with `estimator.get_params().keys()`.

Code:

from sklearn.model_selection import RandomizedSearchCV
model = RandomForestClassifier()
param_vals = {'max_depth': [200, 500, 800, 1100], 'n_estimators': [100, 200, 300, 400],
              'learning_rate': [0.001, 0.01, 0.1, 1, 10]}
random_rf = RandomizedSearchCV(estimator=model, param_distributions=param_vals,
                              n_iter=10, scoring='accuracy', cv=5,
                              refit=True, n_jobs=-1)
random_rf.fit(X_train,y_train)

Why am I getting this error?

CodePudding user response:

The error means that RandomForestClassifier does not take learning_rate as parameter. Removing 'learning_rate': [0.001, 0.01, 0.1, 1, 10] from the param_vals variable will fix the issue.

  •  Tags:  
  • Related