Aug-16-2023, 06:59 PM
(This post was last modified: Aug-16-2023, 07:24 PM by deanhystad.)
I am trying to find best n_estimators for random forest, when running following script, got error message:
TypeError: 'ABCMeta' object is not subscriptable
Please help solve the problem, thank you!
Here is the code:
TypeError: 'ABCMeta' object is not subscriptable
Please help solve the problem, thank you!
Here is the code:
from sklearn.ensemble import RandomForestClassifier from sklearn.model_selection import RandomizedSearchCV from sklearn.pipeline import Pipeline # from abc import ABC # from collections.abc import Mapping parameter_grid={'n_estimators':[1,2,3,4,5],'max_depth':[2,4,6,8,10],'min_samples_leaf': [1,2,4],'max_features':[1,2,3,4,5,6,7,8]} number_models=4 random_RandomForest_class=RandomizedSearchCV( estimator=Pipeline['clf'], param_distributions=parameter_grid, n_iter=number_models, scoring='accuracy', n_jobs=2, cv=4, refit=True, return_train_score=True) # Error message was generated after this block of code random_RandomForest_class.fit(X_train,y_train) predictions=random_RandomForest_class.predict(X) print("Accuracy Score",accuracy_score(y,predictions)); print("Best params",random_RandomForest_class.best_params_) print("Best score",random_RandomForest_class.best_score_)
deanhystad write Aug-16-2023, 07:24 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.