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. In R, this is a fairly simple visual, but python seems to require a little more thought.
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.
Otherwise, this website might help you, it's doing exactly what your looking for.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.