资源简介
本资源包含数据,代码,解释,相应的文件。代码是练习用的,文章中的代码都可以运行出来,是很好的一个练手项目。
代码片段和文件信息
###########################################
# Suppress matplotlib user warnings
# Necessary for newer version of matplotlib
import warnings
warnings.filterwarnings(“ignore“ category = UserWarning module = “matplotlib“)
#
# Display inline matplotlib plots with IPython
from IPython import get_ipython
get_ipython().run_line_magic(‘matplotlib‘ ‘inline‘)
###########################################
import matplotlib.pyplot as pl
import numpy as np
from sklearn.model_selection import learning_curve validation_curve
from sklearn.tree import DecisionTreeRegressor
from sklearn.model_selection import ShuffleSplit train_test_split
def ModelLearning(X y):
“““ Calculates the performance of several models with varying sizes of training data.
The learning and validation scores for each model are then plotted. “““
# Create 10 cross-validation sets for training and testing
cv = ShuffleSplit(n_splits = 10 test_size = 0.2 random_state = 0)
# Generate the training set sizes increasing by 50
train_sizes = np.rint(np.linspace(1 X.shape[0]*0.8 - 1 9)).astype(int)
# Create the figure window
fig = pl.figure(figsize=(107))
# Create three different models based on max_depth
for k depth in enumerate([13610]):
# Create a Decision tree regressor at max_depth = depth
regressor = DecisionTreeRegressor(max_depth = depth)
# Calculate the training and testing scores
sizes train_scores valid_scores = learning_curve(regressor X y \
cv = cv train_sizes = train_sizes scoring = ‘r2‘)
# Find the mean and standard deviation for smoothing
train_std = np.std(train_scores axis = 1)
train_mean = np.mean(train_scores axis = 1)
valid_std = np.std(valid_scores axis = 1)
valid_mean = np.mean(valid_scores axis = 1)
# Subplot the learning curve
ax = fig.add_subplot(2 2 k+1)
ax.plot(sizes train_mean ‘o-‘ color = ‘r‘ label = ‘Training Score‘)
ax.plot(sizes valid_mean ‘o-‘ color = ‘g‘ label = ‘Validation Score‘)
ax.fill_between(sizes train_mean - train_std \
train_mean + train_std alpha = 0.15 color = ‘r‘)
ax.fill_between(sizes valid_mean - valid_std \
valid_mean + valid_std alpha = 0.15 color = ‘g‘)
# Labels
ax.set_title(‘max_depth = %s‘%(depth))
ax.set_xlabel(‘Number of Training Points‘)
ax.set_ylabel(‘r2_score‘)
ax.set_xlim([0 X.shape[0]*0.8])
ax.set_ylim([-0.05 1.05])
# Visual aesthetics
ax.legend(bbox_to_anchor=(1.05 2.05) loc=‘lower left‘ borderaxespad = 0.)
fig.suptitle(‘Decision Tree Regressor Learning Performances‘ fontsize = 16 y = 1.03)
fig.tight_layout()
fig.show()
def ModelComplexity(X y):
“““ Calculates the performance of the model as model complexity increases.
The learning and validation errors rates are then pl
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 784 2018-12-17 13:57 boston_housing\.gitignore
文件 30918 2018-12-17 13:57 boston_housing\boston_housing.ipynb
文件 12435 2018-12-17 13:57 boston_housing\housing.csv
文件 1554 2018-12-17 13:57 boston_housing\README.md
文件 5046 2018-12-17 13:57 boston_housing\visuals.py
目录 0 2018-12-17 13:57 boston_housing
----------- --------- ---------- ----- ----
50737 6
- 上一篇:软件测试报告.doc
- 下一篇:IDEA导入eclipse常用快捷键
相关资源
- Python中Numpy库最新教程
- CCSv9链接及安装流程详解
- 用python编写的移动彩信的发送程序
- Python全栈学习笔记面向对象大作业:
- python实现的ftp自动上传、下载脚本
- Python版的A*寻路算法
- IronPython IDE
- 易语言EXCEL另存为CSV文件源码
- csv2xls,批量转换CSV到Excel
- pip-10.0.1.tar.gz
- Data Science from Scratch 2nd Edition
- usa_flights.csv
- shape_predictor_68_face_landmarks.dat.bz2 68个标
- 爬取豆瓣电影TOP250程序,包含非常详
- 中文维基百科语料库百度网盘网址.
- MSCNN_dehaze.rar
- 爬取豆瓣排行榜电影数据(含GUI界面
- 字典文本资源
- titanic_dataset.csv泰坦尼克数据集
- Brainfuck / OoK 解码脚本
- creditcard csv - 训练集
- 案例实战信用卡欺诈检测数据集
- Labview读取CSV文件并整合
- 招商策略_抱团启示录那些年我们一起
- csv文件转换为kml文件的可靠工具
- csv 转换为google earth的轨迹kml
- sip-4.19.zip
- 树莓派3b+学习使用教程
- numpy 中文学习手册
- 2016年11月截止的,最新全国城市名数
评论
共有 条评论