日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

【Python学习系列十】Python机器学习库scikit-learn实现Decision Trees案例

發(fā)布時間:2025/4/16 python 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【Python学习系列十】Python机器学习库scikit-learn实现Decision Trees案例 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

學習網(wǎng)址:http://scikit-learn.org/stable/modules/tree.html

scikit-learn這個官網(wǎng)很好,里面有算法案例也有算法原理說明。

案例代碼:

# -*- coding: utf-8 -*- __author__ = 'Jason.F'#http://scikit-learn.org/stable/modules/tree.htmlimport numpy as np import matplotlib.pyplot as plt from sklearn.tree import DecisionTreeRegressor# Create a random dataset rng = np.random.RandomState(1) X = np.sort(200 * rng.rand(100, 1) - 100, axis=0) y = np.array([np.pi * np.sin(X).ravel(), np.pi * np.cos(X).ravel()]).T y[::5, :] += (0.5 - rng.rand(20, 2))# Fit regression model regr_1 = DecisionTreeRegressor(max_depth=2) regr_2 = DecisionTreeRegressor(max_depth=5) regr_3 = DecisionTreeRegressor(max_depth=8) regr_1.fit(X, y) regr_2.fit(X, y) regr_3.fit(X, y)# Predict X_test = np.arange(-100.0, 100.0, 0.01)[:, np.newaxis] y_1 = regr_1.predict(X_test) y_2 = regr_2.predict(X_test) y_3 = regr_3.predict(X_test)# Plot the results plt.figure() s = 50 plt.scatter(y[:, 0], y[:, 1], c="navy", s=s, label="data") plt.scatter(y_1[:, 0], y_1[:, 1], c="cornflowerblue", s=s, label="max_depth=2") plt.scatter(y_2[:, 0], y_2[:, 1], c="c", s=s, label="max_depth=5") plt.scatter(y_3[:, 0], y_3[:, 1], c="orange", s=s, label="max_depth=8") plt.xlim([-6, 6]) plt.ylim([-6, 6]) plt.xlabel("target 1") plt.ylabel("target 2") plt.title("Multi-output Decision Tree Regression") plt.legend() plt.show()
結果:


對scikit-learn庫大體上拿決策樹和支持向量機來了解,后面就是要具體應用。

總結

以上是生活随笔為你收集整理的【Python学习系列十】Python机器学习库scikit-learn实现Decision Trees案例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。