How do decision trees for regression work? 决策树模型既可以求解分类问题(对应的就是 classification tree),也即对应的目标值是类别型数据,也可以应用于回归预测问题的求解(regression tree),其输出值则可以是连续的实数值.一般市面上介绍决策树模型的书及相关的教学视频,通常只关注决策树在分类问题上的求解,而一笔带过对回归树的介绍.事实上,二者的构建过程也确实没有本质的不同,二者的差异主要集中在划分属性时的划分原则上. 1.
import numpy as np import matplotlib.pyplot as plt from sklearn import datasets from sklearn.model_selection import train_test_split from sklearn.tree import DecisionTreeClassifier,DecisionTreeRegressor def load_data(): ''' 加载用于分类问题的数据集.数据集采用 scikit-
import numpy as np import matplotlib.pyplot as plt from sklearn import datasets from sklearn.model_selection import train_test_split from sklearn.tree import DecisionTreeClassifier,DecisionTreeRegressor def creat_data(n): np.random.seed(0) X = 5 * np