[英]Graphing Random Forest with Tree for Linear Regression
I am having a problem graphing my linear regression model with a random forest.我在用随机森林绘制线性回归模型时遇到问题。 Also, I am having a problem defining my feature_names and class_names because it is a continuous number.
另外,我在定义 feature_names 和 class_names 时遇到问题,因为它是一个连续的数字。 In R, this is a fairly simple visual, but python seems to require a little more thought.
在 R 中,这是一个相当简单的视觉效果,但 Python 似乎需要更多的思考。
I am utilizing the NYC Property data to predict future housing prices.我正在利用纽约市房地产数据来预测未来的房价。 I want to visualize this in a decision tree.
我想在决策树中将其可视化。
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
)
I expect a decision tree with several branches.我期望有几个分支的决策树。
What kind of issue are you encountering?您遇到了什么样的问题? Making your data is not shaped the right way (n_samples,n_features) for X, and (n_samples) for y.
制作数据的方式不正确 (n_samples,n_features) 用于 X,而 (n_samples) 用于 y。
Otherwise, this website might help you, it's doing exactly what your looking for.否则,这个网站可能会帮助你,它正在做你正在寻找的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.