因果森林算法中'MultiOutputGRF' object has no attribute 'estimators_'


from econml.dml import CausalForestDML
clf = CausalForestDML
clf.fit(Y=train_y, 
              T=train_X,
              X=train_X)
fig, ax = plt.subplots()
sns.barplot(x=X,y=clf.feature_importances_)
plt.suptitle('特征重要性', fontproperties=my_font)
plt.bar(range(len(importances)), importances[indices])
plt.xticks(range(len(importances)), names, rotation=90, fontproperties=my_font,fontsize=7)

plt.show()

报错:'MultiOutputGRF' object has no attribute 'estimators_'

img

The error message indicates that the CausalForestDML model object has no attribute estimators_, which is likely being called by clf.feature_importances_ in the sns.barplot line. This could be caused by not properly initializing the CausalForestDML model, or potentially by a version incompatibility issue with the econml package.

To properly initialize the CausalForestDML model, you should use parentheses when calling the class, like this:

python
Copy code
clf = CausalForestDML()
Also, make sure that you have properly defined the variables X, importances, indices, and names before using them in the plot.