当前位置: 首页 > news >正文

【Python数据分析】基于自回归积分滑动平均模型的疫情分析报告 附完整python代码

资源地址:Python数据分析大作业 2000+字 图文分析文档 疫情分析+完整python代码
在这里插入图片描述

数据分析

数据来自法国疫情数据

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

资源地址:Python数据分析大作业 2000+字 图文分析文档 疫情分析+完整python代码

代码详解

image-20240407220302833

image-20240407220441078

image-20240407220508782

完整代码文件

主要是对时间序列数据进行分析和预测。让我们逐步解释每一部分:

  1. 导入必要的库

    from math import *
    import numpy as np
    import pandas as pd
    import matplotlib.pyplot as plt
    from statsmodels.graphics.tsaplots import plot_acf, plot_pacf
    from pylab import *
    
    • math: 导入数学函数库,但实际上在后续的代码中没有用到。
    • numpypandasmatplotlib.pyplot: 分别是用于数值计算、数据处理和可视化的常用库。
    • statsmodels.graphics.tsaplots.plot_acfstatsmodels.graphics.tsaplots.plot_pacf:用于绘制自相关性和偏自相关性图。
    • pylab: 导入了 *,所以其下所有函数都可直接使用。
  2. 设置中文字体和负号显示

    plt.rcParams['font.sans-serif'] = ['SimHei'] # 设置中文字体为黑体
    plt.rcParams['axes.unicode_minus'] = False  # 解决负号显示问题
    
  3. 读取数据

    cas_confirmes = pd.read_csv('cas_confirmes.csv', index_col=0)
    hospitalises = pd.read_csv('hospitalises.csv', index_col=0)
    

    从文件中读取了两个时间序列数据,分别是患病确诊人数和住院人数。

  4. 数据处理

    cas_confirmes.fillna(np.nanmean(cas_confirmes) + 30 * np.random.random(), inplace=True)
    hospitalises.fillna(np.nanmean(hospitalises), inplace=True)
    

    使用每列的均值填充缺失值。

  5. 数据可视化

    cas_confirmes.plot() 
    plt.title('Change in the number of cases')
    plt.show()
    hospitalises.plot()
    plt.title('Changes in the number of people in the hospital')
    plt.show()
    

    绘制了患病确诊人数和住院人数的变化趋势图。

  6. 自相关性分析

    plot_acf(cas_confirmes)
    plt.title('The autocorrelation of the number of patients')
    plot_pacf(cas_confirmes)
    plt.title('Partial autocorrelation of the number of patients')
    plt.show()plot_acf(hospitalises)
    plt.title('Autocorrelation graph of the number of people in the hospital')
    plot_pacf(hospitalises)
    plt.title('Partial autocorrelation graph of the number of people in the hospital')
    plt.show()
    

    绘制了患病确诊人数和住院人数的自相关性和偏自相关性图。

  7. ARIMA 模型定阶

    train_results = sm.tsa.arma_order_select_ic(cas_confirmes['2020-03-19':'2021-06-09'], ic=['bic'], trend='nc', max_ar=5, max_ma=5)
    print('BIC for the number of patients', train_results.bic_min_order)
    

    使用 BIC 准则确定 ARIMA 模型的阶数。

  8. 构建 ARIMA 模型

    model = ARIMA(cas_confirmes['2020-03-19':'2021-05-09'], order=(2,0,1))
    results_comfirm = model.fit();
    

    使用确定的阶数构建 ARIMA 模型,并对患病确诊人数和住院人数分别进行建模。

  9. 模型诊断

    print('The white noise test result of the diseased difference sequence was:', acorr_ljungbox(resid1.values.squeeze(), lags=1))
    print('The white noise test result of hospitalization difference sequence is:', acorr_ljungbox(resid2.values.squeeze(), lags=1))
    

    对模型的残差进行自相关性分析,检验残差序列是否为白噪声。

  10. 模型预测

    predict_comfirm=results_comfirm.forecast(30)
    

    使用训练好的 ARIMA 模型对未来一段时间内的患病确诊人数和住院人数进行预测。

  11. 可视化预测结果

    plt.plot(list(range(1,418)),predict_sunspots_comfirm,label='predict comfirmed')
    plt.plot(smooth_comfirm.loc['2020-03-18':'2021-06-09'],label='true comfirmed')
    plt.plot(list(range(417,447)),predict_comfirm[0],'g',label='future predict')
    plt.title('Actual and predicted disease graphs')
    plt.legend()
    

    绘制预测结果和真实数据的对比图。

