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)
rf_prediction = random_rf.predict(X_test)
rf_predprobability = random_rf.predict_proba(X_test)
#Random search execute
print("accuracy score:")
print(accuracy_score(y_test, rf_prediction))
print("Accuracy on training set: {:.2f}".format(random_rf.score(X_train, y_train)))
print("Accuracy on test set: {:.2f}".format(random_rf.score(X_test, y_test)))
I can't figure out why the error is showing. Can anyone tell me why I am getting this error?
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.
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.