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

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

时间:2023-09-19 23:56:59浏览次数:54  
标签: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/17716198.html

相关文章

  • m基于码率兼容打孔LDPC码BP译码算法的matlab误码率仿真
    1.算法仿真效果matlab2022a仿真结果如下:2.算法涉及理论知识概要码率兼容打孔LDPC码BP译码算法是一种改进的LDPC译码算法,能够在不同码率下实现更好的译码性能。该算法通过在LDPC码中引入打孔操作,使得码率可以灵活地调整,同时利用BP(BeliefPropagation)译码算法进行迭代译码,提高了......
  • 2023年9月19日 天气:阴
    今天学习了数据结构的栈,然后上了马克思基本原理,接着下午上了英语课,上课学会了十个单词。然后在网上学习了Javaweb的课程。然后学习了一下写一个倒计时的代码。publicclassCountdownTime{publicstaticvoidmain(String[]args){LocalDateTime......
  • m基于码率兼容打孔LDPC码BP译码算法的matlab误码率仿真
    1.算法仿真效果matlab2022a仿真结果如下:   2.算法涉及理论知识概要       码率兼容打孔LDPC码BP译码算法是一种改进的LDPC译码算法,能够在不同码率下实现更好的译码性能。该算法通过在LDPC码中引入打孔操作,使得码率可以灵活地调整,同时利用BP(BeliefPropagation)译......
  • 安装matlab少量版
    安装matlab完整版本往往很大,其中很多工具箱也不一定总会用到,下面是一个参考链接,推荐参考:https://www.tiger2doudou.com/doku.php/coding:matlab:a_clean_install_list PS:2017b以上有MappingToolbox按照需求安装可以大大减少体积~附上:MATLAB2017b安装教程参考https://mp......
  • 决策树案例分析
    决策树(DecisionTree)常用于研究类别归属和预测关系的模型,比如是否抽烟、是否喝酒、年龄、体重等4项个人特征可能会影响到‘是否患癌症’,上述4项个人特征称作‘特征’,也即自变量(影响因素X),‘是否患癌症’称为‘标签’,也即因变量(被影响项Y)。决策树模型时,其可首先对年龄进行划分,比如......
  • 图像去噪及其Matlab实现
    ✅作者简介:热爱科研的算法开发者,Python、Matlab项目可交流、沟通、学习。......
  • Matlab-resample
    1.resample步骤1:低通滤波首先,resample函数会应用一个低通滤波器,以滤除输入信号中高于重采样频率的频率成分。这是为了防止混叠现象,即重采样后出现在新采样率频带之外的频率成分。在MATLAB中,默认使用一个FIR滤波器进行低通滤波,滤波器的设计根据重采样因子和滤波器长度来确定。此外......
  • 机器学习——决策树模型
    谈起过年回家的年轻人最怕什么、最烦什么?无外乎就是面对那些七大姑、八大姨的催结婚、催生子、催相亲、催买房……说起这些亲戚们是如何判断催什么,不得不让我们想起经典的决策树模型。决策树是一个用于分类和回归的机器学习模型。通过对输入对象数据特征进行一系列条件划分构建一个......
  • 基于DNN深度学习网络的OFDM+QPSK信号检测算法matlab仿真
    1.算法运行效果图预览   2.算法运行软件版本matlab2022a  3.算法理论概述        正交频分复用(OFDM)是一种多载波调制技术,已经广泛应用于数字通信领域。OFDM信号检测是接收端的关键问题之一,目的是将接收到的OFDM信号恢复为原始数据。由于OFDM信号具有高带......
  • Matlab : 数据类型与文件读写
    学习一门技术的最佳方式之一是阅读官方文档。MATLAB官方文档提供了关于各种主要数据类型的详细介绍。数值类型(numeric)在MATLAB中,数值类型的变量默认为双精度浮点数(double),但可以使用类型转换将其转换为其他数值类型。以下是MATLAB支持的数值类型:double:双精度浮点数single:单精度......