Gavin
Gavin

Reputation: 1521

Can RandomizedSearchCV output feature importance based on the best model?

After use RandomizedSearchCV to find the best hyperparameters, is there a way to find the following outputs? 1. save the best model as an object 2. output feature importance

gbm = GradientBoostingClassifier()
rand = RandomizedSearchCV(gbm, param_distributions=param_dist, cv=10, 
scoring='roc_auc', n_iter=10, random_state=5)
rand.fit(X_train, y_train_num)

Upvotes: 1

Views: 1452

Answers (1)

Cody Glickman
Cody Glickman

Reputation: 524

Use the best_params_ parameter and save it into a dictionary. From the dictionary retrain the model and call the values by the keys.

top_params = rand.best_params_
gbm_model = GradientBoostingClassifier(learning_rate=top_params['learning_rate'], max_depth=top_params["max_depth"], ...)
gbm_model.fit(X_train, y_train_num)
gbm_model.feature_importances_

Upvotes: 1

Related Questions