“RandomForestClassifier”对象没有属性“tree_”

6 python scikit-learn

from sklearn.ensemble import RandomForestClassifier
from sklearn import tree

rf = RandomForestClassifier()

rf.fit(X_train, y_train)
n_nodes = rf.tree_.node_count
Run Code Online (Sandbox Code Playgroud)

每次运行此代码时,我都会收到以下错误

“RandomForestClassifier”对象没有属性“tree_”

任何想法为什么

joa*_*avf 4

根据scikit-learn 文档,它没有.tree_ 属性。

它只有:estimators_classes_n_classes_n_features_n_outputs_feature_importances_oob_score_、 和oob_decision_function_属性。