Matlab决策树对空气质量和天气温度及天气数据做交通出行推荐预测|数据分享

简介: Matlab决策树对空气质量和天气温度及天气数据做交通出行推荐预测|数据分享

为解决城市交通拥堵问题,本文提出了一种基于 Matlab决策树的交通预测方法,我们通过采集上海地区的空气质量数据和温度数据,帮助客户在 Matlab中实现决策树建模,利用所提取的天气和温度特征建立决策树,对未来的出行时间、出行路线等进行预测点击文末“阅读原文”获取完整代码数据


结果表明:该方法可实现交通时间、出行路线的预测,并能在未来三天进行有效预测时间长度与空气质量、温度相关。


数据


里面一个是天气数据(区县自动站实况数据),只把地区为徐家汇的取出来,其余地点的不用参考。

另一个是空气数据(实时空气质量数据)。


预期结果


根据空气中的空气质量和天气数据中的温度及天气情况做一个交通出行的推荐。

举个例子:今天温度0度 天气晴朗 空气质量优 出行方式可以为 公交车或地铁。

今天温度15度 天气晴朗 空气质量优 出行方式为 步行。

今天温度15度 天气晴朗 控制质量轻度污染 出现方式为 公交车或地铁。


读取气温数据


[data, ~, raw] = xlsread('区县自动站实况数据.xlsx','Sheet2');


筛选对应日期数据


data=data(1:9649,:);
raw=raw(1:9649,:);


找出徐家汇地区的数据


index=strcmp(raw(:,3),'徐家汇')


读取空气质量数据


