簡體   English   中英

用樹繪制隨機森林以進行線性回歸

[英]Graphing Random Forest with Tree for Linear Regression

我在用隨機森林繪制線性回歸模型時遇到問題。 另外,我在定義 feature_names 和 class_names 時遇到問題,因為它是一個連續的數字。 在 R 中,這是一個相當簡單的視覺效果,但 Python 似乎需要更多的思考。

我正在利用紐約市房地產數據來預測未來的房價。 我想在決策樹中將其可視化。

python
from sklearn.ensemble import RandomForestRegressor
random_forest = RandomForestRegressor(n_estimators=12)
random_forest.fit(X_train, y_train)

from sklearn.tree import export_graphviz

estimator = random_forest.estimators_[5]

export_graphviz(
    estimator,
    out_file="nyc_tree.dot",
    rounded=True,
    filled=True
)

我期望有幾個分支的決策樹。

您遇到了什么樣的問題? 制作數據的方式不正確 (n_samples,n_features) 用於 X,而 (n_samples) 用於 y。

否則,這個網站可能會幫助你,它正在做你正在尋找的東西。

暫無
暫無

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

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