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))

相关文章
|
4天前
|
算法 数据安全/隐私保护
matlab程序,傅里叶变换,频域数据,补零与不补零傅里叶变换
地震波格式转换、时程转换、峰值调整、规范反应谱、计算反应谱、计算持时、生成人工波、时频域转换、数据滤波、基线校正、Arias截波、傅里叶变换、耐震时程曲线、脉冲波合成与提取、三联反应谱、地震动参数、延性反应谱、地震波缩尺、功率谱密度
|
4天前
|
数据安全/隐私保护
matlab 曲线光滑,去毛刺,去离群值,数据滤波,高通滤波,低通滤波,带通滤波,带阻滤波
地震波格式转换、时程转换、峰值调整、规范反应谱、计算反应谱、计算持时、生成人工波、时频域转换、数据滤波、基线校正、Arias截波、傅里叶变换、耐震时程曲线、脉冲波合成与提取、三联反应谱、地震动参数、延性反应谱、地震波缩尺、功率谱密度
|
4天前
|
数据安全/隐私保护
时域与频域数据互相转换,傅里叶变换与逆傅里叶变换,matlab程序,时域转频域
地震波格式转换、时程转换、峰值调整、规范反应谱、计算反应谱、计算持时、生成人工波、时频域转换、数据滤波、基线校正、Arias截波、傅里叶变换、耐震时程曲线、脉冲波合成与提取、三联反应谱、地震动参数、延性反应谱、地震波缩尺、功率谱密度
基于混沌集成决策树的电能质量复合扰动识别(matlab代码)
基于混沌集成决策树的电能质量复合扰动识别(matlab代码)
|
7天前
|
计算机视觉
MATLAB用Lasso回归拟合高维数据和交叉验证
MATLAB用Lasso回归拟合高维数据和交叉验证
|
12天前
|
机器学习/深度学习 算法 数据可视化
Matlab决策树、模糊C-均值聚类算法分析高校教师职称学历评分可视化
Matlab决策树、模糊C-均值聚类算法分析高校教师职称学历评分可视化
|
13天前
|
SQL 移动开发 算法
MATLAB改进模糊C均值聚类FCM在电子商务信用评价应用:分析淘宝网店铺数据|数据分享
MATLAB改进模糊C均值聚类FCM在电子商务信用评价应用:分析淘宝网店铺数据|数据分享
|
4天前
|
数据安全/隐私保护
地震波功率谱密度函数、功率谱密度曲线,反应谱转功率谱,matlab代码
地震波格式转换、时程转换、峰值调整、规范反应谱、计算反应谱、计算持时、生成人工波、时频域转换、数据滤波、基线校正、Arias截波、傅里叶变换、耐震时程曲线、脉冲波合成与提取、三联反应谱、地震动参数、延性反应谱、地震波缩尺、功率谱密度
|
4天前
|
数据安全/隐私保护
耐震时程曲线,matlab代码,自定义反应谱与地震波,优化源代码,地震波耐震时程曲线
地震波格式转换、时程转换、峰值调整、规范反应谱、计算反应谱、计算持时、生成人工波、时频域转换、数据滤波、基线校正、Arias截波、傅里叶变换、耐震时程曲线、脉冲波合成与提取、三联反应谱、地震动参数、延性反应谱、地震波缩尺、功率谱密度
基于混合整数规划的微网储能电池容量规划(matlab代码)
基于混合整数规划的微网储能电池容量规划(matlab代码)

热门文章

最新文章