anaconda配置python2.7 sklearn_【sklearn】Anaconda安装测试
装了一天sklearn环境,之前已经装好numpy,scipy……,但是还有各种问题,最后用Anaconda搞定,官网下载速度太慢,存到网盘分享一下在Anaconda的shell下pip list看一下安装好的包,import sklearn测试,pycharm调用pycharm中添加Anacondasklearn测试代码# Import the necessary modules and lib
装了一天sklearn环境,之前已经装好numpy,scipy……,但是还有各种问题,最后用Anaconda搞定,官网下载速度太慢,存到网盘分享一下
在Anaconda的shell下pip list看一下安装好的包,import sklearn测试,pycharm调用
pycharm中添加Anaconda
sklearn测试代码
# Import the necessary modules and libraries
import numpy as np
from sklearn.tree import DecisionTreeRegressor
import matplotlib.pyplot as plt
# Create a random dataset
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))
# Fit regression model
regr_1 = DecisionTreeRegressor(max_depth=2)
regr_2 = DecisionTreeRegressor(max_depth=5)
regr_1.fit(X, y)
regr_2.fit(X, y)
# Predict
X_test = np.arange(0.0, 5.0, 0.01)[:, np.newaxis]
y_1 = regr_1.predict(X_test)
y_2 = regr_2.predict(X_test)
# Plot the results
plt.figure()
plt.scatter(X, y, c="darkorange", label="data")
plt.plot(X_test, y_1, color="cornflowerblue", label="max_depth=2", linewidth=2)
plt.plot(X_test, y_2, color="yellowgreen", label="max_depth=5", linewidth=2)
plt.xlabel("data")
plt.ylabel("target")
plt.title("Decision Tree Regression")
plt.legend()
plt.show()
输出结果
决策树回归结果
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐



所有评论(0)