python-机器学习-决策树深度影响
本文是python-机器学习系列第三篇,对决策数深度影响分析
此次的决策树算法是引用我上一篇决策树算法
链接:python-机器学习-决策树算法
代码如下:
# -*- coding:utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
from sklearn.tree import DecisionTreeRegressor
import DecisionTree as de
if __name__ == "__main__":
N = 100
x = np.random.rand(N) * 6 # [-3,3)
x.sort()
y = np.sin(x) + np.random.randn(N) * 0.05
y = y.reshape(-1, 1)
print(y)
x = x.reshape(-1, 1) # 转置后,得到N个样本,每个样本都是1维的
print(x)
# 比较决策树的深度影响
depth = [2, 4, 6, 8, 10]
clr = 'rgbmy'
# reg = [DecisionTreeRegressor(criterion='mse', max_depth=depth[0]),
# DecisionTreeRegressor(criterion='mse', m