I want to print the names of the features from my first estimator of GradientBoostingRegressor, but getting the below error.
Scikit_learn version = 1.2.2
model.estimators_[0]._final_estimator.feature_names_in_
output:
AttributeError Traceback (most recent call last)
Cell In[115], line 1
----> 1 model.estimators_[0]._final_estimator.feature_names_in_
AttributeError: 'GradientBoostingRegressor' object has no attribute 'feature_names_in_'
You write that you want to specifically get the feature names of the first estimator of the ensemble. Unfortunately, the feature names of the individual trees are not stored. That's why it gives you the error
However, since they are trained on the same set of features as the entire model, the feature names from the main
GradientBoostingRegressorare available to each of its decision trees. So you can extract the feature names of the ensemble (and thus available to the first tree) like this:If you are interested by the feature names used by the first tree, you can do it like this: