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

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

时间:2023-03-10 15:22:05浏览次数:49  
标签:node 步行 公交车 天气 else 地铁 Matlab class 决策树

全文链接:http://tecdat.cn/?p=31784

原文出处:拓端数据部落公众号

为解决城市交通拥堵问题,本文提出了一种基于 Matlab决策树的交通预测方法,我们通过采集上海地区的空气质量数据和温度数据,帮助客户在 Matlab中实现决策树建模,利用所提取的天气和温度特征建立决策树,对未来的出行时间、出行路线等进行预测。结果表明:该方法可实现交通时间、出行路线的预测,并能在未来三天进行有效预测时间长度与空气质量、温度相关。

数据

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

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

image.png

image.png

预期结果

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

举个例子: 今天温度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);

图片1.png

决策树规则

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

image.png

风向

 hist(inData(:,5))

image.png

风速

 hist(inData(:,6))

image.png

O3

 hist(inData(:,10))

image.png

SO2

 hist(inData(:,11))

image.png NO2

 hist(inData(:,12))

image.png


QQ截图20230122145443.png

最受欢迎的见解

1.PYTHON用户流失数据挖掘:建立逻辑回归、XGBOOST、随机森林、决策树、支持向量机、朴素贝叶斯模型和KMEANS聚类用户画像

2.R语言基于树的方法:决策树,随机森林

3.python中使用scikit-learn和pandas决策树

4.机器学习:在SAS中运行随机森林数据分析报告

5.R语言用随机森林和文本挖掘提高航空公司客户满意度

6.机器学习助推快时尚精准销售时间序列

7.用机器学习识别不断变化的股市状况——隐马尔可夫模型的应用

8.python机器学习:推荐系统实现(以矩阵分解来协同过滤)

9.python中用pytorch机器学习分类预测银行客户流失

标签:node,步行,公交车,天气,else,地铁,Matlab,class,决策树
From: https://www.cnblogs.com/tecdat/p/17203469.html

相关文章

  • matlab2c使用c++实现matlab函数系列教程-sort函数
    ​​​​全栈工程师开发手册(作者:栾鹏)​​matlab2c动态链接库下载​​​matlab库函数大全matlab2c基础教程matlab2c开发全解教程matlab2c调用方法:1、下载动态链接库2、......
  • matlab2c使用c++实现matlab函数系列教程-trace函数
    ​​​​全栈工程师开发手册(作者:栾鹏)​​matlab2c动态链接库下载​​​matlab库函数大全matlab2c基础教程matlab2c开发全解教程matlab2c调用方法:1、下载动态链接库2、......
  • matlab2c使用c++实现matlab函数系列教程-reshape函数
    ​​​​全栈工程师开发手册(作者:栾鹏)​​matlab2c动态链接库下载​​​matlab库函数大全matlab2c基础教程matlab2c开发全解教程matlab2c调用方法:1、下载动态链接库2、......
  • matlab2c使用c++实现matlab函数系列教程-triu函数
    ​​​​全栈工程师开发手册(作者:栾鹏)​​matlab2c动态链接库下载​​​matlab库函数大全matlab2c基础教程matlab2c开发全解教程matlab2c调用方法:1、下载动态链接库2、......
  • 基于步态能量图和CNN卷积神经网络的人体步态识别matlab仿真
    1.算法描述       步态能量图(GaitEngeryImage,GEI)是步态检测中最非常常用的特征,提取方法简单,也能很好的表现步态的速度,形态等特征。其定义如下:     ......
  • m自适应FSK解调系统误码率matlab仿真
    1.算法描述FSK信号的解调也有非相干和相干两种,FSK信号可以看作是用两个频率源交替传输得到的,所以FSK的接收机由两个并联的ASK接收机组成。(1)相干解调相干解调是利用......
  • 基于PSO粒子群优化的带时间窗VRPTW问题matlab仿真
    1.算法描述粒子群优化算法(PSO)是一种进化计算技术(evolutionarycomputation),1995年由Eberhart博士和kennedy博士提出,源于对鸟群捕食的行为研究。该算法最初是受到飞......
  • m自适应FSK解调系统误码率matlab仿真
    1.算法描述       FSK信号的解调也有非相干和相干两种,FSK信号可以看作是用两个频率源交替传输得到的,所以FSK的接收机由两个并联的ASK接收机组成。 (1)相干解调......
  • matlab 导入图片
    去除图框刻度找到预处理函数如下图:   去除图框刻度代码:axes(handles.axes1);clareset;boxon;set(gca,'XTickLabel',[],'YTickLabel',[]);axes(handle......
  • MATLAB:while的用法
    参考ROMS网格制作的部分代码lonmin=110;%Minimumlongitude[degreeeast]lonmax=130;%Maximumlongitude[degreeeast]latmin=20;%Minimumlati......