簡體   English   中英

scikit-learn RandomForestClassifier 列出估計樹的所有變量?

[英]scikit-learn RandomForestClassifier list all variables of an estimator tree?

我訓練一個RandomForestClassifier作為

from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import make_classification
X, y = make_classification()
clf = RandomForestClassifier()
clf.fit(X,y)

其中Xy是一些特征向量和標簽。

完成擬合后,我可以列出森林中每個估計器生長的所有樹木的深度,如下所示:

[estimator.tree_.max_depth for estimator in clf.estimators_]

現在我想找出所有其他公共變量(除了max_depth )一個estimator stores 中的tree_ 所以我嘗試了:

vars(clf.estimators_[0].tree_)

但不幸的是,這不起作用並返回錯誤

TypeError: vars() argument must have __dict__ attribute

我可以使用什么語法來成功列出estimator.tree_中的所有公共變量?

無法自動獲取此屬性,但Tree class 的文檔為您提供了所有屬性:

  • 容量
  • children_left
  • 兒童權利
  • 特征
  • 不純
  • 最大深度
  • max_n_classes
  • n_classes
  • n_features
  • n_leaves
  • n_node_samples
  • n_輸出
  • 節點數
  • 臨界點
  • 價值
  • weighted_n_node_samples

了解更多: https://scikit-learn.org/stable/auto_examples/tree/plot_unveil_tree_structure.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM