首页 > 其他分享 >空气质量与车流量的相关性分析

空气质量与车流量的相关性分析

时间:2024-05-25 22:11:18浏览次数:16  
标签:normalized df car 车流量 空气质量 out 1.000000 相关性

空气质量与车流量对应指标的相关性分析

目录

数据预处理

1.当天空气质量/车流量其中一类全部缺失/均缺失的占整体数据的不到5%,这部分数据直接删去,认为不影响准确性;

2.剩余数据根据时间进行了连接,去了两张表格相交的日期(2017/3/23-2023/6/25),共1789天(部分天数不连续);

3.面对空气质量衡量指标的部分缺失,考虑到表中无0值,这里假设空值均代表未测量到对应空气污染量,因此置为0。

处理目标

得到车辆数和空气质量以及大车数和空气质量的相关性。

代码实现

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt 
import seaborn as sns ;sns.set(color_codes=True)#用color_codes预定的颜色
import chardet#用于判断表中数据的类型
from sklearn.preprocessing import StandardScaler#为了标准化
#df = pd.read_csv("python_play.csv")
# 读取CSV文件
#df.head()
# 显示数据框的前几行
#with open('python_play.csv', 'rb') as f:
 #   content = f.read()
  #  print(content)
with open('last.csv', 'rb') as f:
    content = f.read()
    encoding = chardet.detect(content)['encoding']

print(encoding)

out:
UTF-8-SIG


# 读取CSV文件,指定编码为UTF-8-SIG
df = pd.read_csv('last.csv', encoding='UTF-8-SIG',usecols=lambda column: column != 'date')
df.head()

out:

stream long-car large-car middle-car light-car little-car pm25 pm10 o3 no2 so2 co
0 6245 601 218 347 389 4690 123 43 71 23 4 8
1 18504 2401 932 1612 1339 12220 87 45 34 30 4 9
2 16541 2528 1047 1808 1504 9654 88 44 36 21 4 8
3 13164 2194 876 1410 1255 7429 77 57 60 29 6 8
4 8533 1490 559 973 821 4690 104 67 73 28 6 7

车流量 长车流量 大型车流量 中型车流量 轻型车流量 微型车流量

scaler = StandardScaler()
# 初始化标准化器
df_normalized = pd.DataFrame(scaler.fit_transform(df), columns=df.columns)
# 对每列数据进行标准化
df_normalized.head()

out:

stream long-car large-car middle-car light-car little-car pm25 pm10 o3 no2 so2 co
0 -0.315919 -0.472971 -0.011644 -0.676805 0.263679 -0.254230 1.058263 -0.109127 1.027142 0.474434 0.130986 1.102301
1 1.028897 0.594040 1.689531 0.981990 2.363031 0.885089 0.006061 0.001327 -0.141546 1.312421 0.130986 1.693079
2 0.813555 0.669323 1.963529 1.239005 2.727656 0.496843 0.035289 -0.053900 -0.078374 0.235009 0.130986 1.102301
3 0.443097 0.471333 1.556105 0.717108 2.177405 0.160192 -0.286217 0.664057 0.679694 1.192709 1.132417 1.102301
4 -0.064925 0.054014 0.800822 0.144069 1.218332 -0.254230 0.502934 1.216331 1.090314 1.072996 1.132417 0.511523

df_normalized.corr()

out:

stream long-car large-car middle-car light-car little-car pm25 pm10 o3 no2 so2 co
stream 1.000000 0.960397 0.334564 0.936301 0.290630 0.984934 -0.291996 -0.259647 -0.249167 -0.195712 -0.076936 -0.182893
long-car 0.960397 1.000000 0.468035 0.893379 0.401189 0.909110 -0.219200 -0.208401 -0.184057 -0.138806 -0.000536 -0.128781
large-car 0.334564 0.468035 1.000000 0.274743 0.953798 0.181474 0.137599 0.086044 0.172481 0.161718 0.342927 0.185937
middle-car 0.936301 0.893379 0.274743 1.000000 0.257476 0.912902 -0.296563 -0.250422 -0.324601 -0.197463 -0.107954 -0.189003
light-car 0.290630 0.401189 0.953798 0.257476 1.000000 0.139703 0.148665 0.091512 0.195345 0.176855 0.386891 0.230381
little-car 0.984934 0.909110 0.181474 0.912902 0.139703 1.000000 -0.331484 -0.287759 -0.283557 -0.234101 -0.141788 -0.225157
pm25 -0.291996 -0.219200 0.137599 -0.296563 0.148665 -0.331484 1.000000 0.722665 0.422200 0.561810 0.473017 0.550983
pm10 -0.259647 -0.208401 0.086044 -0.250422 0.091512 -0.287759 0.722665 1.000000 0.523732 0.736929 0.530307 0.550590
o3 -0.249167 -0.184057 0.172481 -0.324601 0.195345 -0.283557 0.422200 0.523732 1.000000 0.417945 0.424055 0.373651
no2 -0.195712 -0.138806 0.161718 -0.197463 0.176855 -0.234101 0.561810 0.736929 0.417945 1.000000 0.552486 0.585678
so2 -0.076936 -0.000536 0.342927 -0.107954 0.386891 -0.141788 0.473017 0.530307 0.424055 0.552486 1.000000 0.465094
co -0.182893 -0.128781 0.185937 -0.189003 0.230381 -0.225157 0.550983 0.550590 0.373651 0.585678 0.465094 1.000000

  • 后续发现:是否标准化对相关系数影响不变。

相关系数表

df.corr()

out:

stream long-car large-car middle-car light-car little-car pm25 pm10 o3 no2 so2 co
stream 1.000000 0.960397 0.334564 0.936301 0.290630 0.984934 -0.291996 -0.259647 -0.249167 -0.195712 -0.076936 -0.182893
long-car 0.960397 1.000000 0.468035 0.893379 0.401189 0.909110 -0.219200 -0.208401 -0.184057 -0.138806 -0.000536 -0.128781
large-car 0.334564 0.468035 1.000000 0.274743 0.953798 0.181474 0.137599 0.086044 0.172481 0.161718 0.342927 0.185937
middle-car 0.936301 0.893379 0.274743 1.000000 0.257476 0.912902 -0.296563 -0.250422 -0.324601 -0.197463 -0.107954 -0.189003
light-car 0.290630 0.401189 0.953798 0.257476 1.000000 0.139703 0.148665 0.091512 0.195345 0.176855 0.386891 0.230381
little-car 0.984934 0.909110 0.181474 0.912902 0.139703 1.000000 -0.331484 -0.287759 -0.283557 -0.234101 -0.141788 -0.225157
pm25 -0.291996 -0.219200 0.137599 -0.296563 0.148665 -0.331484 1.000000 0.722665 0.422200 0.561810 0.473017 0.550983
pm10 -0.259647 -0.208401 0.086044 -0.250422 0.091512 -0.287759 0.722665 1.000000 0.523732 0.736929 0.530307 0.550590
o3 -0.249167 -0.184057 0.172481 -0.324601 0.195345 -0.283557 0.422200 0.523732 1.000000 0.417945 0.424055 0.373651
no2 -0.195712 -0.138806 0.161718 -0.197463 0.176855 -0.234101 0.561810 0.736929 0.417945 1.000000 0.552486 0.585678
so2 -0.076936 -0.000536 0.342927 -0.107954 0.386891 -0.141788 0.473017 0.530307 0.424055 0.552486 1.000000 0.465094
co -0.182893 -0.128781 0.185937 -0.189003 0.230381 -0.225157 0.550983 0.550590 0.373651 0.585678 0.465094 1.000000

轻型车与衡量空气质量指标的正相关最为明显(最高为so2与轻型车流量,达到38.7%),接着是大型车(最高为so2与大型车流量,达到34.3%),其余车型关于空气质量均出现了不同程度的负相关。

还可看到,微型车与车流量的正相关程度最高。大型车次之,均在96%以上。

两两变量关系图

sns.pairplot(df_normalized)
D:\anaconda3\envs\FLpyth38\lib\site-packages\seaborn\axisgrid.py:123: UserWarning: The figure layout has changed to tight
  self._figure.tight_layout(*args, **kwargs)

out:
<seaborn.axisgrid.PairGrid at 0x26837f3c190>



png

相关系数热力图

sns.heatmap(df_normalized.corr())

out:
<Axes: >

png


相关系数聚类图

sns.clustermap(df_normalized.corr(), figsize=(7, 7))

out:
<seaborn.matrix.ClusterGrid at 0x2685052ffd0>

png


列名说明

print(df.columns)

out:
Index(['stream', 'long-car', 'large-car', 'middle-car', 'light-car',
'little-car', ' pm25', ' pm10', ' o3', ' no2', ' so2', ' co'],
dtype='object')


相关程度较高的关系呈现

车流量与pm2.5关系图

sns.jointplot(x='stream',y=' pm25',data=df_normalized)

out:
<seaborn.axisgrid.JointGrid at 0x268546bcd00>

<Figure size 400x400 with 0 Axes>

png


车流量与pm10关系图

sns.jointplot(x='stream',y=' pm10',data=df_normalized)

out:
<seaborn.axisgrid.JointGrid at 0x26847b7d160>

png


大型车流量与SO2浓度

sns.jointplot(x='large-car',y=' so2',data=df_normalized)

out:

<seaborn.axisgrid.JointGrid at 0x268458aa040>

png


大型车流量与CO浓度关系

sns.jointplot(x='large-car',y=' co',data=df_normalized)

out:

<seaborn.axisgrid.JointGrid at 0x268485f2c40>

png


车流量与小型车流量关系

sns.jointplot(x='stream',y='little-car',data=df_normalized,kind='hex')

out:

<seaborn.axisgrid.JointGrid at 0x26848ac0100>

png


车流量与大型车流量关系

sns.jointplot(x='stream',y='large-car',data=df_normalized,kind='hex')

out:

<seaborn.axisgrid.JointGrid at 0x26848ce2250>

png


大型车流量与SO2浓度关系

sns.jointplot(x='large-car',y=' so2',data=df_normalized,kind='hex')

out:

<seaborn.axisgrid.JointGrid at 0x268493f6730>

png


车流量与pm10浓度关系

sns.jointplot(x='stream',y=' pm10',data=df_normalized,kind='hex')

out:

<seaborn.axisgrid.JointGrid at 0x268498d8a30>


png


车流量与pm10浓度关系

sns.jointplot(x='stream',y=' pm10',data=df_normalized,kind='reg')

out:

<seaborn.axisgrid.JointGrid at 0x26849b37430>


png


车流量与大型车流量浓度关系

sns.jointplot(x='large-car',y='stream',data=df_normalized,kind='reg')

out:
<seaborn.axisgrid.JointGrid at 0x26849f8a2b0>


png


车流量与轻型车流量关系

sns.jointplot(x='light-car',y='stream',data=df_normalized,kind='reg')

out:

<seaborn.axisgrid.JointGrid at 0x2684ebc6af0>

png


轻型车流量与SO2浓度关系

sns.jointplot(x='light-car',y=' so2',data=df_normalized,kind='reg')

out:

<seaborn.axisgrid.JointGrid at 0x2684df7e040>


png


大型车流量与SO2浓度关系

sns.jointplot(x='large-car',y=' so2',data=df_normalized,kind='reg')

out:

<seaborn.axisgrid.JointGrid at 0x2684e46f1c0>


png


标签:normalized,df,car,车流量,空气质量,out,1.000000,相关性
From: https://www.cnblogs.com/HYLOVEYOURSELF/p/18213048

相关文章

  • 行业与气象数据的相关性探索
    行业数据与气象数据的相关性探索目录行业数据与气象数据的相关性探索缺失值的处理方式定性数据的赋值方式1.行业类型2.天气状况3.风向情况4.温度数据5.时间数据数据预处理符号说明代码实现结论说明缺失值的处理方式通过筛查,发现行业表中各类行业均缺失2021年1月26日的数据,对此......
  • 计算机毕业设计python+spark天气预测 天气可视化 天气大数据 空气质量检测 空气质量分
    摘  要近些年大数据人工智能等技术发展迅速,我国工业正努力从“制造”迈向“智造”实现新跨越。神经网络(NeuronNetwork)是一种计算模型,通过大量数据的学习,来发现数据之间的模式和规律,模仿人脑神经元的工作方式。随着算力的提升和算法的不断成熟图像识别技术已经完全融入到生......
  • R语言空气污染数据的地理空间可视化和分析:颗粒物2.5(PM2.5)和空气质量指数(AQI)|附代码数
    原文链接:http://tecdat.cn/?p=23800最近我们被客户要求撰写关于空气污染数据的研究报告,包括一些图形和统计输出。由于空气污染对公众健康的不利影响,人们一直非常关注。世界各国的环境部门都通过各种方法(例如地面观测网络)来监测和评估空气污染问题介绍全球的地面站及时测量了许......
  • ES入门十二:相关性评分
    对于一个搜索引擎来说,对检索出来的数据进行排序是非常重要的功能。全文本数据的检索通常无法用是否相等来的出结果,而是用相关性来决定最后的返回结果相关性是值搜索内容和结果的相关性,是用来描述文档和查询语句的匹配程度的。通过计算相关性,可以得出一个相关性评分,然后根据......
  • 基于BP神经网络的城市空气质量数据预测matlab仿真
    1.算法运行效果图预览  2.算法运行软件版本matlab2022A 3.算法理论概述3.1BP神经网络结构       一个典型的BP(Backpropagation)神经网络包含输入层、隐藏层和输出层。假设我们有一个三层的BP神经网络,其结构如下: 输入层:有n个节点,代表n种影响空气质量......
  • 基于R、Python的Copula变量相关性分析及AI大模型应用
    在工程、水文和金融等各学科的研究中,总是会遇到很多变量,研究这些相互纠缠的变量间的相关关系是各学科的研究的重点。虽然皮尔逊相关、秩相关等相关系数提供了变量间相关关系的粗略结果,但这些系数都存在着无法克服的困难。例如,皮尔逊相关系数只能反映变量间的线性相关,而秩相关则......
  • 训练句子相关性出现的问题
    运行train的时候出现的问题TypeError:TextInputSequencemustbestr后来发现问题的原因是错误的根源在于doubletext_to_encode函数调用tokenizer.encode方法时传入的参数不是字符串(str)类型。 解决方法这意味着tokenizer.encode方法期望输入的text_1和text_2......
  • 恒温恒湿空气调节系统设计:基于MATLAB的恒温恒湿空气调节系统建模和仿真,包括空气调节系
    鱼弦:公众号【红尘灯塔】,CSDN内容合伙人、CSDN新星导师、全栈领域优质创作者、51CTO(Top红人+专家博主)、github开源爱好者(go-zero源码二次开发、游戏后端架构https://github.com/Peakchen)基于MATLAB的恒温恒湿空气调节系统设计:原理、应用、实现与分析1.恒温恒湿空气......
  • 基于皮尔逊相关性的大规模多目标优化自适应变量分组方法
    APearsoncorrelation-basedadaptivevariablegroupingmethodforlarge-scalemulti-objectiveoptimizationAbstract根据作者的实验观察,具有相似得到性能的变量在进化过程成中的趋势也是类似的。换而言之皮尔逊相关系数很大。搜索方法Novelsearchmethods:设计新的交叉......
  • 计算两列的相关性
    计算两列的相关性使用Pandas中的corr()函数计算DataFrame中特定的两列之间相关系数。defcorr_analys(input_file_path,col_1,col_2,output_pic_path,sheet_name='Sheet1'):'''########################################计算两列之间的相关系数(Pearson相关......