[data2, ~, raw2, dateNums] = xlsread('实时空气质量数据(历史)2.xlsx','Sheet1','','


筛选对应日期数据


data2=data2(4415:end,:);
raw2=raw2(4415:end,:);


得到对应时间


index=1:3:2880

得到对应时间的 空气质量数据

mydata=[raw,raw2];


建立决策规则


分类类别号

label=mydata(:,18);
%label=label(2:end);

将类别号赋值给outData

outData=label;

获得特征变量矩阵

inData = [data,data2];          % 输入特征矩阵

根据训练集数据创建决策树

classregtree(inData, o)

查看决策树

view(mytree);


点击标题查阅往期内容


数据分享|R语言用主成分PCA、 逻辑回归、决策树、随机森林分析心脏病数据并高维可视化


01

02

03

04


决策树规则


Decision tree for classification
  1  if x5<11.5 then node 2 elseif x5>=11.5 then node 3 else 步行
  2  if x5<3.5 then node 4 elseif x5>=3.5 then node 5 else 步行
  3  if x13<0.45 then node 6 elseif x13>=0.45 then node 7 else 步行
  4  if x1<2.01504e+011 then node 8 elseif x1>=2.01504e+011 then node 9 else 公交车或地铁
  5  if x12<91.5 then node 10 elseif x12>=91.5 then node 11 else 步行
  6  if x11<11.5 then node 12 elseif x11>=11.5 then node 13 else 步行
  7  if x9<27.5 then node 14 elseif x9>=27.5 then node 15 else 公交车或地铁
  8  if x6<1.6 then node 16 elseif x6>=1.6 then node 17 else 公交车或地铁
  9  class = 步行
 10  if x8<86.5 then node 18 elseif x8>=86.5 then node 19 else 步行
 11  class = 公交车或地铁
 12  if x7<1.5 then node 20 elseif x7>=1.5 then node 21 else 步行
 13  if x9<94 then node 22 elseif x9>=94 then node 23 else 公交车或地铁
 14  if x9<8.5 then node 24 elseif x9>=8.5 then node 25 else 步行
 15  if x6<2.75 then node 26 elseif x6>=2.75 then node 27 else 公交车或地铁
 16  class = 公交车或地铁
 17  class = 步行
 18  class = 步行
 19  if x1<2.01502e+011 then node 28 elseif x1>=2.01502e+011 then node 29 else 步行
 20  class = 步行
 21  if x1<2.01504e+011 then node 30 elseif x1>=2.01504e+011 then node 31 else 步行
 22  if x4<6.95 then node 32 elseif x4>=6.95 then node 33 else 公交车或地铁
 23  class = 步行
 24  if x6<0.35 then node 34 elseif x6>=0.35 then node 35 else 公交车或地铁
 25  if x8<49.5 then node 36 elseif x8>=49.5 then node 37 else 步行
 26  if x6<2.25 then node 38 elseif x6>=2.25 then node 39 else 公交车或地铁
 27  if x11<26.5 then node 40 elseif x11>=26.5 then node 41 else 步行
 28  class = 步行
 29  class = 公交车或地铁
 30  class = 步行
 31  class = 公交车或地铁
 32  if x5<142.5 then node 42 elseif x5>=142.5 then node 43 else 步行
 33  class = 公交车或地铁
 34  class = 步行
 35  if x5<311 then node 44 elseif x5>=311 then node 45 else 公交车或地铁
 36  if x9<22 then node 46 elseif x9>=22 then node 47 else 公交车或地铁
 37  if x12<135 then node 48 elseif x12>=135 then node 49 else 步行
 38  if x5<102.5 then node 50 elseif x5>=102.5 then node 51 else 公交车或地铁
 39  if x8<18.5 then node 52 elseif x8>=18.5 then node 53 else 公交车或地铁
 40  if x12<40.5 then node 54 elseif x12>=40.5 then node 55 else 步行
 41  if x6<3 then node 56 elseif x6>=3 then node 57 else 公交车或地铁
 42  class = 步行
 43  if x1<2.01503e+011 then node 58 elseif x1>=2.01503e+011 then node 59 else 公交车或地铁
 44  class = 公交车或地铁
 45  class = 步行
 46  if x4<21.75 then node 60 elseif x4>=21.75 then node 61 else 公交车或地铁
 47  if x14<40.5 then node 62 elseif x14>=40.5 then node 63 else 步行
 48  if x12<78.5 then node 64 elseif x12>=78.5 then node 65 else 步行
 49  if x5<212 then node 66 elseif x5>=212 then node 67 else 公交车或地铁
 50  if x14<35.5 then node 68 elseif x14>=35.5 then node 69 else 公交车或地铁
 51  if x6<1.85 then node 70 elseif x6>=1.85 then node 71 else 步行
 52  class = 公交车或地铁

查看所有预测的分类标签

y_est
type classregtree

判断准确率

Remp

气温

hist(inData(:,4))

风向

hist(inData(:,5))

风速

hist(inData(:,6))

O3

hist(inData(:,10))

SO2

hist(inData(:,11))

NO2

hist(inData(:,12))

相关文章
|
3月前
|
传感器 机器学习/深度学习 算法
【使用 DSP 滤波器加速速度和位移】使用信号处理算法过滤加速度数据并将其转换为速度和位移研究(Matlab代码实现)
【使用 DSP 滤波器加速速度和位移】使用信号处理算法过滤加速度数据并将其转换为速度和位移研究(Matlab代码实现)
235 1
|
3月前
|
机器学习/深度学习 算法 调度
14种智能算法优化BP神经网络(14种方法)实现数据预测分类研究(Matlab代码实现)
14种智能算法优化BP神经网络(14种方法)实现数据预测分类研究(Matlab代码实现)
338 0
|
3月前
|
机器学习/深度学习 算法 安全
【图像处理】使用四树分割和直方图移动的可逆图像数据隐藏(Matlab代码实现)
【图像处理】使用四树分割和直方图移动的可逆图像数据隐藏(Matlab代码实现)
167 2
|
2月前
|
机器学习/深度学习 算法 新能源
基于动态非合作博弈的大规模电动汽车实时优化调度电动汽车决策研究(Matlab代码实现)
基于动态非合作博弈的大规模电动汽车实时优化调度电动汽车决策研究(Matlab代码实现)
|
2月前
|
机器学习/深度学习 人工智能 算法
【基于TTNRBO优化DBN回归预测】基于瞬态三角牛顿-拉夫逊优化算法(TTNRBO)优化深度信念网络(DBN)数据回归预测研究(Matlab代码实现)
【基于TTNRBO优化DBN回归预测】基于瞬态三角牛顿-拉夫逊优化算法(TTNRBO)优化深度信念网络(DBN)数据回归预测研究(Matlab代码实现)
120 0
|
2月前
|
存储 监控 并行计算
目标跟踪中常用点迹航迹数据关联算法的MATLAB实现
通过计算测量点与预测点之间的欧氏距离,选择最近邻点进行关联,适用于单目标跟踪场景。
|
3月前
|
传感器 机器学习/深度学习 算法
【室内导航通过视觉惯性数据融合】将用户携带的智能手机收集的惯性数据与手机相机获取的视觉信息进行融合研究(Matlab代码实现)
【室内导航通过视觉惯性数据融合】将用户携带的智能手机收集的惯性数据与手机相机获取的视觉信息进行融合研究(Matlab代码实现)
159 2
|
3月前
|
传感器 资源调度 算法
【数据融合】【状态估计】基于KF、UKF、EKF、PF、FKF、DKF卡尔曼滤波KF、无迹卡尔曼滤波UKF、拓展卡尔曼滤波数据融合研究(Matlab代码实现)
【数据融合】【状态估计】基于KF、UKF、EKF、PF、FKF、DKF卡尔曼滤波KF、无迹卡尔曼滤波UKF、拓展卡尔曼滤波数据融合研究(Matlab代码实现)
314 0
|
3月前
|
传感器 数据采集 存储
【无线传感器】使用 MATLAB和 XBee连续监控温度传感器无线网络研究(Matlab代码实现)
【无线传感器】使用 MATLAB和 XBee连续监控温度传感器无线网络研究(Matlab代码实现)
|
3月前
|
传感器 算法 定位技术
【GPS+INS在MAV导航上融合】基于间接卡尔曼滤波的IMU与GPS融合MATLAB仿真(IMU与GPS数据由仿真生成)
【GPS+INS在MAV导航上融合】基于间接卡尔曼滤波的IMU与GPS融合MATLAB仿真(IMU与GPS数据由仿真生成)
228 0

热门文章

最新文章