完整代码文件&2000+图文分析报告

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • Python操作MySQL数据库的工具--sqlalchemy
  • 日用百货元宇宙 以科技创新培育产业新质生产力
  • tensorflow如何指定gpu运行还是cpu运行
  • Kotlin中 take、drop方法使用
  • 生命在于学习——Python人工智能原理(1.2)
  • go map
  • 【小技巧】KEIL C51 报错`Warning L6: XDATA Space Memory Overlap`
  • [前端] axios 请求成功了,为什么通过浏览器看不到返回数据
  • 极致优化之道-JVM字节码调优全揭秘
  • 2024电工杯数学建模B题完整论文讲解(含每一问python代码+数据)
  • 2、OpenVPN搭建
  • 学 Python 具体能干什么?
  • ZeroTier+Nomachine远程
  • 【Python】 使用SMOTE解决数据不平衡问题
  • 【加密与解密(第四版)】第十八章笔记
  • 【知识碎片】第三方登录弹窗效果
  • js算法-归并排序(merge_sort)
  • Laravel深入学习6 - 应用体系结构:解耦事件处理器
  • Linux快速复制或删除大量小文件
  • mac修复ab及siege安装
  • Redis在Web项目中的应用与实践
  • supervisor 永不挂掉的进程 安装以及使用
  • 工作手记之html2canvas使用概述
  • 海量大数据大屏分析展示一步到位:DataWorks数据服务+MaxCompute Lightning对接DataV最佳实践...
  • 互联网大裁员:Java程序员失工作,焉知不能进ali?
  • 浏览器缓存机制分析
  • 时间复杂度与空间复杂度分析
  • 微信端页面使用-webkit-box和绝对定位时,元素上移的问题
  • 项目实战-Api的解决方案
  • 写给高年级小学生看的《Bash 指南》
  • 白色的风信子
  • raise 与 raise ... from 的区别
  • ​​​​​​​​​​​​​​汽车网络信息安全分析方法论
  • ​Redis 实现计数器和限速器的
  • ​软考-高级-信息系统项目管理师教程 第四版【第23章-组织通用管理-思维导图】​
  • #APPINVENTOR学习记录
  • (26)4.7 字符函数和字符串函数
  • (9)目标检测_SSD的原理
  • (Redis使用系列) Springboot 在redis中使用BloomFilter布隆过滤器机制 六
  • (仿QQ聊天消息列表加载)wp7 listbox 列表项逐一加载的一种实现方式,以及加入渐显动画...
  • (分享)自己整理的一些简单awk实用语句
  • (附源码)springboot太原学院贫困生申请管理系统 毕业设计 101517
  • (附源码)计算机毕业设计SSM基于java的云顶博客系统
  • (回溯) LeetCode 78. 子集
  • (七)微服务分布式云架构spring cloud - common-service 项目构建过程
  • (十一)图像的罗伯特梯度锐化
  • (五十)第 7 章 图(有向图的十字链表存储)
  • (转)C#开发微信门户及应用(1)--开始使用微信接口
  • (转)Scala的“=”符号简介
  • (转)创业家杂志:UCWEB天使第一步
  • (转)关于多人操作数据的处理策略
  • .gitignore文件—git忽略文件
  • .net core Swagger 过滤部分Api
  • .NET delegate 委托 、 Event 事件
  • .NET delegate 委托 、 Event 事件,接口回调