Advertisement

(DecisionTreeRegressor) Decision Tree Regression 实例 - max_depth Notes

阅读量:
复制代码
    import numpy as np
    from sklearn.tree import DecisionTreeRegressor
    import matplotlib.pyplot as plt
    %matplotlib inline
    
    n = 100
    x = np.random.rand(n)*6 - 3
    x.sort()
    y = np.sin(x) + np.random.rand(n) + 0.06
    x = x.reshape(-1,1)
    y = y.reshape(-1,1)
    
    dtr = DecisionTreeRegressor(criterion='mse', max_depth=3)
    dtr.fit(x,y)
    x_test = np.linspace(-3,3,50).reshape(-1,1)
    y_pre = dtr.predict(x_test)
    
    plt.figure(figsize=(8,6)
    plt.plot(x,y,'g^',label='actual')
    plt.plot(x_test,y_pre,'b-',linewidth=2,label='predict')
    plt.grid

全部评论 (0)

还没有任何评论哟~