diff --git "a/5 \347\216\257\345\242\203\346\261\241\346\237\223\347\232\204\351\242\204\346\265\213/README.md" "b/5 \347\216\257\345\242\203\346\261\241\346\237\223\347\232\204\351\242\204\346\265\213/README.md" index 00a9c521..c376d08c 100644 --- "a/5 \347\216\257\345\242\203\346\261\241\346\237\223\347\232\204\351\242\204\346\265\213/README.md" +++ "b/5 \347\216\257\345\242\203\346\261\241\346\237\223\347\232\204\351\242\204\346\265\213/README.md" @@ -3,3 +3,4 @@ 近年来,随着人工智能、大数据、云计算等技术的成熟,环保领域正向智能化转变,因为 AI 的加入环境保护充满了无限的想象,而其中环境污染预测就是重要一环——利用环境传感器、智能摄像头、环保设备 IoT 化,我们可以实现对空气、水源、噪声等污染情况进行实时监测及预警,做到“未病先知,未病先治”,进一步改善环境污染。 请以“环境污染的预测”为主题,利用人工智能技术完成一款产品(软件或硬件)的开发。 + diff --git "a/5 \347\216\257\345\242\203\346\261\241\346\237\223\347\232\204\351\242\204\346\265\213/pm2.5\347\232\204\347\272\277\346\200\247\345\233\236\345\275\222\351\242\204\346\265\213\346\250\241\345\236\213-\344\273\212\345\244\251\347\235\241\351\206\222\344\272\206\345\220\227/Figure_1.png" "b/5 \347\216\257\345\242\203\346\261\241\346\237\223\347\232\204\351\242\204\346\265\213/pm2.5\347\232\204\347\272\277\346\200\247\345\233\236\345\275\222\351\242\204\346\265\213\346\250\241\345\236\213-\344\273\212\345\244\251\347\235\241\351\206\222\344\272\206\345\220\227/Figure_1.png" new file mode 100644 index 00000000..e5731f0e Binary files /dev/null and "b/5 \347\216\257\345\242\203\346\261\241\346\237\223\347\232\204\351\242\204\346\265\213/pm2.5\347\232\204\347\272\277\346\200\247\345\233\236\345\275\222\351\242\204\346\265\213\346\250\241\345\236\213-\344\273\212\345\244\251\347\235\241\351\206\222\344\272\206\345\220\227/Figure_1.png" differ diff --git "a/5 \347\216\257\345\242\203\346\261\241\346\237\223\347\232\204\351\242\204\346\265\213/pm2.5\347\232\204\347\272\277\346\200\247\345\233\236\345\275\222\351\242\204\346\265\213\346\250\241\345\236\213-\344\273\212\345\244\251\347\235\241\351\206\222\344\272\206\345\220\227/Figure_2.png" "b/5 \347\216\257\345\242\203\346\261\241\346\237\223\347\232\204\351\242\204\346\265\213/pm2.5\347\232\204\347\272\277\346\200\247\345\233\236\345\275\222\351\242\204\346\265\213\346\250\241\345\236\213-\344\273\212\345\244\251\347\235\241\351\206\222\344\272\206\345\220\227/Figure_2.png" new file mode 100644 index 00000000..0b4173cf Binary files /dev/null and "b/5 \347\216\257\345\242\203\346\261\241\346\237\223\347\232\204\351\242\204\346\265\213/pm2.5\347\232\204\347\272\277\346\200\247\345\233\236\345\275\222\351\242\204\346\265\213\346\250\241\345\236\213-\344\273\212\345\244\251\347\235\241\351\206\222\344\272\206\345\220\227/Figure_2.png" differ diff --git "a/5 \347\216\257\345\242\203\346\261\241\346\237\223\347\232\204\351\242\204\346\265\213/pm2.5\347\232\204\347\272\277\346\200\247\345\233\236\345\275\222\351\242\204\346\265\213\346\250\241\345\236\213-\344\273\212\345\244\251\347\235\241\351\206\222\344\272\206\345\220\227/Normalization.py" "b/5 \347\216\257\345\242\203\346\261\241\346\237\223\347\232\204\351\242\204\346\265\213/pm2.5\347\232\204\347\272\277\346\200\247\345\233\236\345\275\222\351\242\204\346\265\213\346\250\241\345\236\213-\344\273\212\345\244\251\347\235\241\351\206\222\344\272\206\345\220\227/Normalization.py" new file mode 100644 index 00000000..358e15d1 --- /dev/null +++ "b/5 \347\216\257\345\242\203\346\261\241\346\237\223\347\232\204\351\242\204\346\265\213/pm2.5\347\232\204\347\272\277\346\200\247\345\233\236\345\275\222\351\242\204\346\265\213\346\250\241\345\236\213-\344\273\212\345\244\251\347\235\241\351\206\222\344\272\206\345\220\227/Normalization.py" @@ -0,0 +1,23 @@ +import pandas as pd +import matplotlib as mpl +import seaborn as sns +import csv + +from sklearn import preprocessing +from matplotlib import pyplot as plt + +def Normalization(): + data_file = "..\PRSA2017_Data_20130301-20170228\PRSA_Data_20130301-20170228\simpleDataSet.csv" + pd_data = pd.read_csv(data_file) + sam = [] + a = ["PM10", "SO2","NO2","CO","PRES","DEWP"] + for i in a: + y = pd_data.loc[:, i] + ys = list(preprocessing.scale(y)) + sam.append(ys) + + print(len(sam)) + with open('eth2.csv', 'w') as file: + writer = csv.writer(file) + for i in range(len(sam[0])): + writer.writerow([sam[0][i],sam[1][i],sam[2][i],sam[3][i],sam[4][i],sam[5][i]]) diff --git "a/5 \347\216\257\345\242\203\346\261\241\346\237\223\347\232\204\351\242\204\346\265\213/pm2.5\347\232\204\347\272\277\346\200\247\345\233\236\345\275\222\351\242\204\346\265\213\346\250\241\345\236\213-\344\273\212\345\244\251\347\235\241\351\206\222\344\272\206\345\220\227/README.md" "b/5 \347\216\257\345\242\203\346\261\241\346\237\223\347\232\204\351\242\204\346\265\213/pm2.5\347\232\204\347\272\277\346\200\247\345\233\236\345\275\222\351\242\204\346\265\213\346\250\241\345\236\213-\344\273\212\345\244\251\347\235\241\351\206\222\344\272\206\345\220\227/README.md" new file mode 100644 index 00000000..a7795ced --- /dev/null +++ "b/5 \347\216\257\345\242\203\346\261\241\346\237\223\347\232\204\351\242\204\346\265\213/pm2.5\347\232\204\347\272\277\346\200\247\345\233\236\345\275\222\351\242\204\346\265\213\346\250\241\345\236\213-\344\273\212\345\244\251\347\235\241\351\206\222\344\272\206\345\220\227/README.md" @@ -0,0 +1,36 @@ +# 基于线性回归的PM2.5的预测模型 + +## 作品介绍 + +### 背景 + +随着经济社会发展,空气污染情况成为我们不得不关注的问题,其中Pm2.5为重要的空气质量评价指标,本项目使用`sklearn`进行线性回归建模,并进行预测。 + +### 截图 + +![](./Figure_2.png) + +经过绘图发现,PM2.5和空气中$SO_2$、$NO_2$、$CO$, 以及气压、露点温度近似成线性关系,使用sklearn中的线性回归模型进行训练拟合并预测 + +![](./Figure_1.png) + +取数据中的$20\%$作为测试数据验证模型的可靠性,如上图所示。 + +**数据来源**: + +[UCI Machine Learning Repository](https://archive.ics.uci.edu/ml/datasets.php?format=mat&task=&att=&area=phys&numAtt=10to100&numIns=&type=ts&sort=attUp&view=list) + +## 团队:今天睡醒了吗 + +**成员**:iLern + +**联系方式**: + +> email: Taisitong@outlook.com +> +> qq: 416138794 + +## 使用到的AWS技术 + +`Amazon SageMaker` + diff --git "a/5 \347\216\257\345\242\203\346\261\241\346\237\223\347\232\204\351\242\204\346\265\213/pm2.5\347\232\204\347\272\277\346\200\247\345\233\236\345\275\222\351\242\204\346\265\213\346\250\241\345\236\213-\344\273\212\345\244\251\347\235\241\351\206\222\344\272\206\345\220\227/__pycache__/Normalization.cpython-38.pyc" "b/5 \347\216\257\345\242\203\346\261\241\346\237\223\347\232\204\351\242\204\346\265\213/pm2.5\347\232\204\347\272\277\346\200\247\345\233\236\345\275\222\351\242\204\346\265\213\346\250\241\345\236\213-\344\273\212\345\244\251\347\235\241\351\206\222\344\272\206\345\220\227/__pycache__/Normalization.cpython-38.pyc" new file mode 100644 index 00000000..cfcecbb8 Binary files /dev/null and "b/5 \347\216\257\345\242\203\346\261\241\346\237\223\347\232\204\351\242\204\346\265\213/pm2.5\347\232\204\347\272\277\346\200\247\345\233\236\345\275\222\351\242\204\346\265\213\346\250\241\345\236\213-\344\273\212\345\244\251\347\235\241\351\206\222\344\272\206\345\220\227/__pycache__/Normalization.cpython-38.pyc" differ diff --git "a/5 \347\216\257\345\242\203\346\261\241\346\237\223\347\232\204\351\242\204\346\265\213/pm2.5\347\232\204\347\272\277\346\200\247\345\233\236\345\275\222\351\242\204\346\265\213\346\250\241\345\236\213-\344\273\212\345\244\251\347\235\241\351\206\222\344\272\206\345\220\227/__pycache__/display_lr.cpython-38.pyc" "b/5 \347\216\257\345\242\203\346\261\241\346\237\223\347\232\204\351\242\204\346\265\213/pm2.5\347\232\204\347\272\277\346\200\247\345\233\236\345\275\222\351\242\204\346\265\213\346\250\241\345\236\213-\344\273\212\345\244\251\347\235\241\351\206\222\344\272\206\345\220\227/__pycache__/display_lr.cpython-38.pyc" new file mode 100644 index 00000000..a0c461c9 Binary files /dev/null and "b/5 \347\216\257\345\242\203\346\261\241\346\237\223\347\232\204\351\242\204\346\265\213/pm2.5\347\232\204\347\272\277\346\200\247\345\233\236\345\275\222\351\242\204\346\265\213\346\250\241\345\236\213-\344\273\212\345\244\251\347\235\241\351\206\222\344\272\206\345\220\227/__pycache__/display_lr.cpython-38.pyc" differ diff --git "a/5 \347\216\257\345\242\203\346\261\241\346\237\223\347\232\204\351\242\204\346\265\213/pm2.5\347\232\204\347\272\277\346\200\247\345\233\236\345\275\222\351\242\204\346\265\213\346\250\241\345\236\213-\344\273\212\345\244\251\347\235\241\351\206\222\344\272\206\345\220\227/__pycache__/predict.cpython-38.pyc" "b/5 \347\216\257\345\242\203\346\261\241\346\237\223\347\232\204\351\242\204\346\265\213/pm2.5\347\232\204\347\272\277\346\200\247\345\233\236\345\275\222\351\242\204\346\265\213\346\250\241\345\236\213-\344\273\212\345\244\251\347\235\241\351\206\222\344\272\206\345\220\227/__pycache__/predict.cpython-38.pyc" new file mode 100644 index 00000000..e0f90275 Binary files /dev/null and "b/5 \347\216\257\345\242\203\346\261\241\346\237\223\347\232\204\351\242\204\346\265\213/pm2.5\347\232\204\347\272\277\346\200\247\345\233\236\345\275\222\351\242\204\346\265\213\346\250\241\345\236\213-\344\273\212\345\244\251\347\235\241\351\206\222\344\272\206\345\220\227/__pycache__/predict.cpython-38.pyc" differ diff --git "a/5 \347\216\257\345\242\203\346\261\241\346\237\223\347\232\204\351\242\204\346\265\213/pm2.5\347\232\204\347\272\277\346\200\247\345\233\236\345\275\222\351\242\204\346\265\213\346\250\241\345\236\213-\344\273\212\345\244\251\347\235\241\351\206\222\344\272\206\345\220\227/display_lr.py" "b/5 \347\216\257\345\242\203\346\261\241\346\237\223\347\232\204\351\242\204\346\265\213/pm2.5\347\232\204\347\272\277\346\200\247\345\233\236\345\275\222\351\242\204\346\265\213\346\250\241\345\236\213-\344\273\212\345\244\251\347\235\241\351\206\222\344\272\206\345\220\227/display_lr.py" new file mode 100644 index 00000000..ae683e57 --- /dev/null +++ "b/5 \347\216\257\345\242\203\346\261\241\346\237\223\347\232\204\351\242\204\346\265\213/pm2.5\347\232\204\347\272\277\346\200\247\345\233\236\345\275\222\351\242\204\346\265\213\346\250\241\345\236\213-\344\273\212\345\244\251\347\235\241\351\206\222\344\272\206\345\220\227/display_lr.py" @@ -0,0 +1,21 @@ +import pandas as pd +import matplotlib as mpl +import seaborn as sns + +from matplotlib import pyplot as plt + +# data_file = "..\PRSA2017_Data_20130301-20170228\PRSA_Data_20130301-20170228\PRSA_Data_Aotizhongxin_20130301-20170228.csv" +data_file = "..\PRSA2017_Data_20130301-20170228\PRSA_Data_20130301-20170228\simpleDataSet.csv" + +def display_data(): + pd_data = pd.read_csv(data_file) + print(f'pd_data.head(10) = \n{pd_data.head(10)}') + mpl.rcParams['axes.unicode_minus'] = False + sns.pairplot(pd_data, + x_vars = ["PM10", "SO2","NO2","CO","PRES","DEWP"], + y_vars = ["PM2.5"], + # dropna = True, + kind = "reg", + height = 5, + aspect = 0.7) + plt.show() diff --git "a/5 \347\216\257\345\242\203\346\261\241\346\237\223\347\232\204\351\242\204\346\265\213/pm2.5\347\232\204\347\272\277\346\200\247\345\233\236\345\275\222\351\242\204\346\265\213\346\250\241\345\236\213-\344\273\212\345\244\251\347\235\241\351\206\222\344\272\206\345\220\227/eth2.csv" "b/5 \347\216\257\345\242\203\346\261\241\346\237\223\347\232\204\351\242\204\346\265\213/pm2.5\347\232\204\347\272\277\346\200\247\345\233\236\345\275\222\351\242\204\346\265\213\346\250\241\345\236\213-\344\273\212\345\244\251\347\235\241\351\206\222\344\272\206\345\220\227/eth2.csv" new file mode 100644 index 00000000..73ffd2e6 --- /dev/null +++ "b/5 \347\216\257\345\242\203\346\261\241\346\237\223\347\232\204\351\242\204\346\265\213/pm2.5\347\232\204\347\272\277\346\200\247\345\233\236\345\275\222\351\242\204\346\265\213\346\250\241\345\236\213-\344\273\212\345\244\251\347\235\241\351\206\222\344\272\206\345\220\227/eth2.csv" @@ -0,0 +1,150 @@ +-1.267467649597359,-1.491002935581235,-1.0587666220112426,1.2644727630246153,-1.0339884811974738,0.7633688133086369,-1.413945935100849 +-1.267467649597359,-1.491002935581235,-1.0587666220112426,1.2644727630246153,-1.1066340419373433,0.788687845259178,-1.2997645675287748 +-1.244062004427952,-1.4328278678293143,-1.0587666220112426,1.1222640174173484,-1.1066340419373433,0.8266663931849753,-1.2997645675287748 +-1.1036281334115103,-1.413436178578674,-1.0587666220112426,1.0867118310155317,-1.161118212492245,0.9532615529376519,-1.5281273026729225 +-1.0802224882421034,-1.3940444893280337,-1.0587666220112426,1.0867118310155317,-1.2700865536020491,1.0418781647645314,-1.5471575306016019 +-0.9397886172256619,-1.2776943538241923,-0.9778169799840779,0.8733987126046313,-1.3064093339719838,1.0925162286655847,-1.566187758530281 +-0.9397886172256619,-1.0062107043152289,-0.8968673379569131,0.3045637301755635,-1.3790548947118533,1.2064518724430053,-1.4710366188868862 +-0.9163829720562549,-0.8316855010594666,-0.8968673379569131,0.05569842536284634,-1.1974409928621799,1.3203875162204257,-1.4710366188868862 +-0.9865999075644757,-0.7929021225581862,-0.8968673379569131,0.12680279816647982,-0.8886973597177351,1.4343231599978177,-1.4900668468155647 +-1.0802224882421034,-1.0837774613177897,-0.9778169799840779,0.6245334077919141,-0.6889220676830943,1.4596421919483586,-1.509097074744244 +-1.1504394237503242,-1.3940444893280337,-0.9778169799840779,1.0867118310155317,-0.5617923363883229,1.4216636440225614,-1.5281273026729225 +-1.1504394237503242,-1.3552611108267534,-0.9778169799840779,1.051159644613715,-0.3801784345386496,1.4216636440225614,-1.7374598098883918 +-1.1972507140891382,-1.3746528000773934,-1.0587666220112426,1.157816203819165,-0.1985645326889762,1.3077280002451408,-1.5852179864589597 +-1.1972507140891382,-1.3940444893280337,-0.9778169799840779,1.2289205766227986,0.0556949299005665,1.168473324517208,-1.509097074744244 +-1.1972507140891382,-1.413436178578674,-0.9778169799840779,1.2644727630246153,0.18282466119533788,1.1304947765914108,-1.566187758530281 +-1.1972507140891382,-1.3552611108267534,-0.9778169799840779,1.2289205766227986,0.2191474415652726,1.1051757446408697,-1.3758854792434911 +-1.1504394237503242,-1.3746528000773934,-0.9778169799840779,1.2289205766227986,0.16466327101037062,1.0925162286655847,-1.2807343396000963 +-1.1036281334115103,-1.335869421576113,-0.9778169799840779,1.157816203819165,-0.12591897194910687,1.1811328404924641,-1.3949157071721698 +-1.1738450689197313,-1.2389109753229117,-0.8968673379569131,1.0156074582118981,-0.3438556541687149,1.3203875162204257,-1.3378250233861326 +-1.0802224882421034,-1.0449940828165094,-0.8968673379569131,0.6600855941937308,-0.4891467756484536,1.4343231599978177,-1.3378250233861326 +-1.0568168430726965,-0.9868190150645886,-0.8159176959297484,0.48232466218464715,-0.5981151167582576,1.5355992877999531,-1.1284925161706643 +-0.9865999075644757,-0.9480356365633081,-0.8968673379569131,0.3045637301755635,-0.7978904087928984,1.6621944475526298,-1.01431114859859 +-0.869571681717441,-0.5214184730492226,-0.7349680539025837,-0.33537562505713775,-0.7434062382379962,1.712832511453712,-1.1475227440993427 +-0.7525434558704064,-0.5795935408011434,-0.8159176959297484,-0.19316687944987082,-0.9431815302726371,1.712832511453712,-1.1475227440993427 +-0.7993547462092202,-0.7735104333075459,-0.8968673379569131,0.09125061176466308,-0.9795043106425718,1.7761300913300504,-1.1855831999567013 +-0.869571681717441,-0.9286439473126679,-0.9778169799840779,0.3045637301755635,-1.0884726517523757,1.8141086392558476,-1.1284925161706643 +-0.8929773268868479,-0.9092522580620276,-0.9778169799840779,0.1979071709701133,-1.1792796026772123,1.7634705753547941,-1.052371604455948 +-1.0568168430726965,-0.9674273258139483,-0.9778169799840779,0.37566810297919695,-1.161118212492245,1.7254920274289682,-1.1855831999567013 +-0.9397886172256619,-0.7929021225581862,-0.9778169799840779,0.05569842536284634,-1.1792796026772123,1.7508110593795092,-1.20461342788538 +-0.9163829720562549,-0.2693265127908995,-0.8968673379569131,-0.7620018618789386,-1.2337637732321145,1.6621944475526298,-1.166552972028022 +-0.7057321655315925,-0.7347270548062654,-0.8968673379569131,-0.08651032024442061,-1.3608935045268857,1.5988968676762916,-1.20461342788538 +-0.5652982945151509,-0.5020267837985825,-0.8968673379569131,-0.5131365570662214,-1.2156023830471472,1.6242158996268325,-1.071401832384627 +-0.869571681717441,-0.6765519870543446,-0.8968673379569131,0.05569842536284634,-0.9795043106425718,1.5988968676762916,-1.1855831999567013 +-0.2610249073128607,-0.4244600267960214,-0.7349680539025837,-0.44203218426258795,-0.7978904087928984,1.6115563836515765,-1.01431114859859 +-0.518487004176337,-0.4632434052973019,-0.8159176959297484,-0.2642712522535043,-0.5981151167582576,1.5102802558494408,-0.9381902368838744 +-0.518487004176337,-0.2693265127908995,-0.6540184118754189,-0.5131365570662214,-0.5073081658334209,1.4216636440225614,-1.0333413765272692 +-0.7759491010398133,-0.15297637728705796,-0.5730687698482542,-0.6908974890753051,-0.4165012149085842,1.3077280002451408,-0.957220464812553 +-0.8929773268868479,-0.5214184730492226,-0.7349680539025837,-0.08651032024442061,-0.30753287379878025,1.1051757446408697,-0.957220464812553 +-0.8461660365480341,-0.5795935408011434,-0.7349680539025837,0.05569842536284634,-0.21672592287394357,0.9912401008634492,-0.8810995530978373 +-0.7993547462092202,-0.5602018515505032,-0.7349680539025837,0.09125061176466308,-0.1985645326889762,0.9026234890365697,-0.9762506927412322 +-0.6823265203621856,-0.4050683375453812,-0.49211912782108935,-0.12206250664623734,-0.27121009342884556,0.8393259091602459,-0.7288577296684052 +-0.3078361976516746,-0.1335846880364177,-0.33021984376675984,-0.4064799978607712,-0.5073081658334209,0.8140068772097048,-0.4243740828095415 +-0.19080797180463993,-0.07540962028449698,-0.4111694857939246,-0.6197931162716717,-0.6889220676830943,0.788687845259178,-0.17698111973671488 +-0.19080797180463993,0.2542490969763872,-0.2492702017395951,-1.117523725897106,-0.6344378971281923,0.7507092973333663,-0.46243453866689965 +-0.09718539112701219,0.46755767873342996,-0.169130056132702,-1.4019412171116399,-0.6889220676830943,0.7507092973333663,-0.5195252224529364 +0.32411622192231265,0.4481659894827897,-0.169130056132702,-1.4019412171116399,-0.7978904087928984,0.7127307494075691,-0.5385554503816153 +0.6049839639551958,0.5063410572347105,-0.08737091768526559,-1.3663890307098232,-1.0158270910125062,0.6747522014817575,-0.4814647665955786 +0.6752008994634167,0.4481659894827897,0.07452836636906393,-1.4019412171116399,-1.052149871382441,0.5228380097785541,-0.38631362695218363 +0.34752186709171956,0.312424164728308,0.23561815400312178,-1.4019412171116399,-1.161118212492245,0.4342213979516747,-0.31019271523746766 +0.5113613832775681,0.3318158539789482,0.4792765765048877,-1.4019412171116399,-1.2700865536020491,0.307626238198998,-0.34825317109482545 +0.932662996326893,0.2930324754776677,0.6403663641389455,-1.4019412171116399,-1.4153776750817877,0.16837156247105078,-0.17698111973671488 +0.6986065446328236,0.312424164728308,0.722125502586382,-1.4019412171116399,-1.3790548947118533,0.02911688674311794,-0.34825317109482545 +0.4879557381081612,0.157290650723186,0.9641649322476046,-1.4019412171116399,-1.687798527856298,-0.0088616611826937,-0.08182998009331993 +0.13687106056705717,0.06033220446998475,0.6403663641389455,-1.4019412171116399,-1.9238966002608733,-0.08481875703430258,0.08944207126479102 +0.20708799607527795,0.06033220446998475,0.39832693447772294,-1.4019412171116399,-1.960219380630808,-0.09747827300955875,0.0704118433361121 +0.5815783187857889,0.13789896147254574,0.3173772924505582,-1.4019412171116399,-1.4698618456366899,-0.059499725083761494,0.05138161540743318 +1.5178041255620662,0.11850727222190549,0.5594167221117808,-1.4019412171116399,-0.779729018607931,-0.09747827300955875,-0.31019271523746766 +1.7986718675949496,0.11850727222190549,0.8030751446135467,-1.3663890307098232,-0.27121009342884556,-0.14811633691064094,-0.46243453866689965 +1.3539646093762177,0.11850727222190549,0.1554780083962287,-1.1530759122989227,0.27363161212017456,-0.2620519806880471,-0.34825317109482545 +0.7220121898022305,0.17668233997382624,-0.006421275658100831,-0.975314980289839,1.1635397311835742,-0.4013066564159943,0.10847229919346994 +0.4411444477693473,0.2930324754776677,-0.006421275658100831,-0.975314980289839,1.5994130956227905,-0.5658803640944682,-0.3672833990235047 +-0.19080797180463993,-0.05601793103385673,-0.33021984376675984,-0.299823438655321,1.9989636796920718,-0.6924755238471448,-0.40534385488086255 +-0.6355152300233717,-0.5214184730492226,-0.5730687698482542,0.3401159165773802,2.1260934109868432,-0.7810921356740244,-0.5004949945242575 +-1.0334111979032896,-1.2970860430748326,-0.8968673379569131,1.2644727630246153,2.1624161913567774,-0.8190706835998216,-0.25310203145143056 +-1.0802224882421034,-1.2970860430748326,-0.9778169799840779,1.2644727630246153,2.071609240431941,-0.806411167624551,-0.7669181855257634 +-1.1504394237503242,-1.258302664573552,-0.9778169799840779,1.1222640174173484,1.4722833643280187,-0.7431135877482127,0.24168389469422305 +-1.1738450689197313,-1.10316915056843,-0.8968673379569131,0.8733987126046313,0.6731821961894559,-0.5911993960450093,0.013321159550075007 +-0.7525434558704064,0.2736407862270275,-0.2492702017395951,-1.0819715394952891,1.3088308526633128,-0.45194472031706207,-0.4434043107382204 +0.13687106056705717,0.9911332885007166,0.3173772924505582,-1.3308368443080063,1.218023901738476,-0.4392852043417915,-0.23407180352275161 +-0.7057321655315925,0.312424164728308,-0.4111694857939246,-1.2952846579061896,0.0556949299005665,-0.426625688366521,0.08944207126479102 +-0.7057321655315925,0.11850727222190549,-0.33021984376675984,-1.4019412171116399,-0.3438556541687149,-0.36332810849018266,0.22265366676554413 +-0.6823265203621856,0.00215713671806401,-0.33021984376675984,-1.4019412171116399,0.03753353971559922,-0.2747114966633176,0.1465327550508281 +-0.167402326635233,0.040940515219344505,-0.2492702017395951,-1.3308368443080063,0.49156829433978266,-0.16077585288589707,0.05138161540743318 +-0.4482700686681162,-0.3856766482947409,-0.49211912782108935,-0.5842409298698549,0.5823752452646191,-0.0341806931332204,-0.06279975216464068 +nan,-1.3552611108267534,-1.0587666220112426,0.9445030854082648,0.5642138550796519,-0.0341806931332204,-0.08182998009331993 +-1.220656359258545,-1.3940444893280337,nan,1.2644727630246153,0.40076134341494596,-0.0088616611826937,-0.043769524235961754 +-1.0334111979032896,nan,-0.9778169799840779,0.020146238961029603,0.18282466119533788,0.13039301454525354,-0.043769524235961754 +-0.9397886172256619,-0.7541187440569056,-0.9778169799840779,-0.05095813384260387,-0.4165012149085842,0.2063501103968624,0.08944207126479102 +-0.7993547462092202,-0.3662849590441007,-0.8968673379569131,-0.6908974890753051,-0.21672592287394357,0.24432865832265965,-0.005709068378603912 +-0.6589208751927786,-0.2693265127908995,-0.8159176959297484,-0.8686584210843888,0.27363161212017456,0.34560478612480966,0.1275025271221492 +-0.47167571383752316,-0.2693265127908995,-0.7349680539025837,-0.7264496754771219,0.727666366744358,0.4721999458774863,-0.1579508918080356 +-0.7525434558704064,-0.9286439473126679,-0.8968673379569131,0.37566810297919695,1.0182486097038352,0.4848594618527425,-0.1389206638793567 +-0.8461660365480341,-0.9286439473126679,-0.8159176959297484,0.5534290349882807,1.2543466821084108,0.4342213979516747,-0.19601134766539377 +-0.9397886172256619,-1.10316915056843,-0.9778169799840779,0.9445030854082648,1.4722833643280187,0.3835833340506069,-0.31019271523746766 +-1.0802224882421034,-1.3552611108267534,-0.9778169799840779,1.2644727630246153,1.6720586563626596,0.24432865832265965,-0.4814647665955786 +-1.1972507140891382,-1.3940444893280337,-1.0587666220112426,1.4422336950336991,1.8718339483973006,0.10507398259471243,-0.31019271523746766 +-1.1738450689197313,-1.3746528000773934,-0.9778169799840779,1.5133380678373325,1.853672558212333,0.0037978547925768464,-0.32922294316614653 +-1.1504394237503242,-1.335869421576113,-0.9778169799840779,1.5133380678373325,1.8718339483973006,-0.08481875703430258,-0.31019271523746766 +-1.1270337785809172,-0.9674273258139483,-0.8968673379569131,1.0156074582118981,1.7265428269175618,-0.16077585288589707,-0.4434043107382204 +-1.0334111979032896,-0.8510771903101069,-0.8968673379569131,1.3000249494264322,1.3996378035881494,-0.13545682093537037,-0.08182998009331993 +-1.0568168430726965,-0.7929021225581862,-0.8159176959297484,1.193368390220982,1.1998625115535086,-0.059499725083761494,0.013321159550075007 +-0.9631942623950688,-0.4438517160466617,-0.7349680539025837,0.4112202893810137,1.0727327802587374,-0.046840209108490946,0.1465327550508281 +-0.9397886172256619,-0.15297637728705796,-0.6540184118754189,-0.05095813384260387,0.8911188784090641,-0.0088616611826937,0.20362343883686487 +-0.4248644234987093,-0.15297637728705796,-0.6540184118754189,-0.08651032024442061,0.618698025634554,-0.0088616611826937,0.260714122622902 +-0.2844305524822677,0.021548825968704256,-0.49211912782108935,-0.3709278114589545,0.6550208060044886,-0.08481875703430258,0.27974435055158087 +-0.2844305524822677,0.040940515219344505,-0.4111694857939246,1.5133380678373325,0.49156829433978266,-0.16077585288589707,0.39392571812365473 +0.183682350905871,-0.11419299878577747,-0.4111694857939246,1.5133380678373325,-0.05327341120923746,-0.22407343276223543,0.4319861739810129 +0.39433315743053343,-0.1723680665376982,-0.33021984376675984,1.5133380678373325,-0.7070834578680616,-0.2873710126385738,0.6603489091251606 +-0.0035628104493844515,-0.09480130953513723,-0.33021984376675984,1.5133380678373325,-1.0158270910125062,-0.3253495605643854,0.6222884532678028 +0.183682350905871,-0.017234552532576237,-0.169130056132702,1.5133380678373325,-0.8705359695327677,-0.3759876244654532,0.4890768577670497 +0.4177388025999404,0.157290650723186,0.5594167221117808,1.5133380678373325,-0.5799537265732904,-0.41396617239125044,0.3558652622662969 +0.7688234801410444,0.13789896147254574,0.6403663641389455,1.5133380678373325,-0.7978904087928984,-0.38864714044072374,0.3748954901949758 +0.8390404156492652,0.09911558297126524,0.4792765765048877,1.5133380678373325,-0.9431815302726371,-0.45194472031706207,0.5271373136244079 +0.558172673616382,0.06033220446998475,0.5594167221117808,1.5133380678373325,-0.3801784345386496,-0.45194472031706207,0.4319861739810129 +1.0028799318351138,0.06033220446998475,0.6403663641389455,1.5133380678373325,0.01937214953063179,-0.45194472031706207,0.4319861739810129 +1.3071533190374038,0.157290650723186,1.0451145742747694,1.5133380678373325,0.49156829433978266,-0.5279018161686709,0.5651977694817657 +1.1433138028515553,0.38999092173086897,0.8840247866407115,1.5133380678373325,0.8003119274842274,-0.6291779439708065,0.6032582253391239 +1.1901250931903693,0.6032995034879117,0.5594167221117808,1.5133380678373325,1.0182486097038352,-0.7431135877482127,0.6222884532678028 +1.0730968673433345,1.010524977751357,0.5594167221117808,-0.9397627938880223,1.2543466821084108,-0.9203468114019572,0.7364698208398767 +0.8390404156492652,1.2238335595083996,0.4792765765048877,1.5133380678373325,1.381476413403182,-1.072261003105175,0.6413186811964817 +0.6283896091246027,1.4371421412654424,0.39832693447772294,1.5133380678373325,1.5449289250678884,-1.1735371309073106,0.6793791370538397 +0.6283896091246027,1.7086257907744058,0.4792765765048877,1.3000249494264322,1.5994130956227905,-1.2368347107836488,0.7174395929111977 +0.909257351157486,2.135242954288491,0.8840247866407115,1.3000249494264322,1.4904447545129862,-1.2494942267589193,0.8316209604832716 +1.0028799318351138,2.3291598467948935,0.9641649322476046,1.193368390220982,1.2906694624783455,-1.1735371309073106,0.9458023280553455 +1.1433138028515553,2.193418022040412,0.722125502586382,0.4112202893810137,0.727666366744358,-1.1102395510309722,1.0790139235560985 +1.0496912221739276,2.0188928187846495,0.4792765765048877,-0.05095813384260387,0.0556949299005665,-1.072261003105175,1.2502859749142092 +1.1199081576821484,2.03828450803529,0.722125502586382,-0.08651032024442061,-0.30753287379878025,-1.046941971154634,1.2693162028428882 +0.8156347704798582,1.8249759262782472,1.2078233547493704,-0.3709278114589545,-0.3801784345386496,-1.0089634232288367,1.2883464307715673 +0.7922291253104513,1.650450723022485,1.2887729967765353,-0.44203218426258795,0.03753353971559922,-1.0216229392041072,1.0028930118413826 +2.0795396096278327,1.9413260617820887,2.2601687011025122,-0.44203218426258795,-0.016950630839302757,-1.0849205190804454,1.0028930118413826 +1.7518605772561355,1.7474091692756863,1.9363701329938534,-0.4775843706644047,-0.016950630839302757,-1.072261003105175,0.9458023280553455 +1.7050492869173217,1.5922756552705644,1.9363701329938534,-0.6908974890753051,-0.03511202102427019,-1.097580035055716,1.0409534676987404 +1.1901250931903693,1.2044418702577593,1.2887729967765353,-0.6908974890753051,-0.1622417523190416,-1.1608776149320543,1.0409534676987404 +0.7454178349716375,1.1074834240045581,0.8030751446135467,-0.6908974890753051,-0.18040314250400885,-1.186196646882581,0.9648325559840245 +0.5975128820171213,1.09633708102329,nan,-0.6908974890753051,-0.1985645326889762,-1.2241751948083928,1.0028930118413826 +0.7922291253104513,1.1462668025058387,0.722125502586382,-0.6908974890753051,-0.1622417523190416,-1.1608776149320543,1.0790139235560985 +0.8390404156492652,0.9135665314981556,0.8030751446135467,-0.6908974890753051,-0.08959619157917217,-1.0849205190804454,1.1551348352708144 +0.7922291253104513,0.8747831529968751,0.8840247866407115,-0.6908974890753051,0.1283404906404359,-0.9709848753030393,1.2122255190568514 +1.0262855770045207,0.5645161249866312,0.722125502586382,-0.6908974890753051,0.2917930023051418,-0.9709848753030393,1.2502859749142092 +0.932662996326893,0.35120754322958847,0.6403663641389455,-0.6908974890753051,0.45524551396984797,-0.996303907253566,1.2883464307715673 +1.1433138028515553,0.3705992324802287,0.8030751446135467,-0.6908974890753051,0.6731821961894559,-1.0596014871299044,1.3073766587002462 +1.4241815448844386,0.4093826109815092,0.6403663641389455,-0.6908974890753051,0.9274416587789986,-1.1735371309073106,1.2693162028428882 +1.5412097707314731,0.5645161249866312,0.5594167221117808,-0.6908974890753051,1.109055560628672,-1.2748132587094605,1.3644673424862832 +1.5880210610702872,1.010524977751357,0.8840247866407115,-0.6908974890753051,1.381476413403182,-1.4140679344374076,1.459618482129678 +1.6816436417479148,1.2044418702577593,0.9641649322476046,-0.975314980289839,1.7265428269175618,-1.4520464823632049,1.5357393938443944 +1.915700093441984,1.417750452014802,1.0451145742747694,-1.117523725897106,1.7628656072874962,-1.4520464823632049,1.5547696217730729 +2.2433791258136813,1.2044418702577593,0.9641649322476046,-0.8686584210843888,1.6720586563626596,-1.4520464823632049,1.5547696217730729 +2.032728319289019,1.6892341015237655,1.2887729967765353,-0.8686584210843888,1.1998625115535086,-1.4014084184621372,1.516709165915715 +1.9625113837807981,1.805584237027607,1.5316219228580294,-0.8686584210843888,0.3281157826750766,-1.287472774684731,1.61186030555911 +1.5412097707314731,1.5534922767692838,1.693521206912359,-0.8686584210843888,0.01937214953063179,-1.186196646882581,1.687981217273826 +1.1433138028515553,1.3595753842628813,2.098269417048183,-0.8686584210843888,-0.10775758176413944,-1.1102395510309722,1.687981217273826 +1.3773702545456248,1.4565338305160827,1.7736613525192522,-0.8686584210843888,-0.21672592287394357,-1.1735371309073106,1.7450719010598628 +1.2369363835291831,1.2432252487590398,2.0165102786007463,-0.8686584210843888,-0.4709853854634863,-1.2241751948083928,1.687981217273826 +1.4241815448844386,1.185050181007119,1.9363701329938534,-0.8686584210843888,-0.4891467756484536,-1.2368347107836488,1.707011445202505 +1.0262855770045207,1.0687000455032776,1.9363701329938534,-0.8686584210843888,-0.6344378971281923,-1.2494942267589193,1.668950989345147 +0.7688234801410444,0.8359997744955946,1.9363701329938534,-0.8686584210843888,-0.779729018607931,-1.2494942267589193,1.649920761416468 +0.5815783187857889,0.9523499099994361,1.9363701329938534,-0.8686584210843888,-0.6344378971281923,-1.2748132587094605,1.687981217273826 +0.6517952542940098,0.7196496389917532,2.0165102786007463,-0.8686584210843888,-0.8523745793478004,-1.3254513226105282,1.649920761416468 +-0.026968455618791385,0.5645161249866312,2.745866553265501,-0.8686584210843888,-1.0703112615674084,-1.338110838585799,1.5357393938443944 +-0.2844305524822677,0.3705992324802287,3.2307549090082177,-0.8686584210843888,-0.6162765069432249,-1.3001322906599873,1.8782834965606159 diff --git "a/5 \347\216\257\345\242\203\346\261\241\346\237\223\347\232\204\351\242\204\346\265\213/pm2.5\347\232\204\347\272\277\346\200\247\345\233\236\345\275\222\351\242\204\346\265\213\346\250\241\345\236\213-\344\273\212\345\244\251\347\235\241\351\206\222\344\272\206\345\220\227/main.py" "b/5 \347\216\257\345\242\203\346\261\241\346\237\223\347\232\204\351\242\204\346\265\213/pm2.5\347\232\204\347\272\277\346\200\247\345\233\236\345\275\222\351\242\204\346\265\213\346\250\241\345\236\213-\344\273\212\345\244\251\347\235\241\351\206\222\344\272\206\345\220\227/main.py" new file mode 100644 index 00000000..a6b73f59 --- /dev/null +++ "b/5 \347\216\257\345\242\203\346\261\241\346\237\223\347\232\204\351\242\204\346\265\213/pm2.5\347\232\204\347\272\277\346\200\247\345\233\236\345\275\222\351\242\204\346\265\213\346\250\241\345\236\213-\344\273\212\345\244\251\347\235\241\351\206\222\344\272\206\345\220\227/main.py" @@ -0,0 +1,9 @@ +import display_lr +import Normalization +import predict + +if __name__ == "__main__": + # display_lr.display_data() + # Normalization.Normalization() + + predict.build_lr() \ No newline at end of file diff --git "a/5 \347\216\257\345\242\203\346\261\241\346\237\223\347\232\204\351\242\204\346\265\213/pm2.5\347\232\204\347\272\277\346\200\247\345\233\236\345\275\222\351\242\204\346\265\213\346\250\241\345\236\213-\344\273\212\345\244\251\347\235\241\351\206\222\344\272\206\345\220\227/predict.ipynb" "b/5 \347\216\257\345\242\203\346\261\241\346\237\223\347\232\204\351\242\204\346\265\213/pm2.5\347\232\204\347\272\277\346\200\247\345\233\236\345\275\222\351\242\204\346\265\213\346\250\241\345\236\213-\344\273\212\345\244\251\347\235\241\351\206\222\344\272\206\345\220\227/predict.ipynb" new file mode 100644 index 00000000..99b1e7ab --- /dev/null +++ "b/5 \347\216\257\345\242\203\346\261\241\346\237\223\347\232\204\351\242\204\346\265\213/pm2.5\347\232\204\347\272\277\346\200\247\345\233\236\345\275\222\351\242\204\346\265\213\346\250\241\345\236\213-\344\273\212\345\244\251\347\235\241\351\206\222\344\272\206\345\220\227/predict.ipynb" @@ -0,0 +1,139 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "ExecuteTime": { + "end_time": "2020-09-13T13:56:40.324016Z", + "start_time": "2020-09-13T13:56:36.982915Z" + } + }, + "outputs": [], + "source": [ + "import pandas as pd\n", + "import matplotlib as mpl\n", + "import seaborn as sns\n", + "import numpy as np\n", + "\n", + "from sklearn.model_selection import train_test_split\n", + "from sklearn.linear_model import LinearRegression\n", + "from matplotlib import pyplot as plt" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "data_file = \"..\\PRSA2017_Data_20130301-20170228\\PRSA_Data_20130301-20170228\\simpleDataSet.csv\"\n", + "def build_lr():\n", + " pd_data = pd.read_csv(data_file)\n", + "\n", + " X = pd_data.loc[:, (\"PM10\", \"SO2\",\"NO2\",\"CO\",\"PRES\",\"DEWP\")]\n", + " y = pd_data.loc[:, \"PM2.5\"]\n", + " \n", + " #选择20%为测试集\n", + " X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=532) \n", + "\n", + " print('训练集测试及参数:')\n", + " print(f'X_train.shape={X_train.shape}\\ny_train.shape ={y_train.shape}\\nX_test.shape={X_test.shape}\\ny_test.shape={y_test.shape}')\n", + "\n", + " linear_reg = LinearRegression()\n", + " model = linear_reg.fit(X_train, y_train)\n", + "\n", + " print('模型参数')\n", + " print(model)\n", + "\n", + " print('模型截距')\n", + " print(linear_reg.intercept_)\n", + "\n", + " print('参数权重')\n", + " print(linear_reg.coef_)\n", + "\n", + " y_pred = linear_reg.predict(X_test)\n", + " sum_mean = 0\n", + "\n", + " for i in range(len(y_pred)):\n", + " sum_mean += (y_pred[i] - y_test.values[i]) ** 2\n", + "\n", + " sum_erro = np.sqrt(sum_mean / len(y_pred))\n", + "\n", + " print(sum_erro)\n", + "\n", + " plt.figure()\n", + " plt.figure()\n", + " plt.plot(range(len(y_pred)), y_pred, 'b', label=\"predict\")\n", + " plt.plot(range(len(y_pred)), y_test, 'r', label=\"test\")\n", + " plt.legend(loc=\"upper right\")\n", + " plt.xlabel(\"the number of sales\")\n", + " plt.ylabel('value of sales')\n", + " plt.show()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.6" + }, + "toc": { + "base_numbering": 1, + "nav_menu": {}, + "number_sections": true, + "sideBar": true, + "skip_h1_title": false, + "title_cell": "Table of Contents", + "title_sidebar": "Contents", + "toc_cell": false, + "toc_position": {}, + "toc_section_display": true, + "toc_window_display": false + }, + "varInspector": { + "cols": { + "lenName": 16, + "lenType": 16, + "lenVar": 40 + }, + "kernels_config": { + "python": { + "delete_cmd_postfix": "", + "delete_cmd_prefix": "del ", + "library": "var_list.py", + "varRefreshCmd": "print(var_dic_list())" + }, + "r": { + "delete_cmd_postfix": ") ", + "delete_cmd_prefix": "rm(", + "library": "var_list.r", + "varRefreshCmd": "cat(var_dic_list()) " + } + }, + "types_to_exclude": [ + "module", + "function", + "builtin_function_or_method", + "instance", + "_Feature" + ], + "window_display": false + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git "a/5 \347\216\257\345\242\203\346\261\241\346\237\223\347\232\204\351\242\204\346\265\213/pm2.5\347\232\204\347\272\277\346\200\247\345\233\236\345\275\222\351\242\204\346\265\213\346\250\241\345\236\213-\344\273\212\345\244\251\347\235\241\351\206\222\344\272\206\345\220\227/predict.py" "b/5 \347\216\257\345\242\203\346\261\241\346\237\223\347\232\204\351\242\204\346\265\213/pm2.5\347\232\204\347\272\277\346\200\247\345\233\236\345\275\222\351\242\204\346\265\213\346\250\241\345\236\213-\344\273\212\345\244\251\347\235\241\351\206\222\344\272\206\345\220\227/predict.py" new file mode 100644 index 00000000..4c0f0c7b --- /dev/null +++ "b/5 \347\216\257\345\242\203\346\261\241\346\237\223\347\232\204\351\242\204\346\265\213/pm2.5\347\232\204\347\272\277\346\200\247\345\233\236\345\275\222\351\242\204\346\265\213\346\250\241\345\236\213-\344\273\212\345\244\251\347\235\241\351\206\222\344\272\206\345\220\227/predict.py" @@ -0,0 +1,53 @@ +import pandas as pd +import matplotlib as mpl +import seaborn as sns +import numpy as np + +from sklearn.model_selection import train_test_split +from sklearn.linear_model import LinearRegression +from matplotlib import pyplot as plt + + +data_file = "..\PRSA2017_Data_20130301-20170228\PRSA_Data_20130301-20170228\simpleDataSet.csv" +def build_lr(): + pd_data = pd.read_csv(data_file) + + X = pd_data.loc[:, ("PM10", "SO2","NO2","CO","PRES","DEWP")] + y = pd_data.loc[:, "PM2.5"] + + #选择20%为测试集 + X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=532) + + print('训练集测试及参数:') + print(f'X_train.shape={X_train.shape}\ny_train.shape ={y_train.shape}\nX_test.shape={X_test.shape}\ny_test.shape={y_test.shape}') + + linear_reg = LinearRegression() + model = linear_reg.fit(X_train, y_train) + + print('模型参数') + print(model) + + print('模型截距') + print(linear_reg.intercept_) + + print('参数权重') + print(linear_reg.coef_) + + y_pred = linear_reg.predict(X_test) + sum_mean = 0 + + for i in range(len(y_pred)): + sum_mean += (y_pred[i] - y_test.values[i]) ** 2 + + sum_erro = np.sqrt(sum_mean / len(y_pred)) + + print(sum_erro) + + plt.figure() + plt.figure() + plt.plot(range(len(y_pred)), y_pred, 'b', label="predict") + plt.plot(range(len(y_pred)), y_test, 'r', label="test") + plt.legend(loc="upper right") + plt.xlabel("the number of sales") + plt.ylabel('value of sales') + plt.show() \ No newline at end of file