fifth commits

This commit is contained in:
Bairly 2025-03-26 16:59:57 +08:00
parent a613f0eed1
commit 5a26dd003a
27 changed files with 173 additions and 201 deletions

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 354 KiB

After

Width:  |  Height:  |  Size: 347 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 362 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 KiB

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 45 KiB

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 47 KiB

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 47 KiB

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 44 KiB

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 44 KiB

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 45 KiB

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 500 KiB

After

Width:  |  Height:  |  Size: 484 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 89 KiB

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 317 KiB

After

Width:  |  Height:  |  Size: 276 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 128 KiB

After

Width:  |  Height:  |  Size: 123 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 142 KiB

After

Width:  |  Height:  |  Size: 138 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 132 KiB

After

Width:  |  Height:  |  Size: 127 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 128 KiB

After

Width:  |  Height:  |  Size: 124 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 134 KiB

After

Width:  |  Height:  |  Size: 131 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 121 KiB

After

Width:  |  Height:  |  Size: 116 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 128 KiB

After

Width:  |  Height:  |  Size: 122 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 317 KiB

After

Width:  |  Height:  |  Size: 309 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 588 KiB

After

Width:  |  Height:  |  Size: 576 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 155 KiB

After

Width:  |  Height:  |  Size: 124 KiB

View File

@ -27,7 +27,7 @@
### 主成分分析解读
1. 检验指标:
- KMO值: 0.762>0.7。
- 巴赫利特检验卡方值: 90424.712, p值: 0.0,显著。
- 巴赫利特检验卡方值: 90424.712, p值: 0.0<0.001显著
- 提取5个特征值大于1的因子作为主成分累积方差贡献率为78.89%。
- 检验效果较好,说明数据适合主成分分析降维。
2. 旋转载荷矩阵解读:
@ -82,13 +82,13 @@
- 最终选择AIC最低的候选模型
4. **评估指标**
- RMSE: 14.326
- R-squared: 0.892
- MAE: 9.815
- 相比XGBoost模型预测精度略低,但保持时间序列特性
- RMSE: 11.893
- R-squared: 0.932
- MAE: 7.744
- 相比XGBoost模型预测精度相近,但保持时间序列特性
5. **预测结果可视化**
- 滚动预测效果图:![SARIMA预测](./images/sarima_forecast.png)
- 滚动预测效果图:![SARIMA预测](./images/AQI-SARIMA.png)
- 置信区间覆盖率达到95%,实际值大部分落在预测区间内
6. **残差分析**
@ -101,10 +101,11 @@
1. 该模型使用历史AQI数据并进行周期性编码和滞后特征构建3小时粒度的滞后特征最多7天作为特征工程。
2. 每次预测均采用该时间点以前的真实数据,即每次预测均为单步预测。
3. 使用随机搜索法参数调优。
4. 评估指标:效果很好
4. 评估指标:
- RMSE: 11.815
- R-squared: 0.929
- MAE: 7.722
5. 预测图:![](./images/xg_by_step.png)
6. 重要特征观察图AQI_lag_1最为重要即该时刻的AQI主要由前1个观测时刻决定。AQI_lag_21也较为重要。day_of_week显示影响较小但不是完全没有。
7. 其实也做了利用递归直接预测一整个月的,效果看图就很明了了![](./images/XG_pred_by_recursion.png)
6. 重要特征:![](./images/xg_feature_importance.png)AQI_lag_1最为重要即该时刻的AQI主要由前1个观测时刻决定。AQI_lag_21也较为重要。day_of_week显示影响较小但不是完全没有。
7. 模型比较与SARIMA模型相近在单步预测的准确度上几乎不相上下。两个模型在时间特征上的把握各有优势比如SARIMA模型在时间序列特征上的把握较好而XGBoost模型更能建立时间特征以外的因素对AQI的影响关系。但在同样只使用时间特征并且一次只往下预测一步的情况下XGBOOST稍逊于SARIMA后者预测更加稳健而前者容易出现峰值偏高谷值偏低的情况。
8. 其实也做了利用递归直接预测一整个月的预测结果在2天以内尚可而后趋于平缓具体效果看图就很明了了。![](./images/XG_pred_by_recursion.png)

4
requirements.txt Normal file
View File

@ -0,0 +1,4 @@
matplotlib==3.8.0
numpy==2.2.4
pandas==2.2.3
seaborn==0.13.2

View File

@ -1,32 +0,0 @@
日期,实际值,预测值,预测下限,预测上限
2023-10-01,28.636363636363626,33.8493112926664,-47.635233636420566,115.33385622175336
2023-10-02,49.727509469696976,38.66548623183452,-42.82536438890146,120.1563368525705
2023-10-03,54.00378787878786,51.59866579632718,-29.89349013130868,133.09082172396305
2023-10-04,23.787878787878775,49.52408793635019,-31.975556791081225,131.0237326637816
2023-10-05,25.58712121212121,30.456530971610437,-51.04494428047694,111.95800622369781
2023-10-06,35.7310606060606,35.746745423979746,-45.75528519745549,117.24877604541498
2023-10-07,60.458333333333336,44.79351798522558,-36.708655136994636,126.29569110744579
2023-10-08,45.109848484848484,55.19286349902602,-26.308989959303503,136.69471695735552
2023-10-09,22.24206912878789,42.96484817061444,-38.533998688523916,124.46369502975278
2023-10-10,29.909090909090914,30.472462505431565,-51.02484294737681,111.96976795823994
2023-10-11,51.76337594696972,36.828726721058544,-44.65444843021167,118.31190187232876
2023-10-12,91.55764678030303,49.28101201127273,-32.19996266583957,130.76198668838504
2023-10-13,56.132575757575786,71.2726908163902,-10.207314064424025,152.75269569720442
2023-10-14,25.9090909090909,49.357596859306355,-32.114598711533134,130.82979243014586
2023-10-15,29.515151515151512,31.565845981296714,-49.897131310870776,113.02882327346421
2023-10-16,35.871212121212125,36.71261110903076,-44.74640914144864,118.17163135951016
2023-10-17,59.96910511363636,40.90517881218401,-40.53040748891922,122.34076511328723
2023-10-18,31.07125946969696,54.730426193951956,-26.70243278829031,136.16328517619422
2023-10-19,21.47028882575759,33.293474144135594,-48.1146067381603,114.70155502643149
2023-10-20,24.37121212121211,31.755445784946758,-49.65029050692998,113.1611820768235
2023-10-21,36.86363636363636,36.817366250812796,-44.50994068018028,118.14467318180587
2023-10-22,51.18181818181816,42.106111359156806,-39.21739699758937,123.42961971590299
2023-10-23,116.10771780303035,48.656996034766536,-32.543358544865384,129.85735061439846
2023-10-24,149.18323863636374,84.37233576451568,3.17385767808355,165.57081385094781
2023-10-25,92.82019412878783,99.46879763697234,18.271785495936854,180.66580977800783
2023-10-26,42.073863636363654,59.3336809840356,-21.853904047755073,140.52126601582628
2023-10-27,62.851543407869016,38.4106814311253,-42.772817201854096,119.59418006410469
2023-10-28,97.23414971285435,60.366035283496224,-20.799260620504604,141.53133118749705
2023-10-29,175.54887585532762,78.4999966197246,-2.6629202331887285,159.6629134726379
2023-10-30,142.330137310606,121.36437355870153,40.20258279816625,202.5261643192368
2023-10-31,117.67966077101673,92.66882789754769,11.508510163001674,173.82914563209368
1 日期 实际值 预测值 预测下限 预测上限
2 2023-10-01 28.636363636363626 33.8493112926664 -47.635233636420566 115.33385622175336
3 2023-10-02 49.727509469696976 38.66548623183452 -42.82536438890146 120.1563368525705
4 2023-10-03 54.00378787878786 51.59866579632718 -29.89349013130868 133.09082172396305
5 2023-10-04 23.787878787878775 49.52408793635019 -31.975556791081225 131.0237326637816
6 2023-10-05 25.58712121212121 30.456530971610437 -51.04494428047694 111.95800622369781
7 2023-10-06 35.7310606060606 35.746745423979746 -45.75528519745549 117.24877604541498
8 2023-10-07 60.458333333333336 44.79351798522558 -36.708655136994636 126.29569110744579
9 2023-10-08 45.109848484848484 55.19286349902602 -26.308989959303503 136.69471695735552
10 2023-10-09 22.24206912878789 42.96484817061444 -38.533998688523916 124.46369502975278
11 2023-10-10 29.909090909090914 30.472462505431565 -51.02484294737681 111.96976795823994
12 2023-10-11 51.76337594696972 36.828726721058544 -44.65444843021167 118.31190187232876
13 2023-10-12 91.55764678030303 49.28101201127273 -32.19996266583957 130.76198668838504
14 2023-10-13 56.132575757575786 71.2726908163902 -10.207314064424025 152.75269569720442
15 2023-10-14 25.9090909090909 49.357596859306355 -32.114598711533134 130.82979243014586
16 2023-10-15 29.515151515151512 31.565845981296714 -49.897131310870776 113.02882327346421
17 2023-10-16 35.871212121212125 36.71261110903076 -44.74640914144864 118.17163135951016
18 2023-10-17 59.96910511363636 40.90517881218401 -40.53040748891922 122.34076511328723
19 2023-10-18 31.07125946969696 54.730426193951956 -26.70243278829031 136.16328517619422
20 2023-10-19 21.47028882575759 33.293474144135594 -48.1146067381603 114.70155502643149
21 2023-10-20 24.37121212121211 31.755445784946758 -49.65029050692998 113.1611820768235
22 2023-10-21 36.86363636363636 36.817366250812796 -44.50994068018028 118.14467318180587
23 2023-10-22 51.18181818181816 42.106111359156806 -39.21739699758937 123.42961971590299
24 2023-10-23 116.10771780303035 48.656996034766536 -32.543358544865384 129.85735061439846
25 2023-10-24 149.18323863636374 84.37233576451568 3.17385767808355 165.57081385094781
26 2023-10-25 92.82019412878783 99.46879763697234 18.271785495936854 180.66580977800783
27 2023-10-26 42.073863636363654 59.3336809840356 -21.853904047755073 140.52126601582628
28 2023-10-27 62.851543407869016 38.4106814311253 -42.772817201854096 119.59418006410469
29 2023-10-28 97.23414971285435 60.366035283496224 -20.799260620504604 141.53133118749705
30 2023-10-29 175.54887585532762 78.4999966197246 -2.6629202331887285 159.6629134726379
31 2023-10-30 142.330137310606 121.36437355870153 40.20258279816625 202.5261643192368
32 2023-10-31 117.67966077101673 92.66882789754769 11.508510163001674 173.82914563209368