Matlab決策樹對空氣質(zhì)量和天氣溫度及天氣數(shù)據(jù)做交通出行推薦預(yù)測|附代碼數(shù)據(jù)
全文鏈接:http://tecdat.cn/?p=31784
原文出處:拓端數(shù)據(jù)部落公眾號
最近我們被客戶要求撰寫關(guān)于決策樹的研究報(bào)告,包括一些圖形和統(tǒng)計(jì)輸出。
為解決城市交通擁堵問題,本文提出了一種基于 Matlab決策樹的交通預(yù)測方法,我們通過采集上海地區(qū)的空氣質(zhì)量數(shù)據(jù)和溫度數(shù)據(jù),幫助客戶在 Matlab中實(shí)現(xiàn)決策樹建模,利用所提取的天氣和溫度特征建立決策樹,對未來的出行時(shí)間、出行路線等進(jìn)行預(yù)測。結(jié)果表明:該方法可實(shí)現(xiàn)交通時(shí)間、出行路線的預(yù)測,并能在未來三天進(jìn)行有效預(yù)測時(shí)間長度與空氣質(zhì)量、溫度相關(guān)。
數(shù)據(jù)
里面一個(gè)是天氣數(shù)據(jù)(區(qū)縣自動(dòng)站實(shí)況數(shù)據(jù)),只把地區(qū)為徐家匯的取出來,其余地點(diǎn)的不用參考。
另一個(gè)是空氣數(shù)據(jù)(實(shí)時(shí)空氣質(zhì)量數(shù)據(jù))。


預(yù)期結(jié)果
根據(jù)空氣中的空氣質(zhì)量和天氣數(shù)據(jù)中的溫度及天氣情況做一個(gè)交通出行的推薦。
舉個(gè)例子: 今天溫度0度 天氣晴朗 空氣質(zhì)量優(yōu) 出行方式可以為 公交車或地鐵。
今天溫度15度 天氣晴朗 空氣質(zhì)量優(yōu) 出行方式為 步行。
今天溫度15度 天氣晴朗 控制質(zhì)量輕度污染 出現(xiàn)方式為 公交車或地鐵。
讀取氣溫?cái)?shù)據(jù)
[data, ~, raw] = xlsread('區(qū)縣自動(dòng)站實(shí)況數(shù)據(jù).xlsx','Sheet2');
篩選對應(yīng)日期數(shù)據(jù)
data=data(1:9649,:);raw=raw(1:9649,:);
找出徐家匯地區(qū)的數(shù)據(jù)
index=strcmp(raw(:,3),'徐家匯')
讀取空氣質(zhì)量數(shù)據(jù)
[data2, ~, raw2, dateNums] = xlsread('實(shí)時(shí)空氣質(zhì)量數(shù)據(jù)(歷史)2.xlsx','Sheet1','','
篩選對應(yīng)日期數(shù)據(jù)
data2=data2(4415:end,:);raw2=raw2(4415:end,:);
得到對應(yīng)時(shí)間
index=1:3:2880
得到對應(yīng)時(shí)間的 空氣質(zhì)量數(shù)據(jù)
mydata=[raw,raw2];
建立決策規(guī)則
分類類別號
label=mydata(:,18);%label=label(2:end);
將類別號賦值給outData
outData=label;
獲得特征變量矩陣
inData = [data,data2]; % 輸入特征矩陣
根據(jù)訓(xùn)練集數(shù)據(jù)創(chuàng)建決策樹
classregtree(inData, o)
查看決策樹
view(mytree);

決策樹規(guī)則
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ù)測的分類標(biāo)簽
y_esttype classregtree
判斷準(zhǔn)確率
Remp
氣溫
hist(inData(:,4))

風(fēng)向
hist(inData(:,5))

風(fēng)速
hist(inData(:,6))

O3
hist(inData(:,10))

SO2
hist(inData(:,11))

?NO2
hist(inData(:,12))


最受歡迎的見解
1.PYTHON用戶流失數(shù)據(jù)挖掘:建立邏輯回歸、XGBOOST、隨機(jī)森林、決策樹、支持向量機(jī)、樸素貝葉斯模型和KMEANS聚類用戶畫像
2.R語言基于樹的方法:決策樹,隨機(jī)森林
3.python中使用scikit-learn和pandas決策樹
4.機(jī)器學(xué)習(xí):在SAS中運(yùn)行隨機(jī)森林?jǐn)?shù)據(jù)分析報(bào)告
5.R語言用隨機(jī)森林和文本挖掘提高航空公司客戶滿意度
6.機(jī)器學(xué)習(xí)助推快時(shí)尚精準(zhǔn)銷售時(shí)間序列
7.用機(jī)器學(xué)習(xí)識別不斷變化的股市狀況——隱馬爾可夫模型的應(yīng)用
8.python機(jī)器學(xué)習(xí):推薦系統(tǒng)實(shí)現(xiàn)(以矩陣分解來協(xié)同過濾)
9.python中用pytorch機(jī)器學(xué)習(xí)分類預(yù)測銀行客戶流失