Python Forum
Issue from RandomizedSearchCV
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Issue from RandomizedSearchCV
#1
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:
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.
Reply
#2
You should post the entire error trace.

I think this is your problem.
estimator=Pipeline['clf'],
Maybe should be this?
estimator=Pipeline(['clf']),
Reply
#3
(Aug-16-2023, 08:15 PM)deanhystad Wrote: You should post the entire error trace.

I think this is your problem.
estimator=Pipeline['clf'],
Maybe should be this?
estimator=Pipeline(['clf']),

The code is from here, under Answer 4 (4 Answer), all was posted above, no extra.
https://stackoverflow.com/questions/6076...classifier
Reply
#4
The problem in the stack overflow post is we have no idea what "pipeline" is. It appears to be a dictionary of Pipeline objects. One thing it is not is the class Pipeline. We'll never know as the link pointing to the code is not valid.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error message about iid from RandomizedSearchCV Visiting 2 1,073 Aug-17-2023, 07:53 PM
Last Post: Visiting

Forum Jump:

User Panel Messages

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