决策树
1 概述
1.1 决策树是如何工作的

1.2 分类树 DecisionTreeClassifier

1.3 回归树 DecisionTreeRegressor

1.4 案例练习
1. 用回归树拟合正弦函数曲线
rng = np.random.RandomState(1)
x = np.sort(5*rng.rand(80,1),axis=0)
y = np.sin(x).ravel()
y[::5]+=3*(0.5- rng.rand(16))
regr1 = DecisionTreeRegressor(max_depth=2)
regr2 = DecisionTreeRegressor(max_depth=5)
regr1 = regr1.fit(x,y)
regr2 = regr2.fit(x,y)
xtest = np.arange(0,5,0.01)[:,np.newaxis]
y_1 = regr1.predict(xtest)
y_2 = regr2.predict(xtest)
plt.figure()
plt.scatter(x,y,s=20,edgecolors='black',c='darkorange',label ='data')
plt.plot(xtest,y_1,color='cornflowerblue',label='max_depth=2',linewidth=2)