RandomForestRegressor ".estimators_" Method

When using the .estimators_ method from RandomForestRegressor as suggested in Lesson 9, a warning is printed repeatedly.

I am using .estimators_ like this

preds = np.stack([t.predict(valid_xs) for t in m.estimators_])

And am getting this warning

/usr/local/lib/python3.7/dist-packages/sklearn/base.py:444: UserWarning: X has feature names, but DecisionTreeRegressor was fitted without feature names
  f"X has feature names, but {self.__class__.__name__} was fitted without"

Any help resolving this issue would be appreciated.

It seems like you’ve used a numpy array kind of input while training, but when predicting you’re doing it on a dataframe that has column names.

The below change might help you with this

preds = np.stack([t.predict(valid_xs.values) for t in m.estimators_])