Search code examples
machine-learningscikit-learngridsearchcv

GridSearchCV and its feature importance


In gridsearchCV, when I fit like something as follows:

forest_reg = RandomForestRegressor()
grid_search = GridSearchCV(forest_reg, param_grid,cv=5,scoring = 'neg_mean_squared_error')
grid_search.fit(X_train,y_train)

and after that, when I execute this,

GridSearch.best_estimator_.feature_importances_ 

it gives an array of values so my question is what values does GridSearch.best_estimator_.feature_importances_ this line return??


Solution

  • In your case, GridSearch.best_estimator_.feature_importances_ returns a RandomForestRegressor object.

    Therefore, according to RandomForestRegressor documentation:

    feature_importances_ : array of shape = [n_features] Return the feature importances (the higher, the more important the feature).

    In other words, it returns the most important features according to your training set X_train. Each element of feature_importances_ corresponds to one feature of X_train (e.g: first element of feature_importances_ refers to the first feature/column of X_train).

    The higher the value of an element in feature_importances_, the more important is the feature in X_train.