0

I am trying to set a RandomForestClassification inside a GridSearch

rfc_model = RandomForestClassifier(n_estimators = 5, max_depth = 3 )

gs = grid_search.GridSearchCV(estimator = rfc_model,
                             param_grid = {'n_estimators': [i for i in range(1,52,10)],
                                          "max_depth": [3, 5],
                                          "bootstrap": [True, False],
                                          "criterion": ["gini"]},
                             cv = cross_val_score(rfc_model,X, y, scoring='roc_auc'))

gs.fit(X, y)
gs.grid_scores_
print gs.best_estimator
print gs.best_score_

I get the error

TypeError: 'numpy.float64' object is not iterable

Obviously I am learning, so any comments are welcome.

1

1 Answer 1

1

Ok, I found the problem, I was using the wrong method(Is it alright to call it method?) for Cross Validation, below the solution:

gs = grid_search.GridSearchCV(estimator = model,
                             param_grid = {'n_estimators': [i for i in range(1,52,10)],
                                          "max_depth": [3, 5],
                                          "bootstrap": [True, False],
                                          "criterion": ["gini"]},
                             cv = cross_validation.KFold(n=len(X), n_folds=10), scoring='roc_auc')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.