时间序列数据的多元回归_清理和理解多元时间序列数据

时间序列数据的多元回归

No matter what kind of data science project one is assigned to, making sense of the dataset and cleaning it always critical for success. The first step is to understand the data using exploratory data analysis (EDA)as it helps us create the logical approach for solving the business problem. It also allows us to identify the issues like outliers existing in our dataset.

无论分配给什么样的数据科学项目,理解数据集并清理它对于成功都是至关重要的。 第一步是使用探索性数据分析(EDA)来理解数据,因为它有助于我们创建解决业务问题的逻辑方法。 它还使我们能够识别数据集中存在的异常值之类的问题。

It is necessary to clean up these issues before starting any analysis because if our data is spewing garbage, so will our analysis. Moreover, the insights from such an analysis won’t tie up with the theoretical or business knowledge of our clients and they may lose confidence in our work.Even if the clients end up making a decision based on such an analysis but the end result will turn out to be wrong and we will be in a lot of trouble! Thus, how well we clean and understand the data has a tremendous impact on the quality of the results.

在开始任何分析之前,有必要清理这些问题,因为如果我们的数据冒出垃圾,我们的分析也将如此。 此外,这种分析的见解不会与客户的理论或业务知识相结合,他们可能会对我们的工作失去信心,即使客户最终根据这样的分析做出决定,但最终结果也会原来是错的,我们会遇到很多麻烦! 因此,我们清理和理解数据的质量对结果的质量有很大的影响。

Things get slightly more complicated when we deal with datasets having hidden properties like time series datasets. Time series datasets is a special type of data which is ordered chronologically and needs special attention for handling it’s intrinsic elements like trend and seasonality.

当我们处理具有隐藏属性(例如时间序列数据集)的数据集时,事情会变得稍微复杂一些。 时间序列数据集是一种特殊的数据类型,按时间顺序排序,在处理其诸如趋势和季节性之类的内在要素时需要特别注意。

For these reasons, We will be focusing on a step-by-step guideline that walks through the EDA and data cleaning process one can follow while working with multivariate time series data.

由于这些原因,我们将重点关注逐步指南,该指南逐步介绍了在处理多元时间序列数据时可以遵循的EDA和数据清理过程。

指数: (Index:)

  • Understanding time series data — The Theory

    了解时间序列数据-理论
  • EDA (inspection, data profiling, visualizations)

    EDA(检查,数据分析,可视化)
  • Data Cleaning (missing data, outlier detection and treatment)

    数据清理(丢失数据,异常检测和处理)
  • Final words

    最后的话

了解时间序列数据-理论 (Understanding time series data — The Theory)

One of the best freely available sources to learn about time series analysis is the book ‘Forecasting Principles and Practices’ by Rob J Hyndman and George Athanasopoulos. Both of them are professors at Monash University, Australia and Rob was Editor-in-Chief of the International Journal of Forecasting and a Director of the International Institute of Forecasters from 2005 to 2018. I am going to summarize some of the basic elements of a time series dataset here and for further details, please refer to the mentioned book.

Rob J Hyndman和George Athanasopoulos所著的“ 预测原理和实践 ”一书是学习时间序列分析的最佳免费资源之一。 他们都是澳大利亚莫纳什大学(Monash University)的教授,罗布(Rob)是2005年至2018年《 国际 预测》杂志的主编和国际预测协会的主任。我将总结一下时间序列数据集,有关更多详细信息,请参阅上述书籍。

时间序列数据的元素 (Elements of Time Series Data)

A time series data can be considered a list of numbers, along with information about when those numbers were recorded.Most commonly, a time series is a sequence taken at successive equally spaced points in time.Time series data is composed of four elements:

时间序列数据可以看作是一个数字列表以及有关记录这些数字的时间的信息。最常见的是,时间序列是在连续的等间隔时间点上获取的序列。时间序列数据由四个元素组成:

Image for post

Decomposition techniques help us extract trend, seasonality and error/irregular components of a time series dataset. There are multiple decomposition techniques but we will be focusing on the additive method in this blog in the EDA section.

分解技术可帮助我们提取时间序列数据集的趋势,季节性和误差/不规则分量。 有多种分解技术,但在本博客的EDA部分中,我们将重点介绍加法。

平稳性 (Stationarity)

In the most intuitive sense, a stationary time series is one whose properties do not depend on the time at which the series is observed. Thus, time series with trends, or with seasonality, are not stationary — the trend and seasonality will affect the value of the time series at different times.

从最直观的意义上说,固定时间序列是一个其属性不依赖于观察该时间的时间的序列。 因此,具有趋势或季节性的时间序列不是固定的-趋势和季节性将影响不同时间的时间序列的值。

Image for post

Why is this property important? Stationary processes are easier to model as the way they change is predictable and stable. For most models involving time series, we will find ourselves determining if the data was generated by a stationary process, and if not, then we possibly need to transform it so it has the properties generated by such a process.

为什么这个属性很重要? 平稳过程更容易模型,因为他们改变的方式是可以预见的,稳定的。 对于大多数涉及时间序列的模型,我们将发现自己确定数据是否是由固定过程生成的,如果不是,则可能需要对其进行转换,使其具有由该过程生成的属性。

ACF和PACF (ACF and PACF)

Autocorrelation (ACF) and partial autocorrelation (PACF) plots are heavily used to determine stationarity and time series model parameters.These plots graphically summarize the strength of a relationship with an observation in a time series with observations at prior time steps.

自相关(ACF)和局部自相关(PACF)图被大量用于确定平稳性和时间序列模型参数,这些图以图形方式总结了时间序列中与观测值的关系强度以及先前时间步长的观测值。

For ACF plots, we calculate the correlation for time series observations with observations with previous time steps, called lags. The PACF plot is a summary of the relationship between an observation in a time series with observations at prior time steps with the relationships of intervening observations removed. Such time plots for a stationary process will have start having statistically insignificant values within the first few lags.

对于ACF图,我们计算时间序列观测值与具有先前时间步长的观测值(称为滞后)的相关性。 PACF图是时间序列中的观测值与先前时间步长的观测值之间的关系的摘要,其中删除了中间观测值的关系。 固定过程的此类时间图将在头几个滞后内开始具有统计上无关紧要的值。

EDA(检查,数据分析,可视化) (EDA (inspection, data profiling, visualizations))

To share my understanding of the common concepts and techniques on EDA, we will work on the multivariate time series dataset on Hong Kong flat prices along with various macro economics variables. It is a daily dataset starting from 2nd January 2003 and goes on till 26th November 2019. The dataset is available in Kaggle.

为了分享我对EDA的通用概念和技术的理解,我们将研究香港统一价格的多元时间序列数据集以及各种宏观经济变量。 它是一个每日数据集,从2003年1月2日开始,一直持续到2019年11月26日。该数据集可在Kaggle中获得 。

To begin with, we imported necessary python libraries (for this example pandas, numpy,matplotlib etc) and loaded the data set.

首先,我们导入了必要的python库(例如pandas,numpy,matplotlib等)并加载了数据集。

查看数据并检查字段类型 (Looking at the data and checking field types)

Image for post
  • To take a closer look at the data, used “ .head()”function of pandas library which returns first five observations of the data. Similarly “.tail()” returns last five observations of the data set.

    为了更仔细地查看数据,使用了熊猫库的“ .head()”函数,该函数返回数据的前五个观察值。 同样,“。tail()”返回数据集的最后五个观察值。
  • We found out the total number of rows and columns in the data set and data type of each column using “.info” function.Dataset comprises of 4233 observations and 14 columns. All the columns have the correct data format (Date is in datetime format and the rest are float). None of the columns have any null values

    我们使用“ .info”函数找出数据集中的行和列总数以及每一列的数据类型。数据集包含4233个观察值和14列。 所有列均具有正确的数据格式(日期为日期时间格式,其余为浮点型)。 所有列均无空值

获取摘要统计 (Get summary statistics)

Image for post
  • Here as you can notice mean value is more than median value of most columns which is represented by 50%(50th percentile) in index column.

    在这里您可以注意到,平均值大于大多数列的中位数,这由索引列中的50%(第50个百分位数)表示。
  • There is notably a big difference between 75th percentile and max values of certain fields like “First hand sales quantity”,”First hand sales amount”,”Total completions” etc.

    第75个百分位数与某些字段(例如“第一手销售数量”,“第一手销售数量”,“完成总数”等)的最大值之间存在很大差异。
  • Thus observations 1 and 2 suggests that there are extreme values-Outliers in our data set. We get the same conclusion once we look at the histograms of all the numeric fields.

    因此,观察值1和2表明在我们的数据集中存在极值-离群值。 查看所有数字字段的直方图,我们将得出相同的结论。
Image for post

检查目标变量的时间序列属性 (Checking time series properties of target variable)

Image for post
  • Target variable/Dependent variable (‘Private Domestic (Price Index)’)has a rising trend

    目标变量/因变量(“国内私有(价格指数)”)呈上升趋势
  • There is a seasonal dip in most years.

    大多数年份都有季节性下降。
  • The variation in 2020 are extreme compared to overall trend

    与整体趋势相比,2020年的变化是极端的
  • The target variable is not stationary

    目标变量不是固定的
Image for post
  • We have used the additive model for decomposition which assumes that the time series data is structured in the following manner:

    我们已使用加法模型进行分解,该模型假定时间序列数据的结构如下:

    Time Series Data = Trend + Seasonal + Random

    时间序列数据=趋势+季节性+随机

  • We can observe that the seasonal pattern is a regularly repeating pattern and that the trend is upward sloping but it is not a smooth line.

    我们可以观察到,季节性模式是有规律的重复模式,并且趋势呈向上倾斜,但不是一条平滑线。
Image for post
Image for post
  • The dataset is highly non-stationary as can be seen from the ACF and PACF plots.

    从ACF和PACF图可以看出,该数据集非常不稳定。

数据清理(丢失数据,异常值检测和处理) (Data Cleaning (missing data , outliers detection and treatment))

Data cleaning is the process of identifying and correcting inaccurate records from a dataset along with recognising unreliable or irrelevant parts of the data. We will be focusing on handling missing data and outliers in this blog.

数据清理是从数据集中识别和纠正不正确记录的过程,同时还要识别数据中不可靠或不相关的部分。 在此博客中,我们将专注于处理丢失的数据和异常值。

缺失数据 (Missing Data)

Image for post
  • Our raw data starts from “2003–01–02” and ends at “2019–11–26”. There are 6173 days between “2003–01–02” and “2019–11–26” but the original data only had 4233 record. So a few dates are missing.

    我们的原始数据从“ 2003-01-02”开始,到“ 2019-11-26”结束。 从“ 2003-01-02”到“ 2019-11-26”之间有6173天,但是原始数据只有4233条记录。 因此缺少一些日期。
  • We create a new dataset with all the 6173 dates and join the original dataset with this new dataset. This leads to null values for all the record not available in the original dataset.

    我们使用所有6173个日期创建一个新数据集,并将原始数据集与此新数据集连接。 这将导致原始数据集中不可用的所有记录的空值。
Image for post
  • We use linear interpolation to fill in the null values

    我们使用线性插值来填充空值

离群值检测 (Outlier detection)

Wikipedia definition,

维基百科的定义,

In statistics, an outlier is an observation point that is distant from other observations.

在统计中, 离群 点是与其他观测值相距较远的观测点。

To ease the discovery of outliers, we have plenty of methods in statistics, but we will only be discussing few basic techniques (interquartile range, standard deviation) here. In a separate blog, I will be focusing on the advanced methods.

为了简化离群值的发现,我们在统计数据中提供了很多方法,但是在这里我们将只讨论一些基本技术(四分位间距,标准差)。 在另一个博客中,我将重点介绍高级方法。

Image for post
  • The Interquartile range (IQR) is calculated as the difference between the 75th and the 25th percentiles of the data.The IQR can be used to identify outliers by defining limits on the sample values that are a factor k of the IQR below the 25th percentile or above the 75th percentile. The common value for the factor k is the value 1.5 (which we have used here). A factor k of 3 or more can be used to identify values that are extreme outliers or “far outs”.

    四分位间距(IQR)由数据的第75个百分位数和第25个百分位数之间的差计算得出.IQR可以通过定义样本值的限制来识别异常值,这些样本值是IQR的第25个百分位数以下的因数k或高于第75个百分点。 因子k的公共值为1.5(我们在这里使用)。 3或更大的系数k可用于识别极端离群值或“ 远距 ”值。

  • For the initial values, fields like ‘Total Completion’ have a lot of outliers.

    对于初始值,“总计完成”之类的字段有很多异常值。
  • If we know that the distribution of values in the sample is Gaussian or Gaussian-like, we can use the standard deviation of the sample as a cut-off for identifying outliers.Three standard deviations from the mean is a common cut-off in practice for identifying outliers in a Gaussian or Gaussian-like distribution. For smaller samples of data, perhaps a value of 2 standard deviations (95%) can be used, and for larger samples, perhaps a value of 4 standard deviations (99.9%) can be used.

    如果我们知道样本中值的分布是高斯或类高斯分布,则可以使用样本的标准偏差作为识别异常值的分界点。与平均值的三个标准差是实践中的常见分界点用于识别高斯或高斯分布中的离群值。 对于较小的数据样本,也许可以使用2个标准偏差(95%)的值,对于较大的样本,也许可以使用4个标准偏差(99.9%)的值。

离群值处理 (Outlier treatment)

Image for post
  • All the identified outliers are replaced by nulls first.

    首先将所有标识的异常值替换为零。
  • Then the nulls are filled by linear interpolation. In a separate blog, a more robust approach to replace outliers will be discussed.

    然后,通过线性插值填充零点。 在单独的博客中,将讨论一种更健壮的方法来替换异常值。

最后的话 (Final Words)

I hope this blog helps the readers make sense of their datasets as well handle some of the issues with messy data. Apart from the that, the readers should now be able to understand the basic elements of a time series dataset as well. But it is important to understand that each dataset comes has its own unique challenges and will need a customized approach to make the data usable.

我希望这个博客可以帮助读者理解他们的数据集,并解决一些数据混乱的问题。 除此之外,读者现在还应该能够理解时间序列数据集的基本元素。 但重要的是要了解,每个数据集都有其独特的挑战,并且需要一种定制的方法来使数据可用。

These are some of the questions one should always ask while working with a new dataset:

这些是在使用新数据集时应始终提出的一些问题:

How the data is collected, and under what conditions?

如何收集数据,在什么条件下收集数据?

What does the data represent?

数据代表什么?

What are the issues in the dataset? Are there any outliers?

数据集中有什么问题? 有离群值吗?

What methods should be used to clean the data and why?

应该使用什么方法清除数据,为什么?

This is a first blog in a series focused on creating a robust forecasting engine based on a multivariate time series data. The next blog will focus on feature engineering and selection. Stay tuned!

这是该系列中的第一个博客,致力于基于多元时间序列数据创建强大的预测引擎。 下一个博客将重点介绍功能设计和选择。 敬请关注!

翻译自: https://medium.com/@indraneeldb1993ds/cleaning-and-understanding-multivariate-time-series-data-6554eefbda9c

时间序列数据的多元回归

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/389760.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

vue-cli搭建项目的目录结构及说明

vue-cli基于webpack搭建项目的目录结构 build文件夹 ├── build // 项目构建的(webpack)相关代码 │ ├── build.js // 生产环境构建代码(在npm run build的时候会用到这个文件夹)│ ├── check-versions.js // 检查node&am…

391. 完美矩形

391. 完美矩形 给你一个数组 rectangles ,其中 rectangles[i] [xi, yi, ai, bi] 表示一个坐标轴平行的矩形。这个矩形的左下顶点是 (xi, yi) ,右上顶点是 (ai, bi) 。 如果所有矩形一起精确覆盖了某个矩形区域,则返回 true ;否…

bigquery 教程_bigquery挑战实验室教程从数据中获取见解

bigquery 教程This medium article focusses on the detailed walkthrough of the steps I took to solve the challenge lab of the Insights from Data with BigQuery Skill Badge on the Google Cloud Platform (Qwiklabs). I got access to this lab in the Google Cloud R…

学习linux系统到底有没捷径?

2019独角兽企业重金招聘Python工程师标准>>> 说起linux操作系,可能对于很多不了解的人来说,第一个想到的就是类似于黑客帝国中的黑框框以及一串串不知所云的代码,总之这些感觉都可以总结成为一个字,那就是——酷&#…

wxpython实现界面跳转

wxPython实现Frame之间的跳转/更新的一种方法 wxPython是Python中重要的GUI框架,下面通过自己的方法实现模拟类似PC版微信登录,并跳转到主界面(朋友圈)的流程。 (一)项目目录 【说明】 icon : 保存项目使用…

java职业技能了解精通_如何通过精通数字分析来提升职业生涯的发展,第8部分...

java职业技能了解精通Continuing from the seventh article in this series, we are going to explore ways to present data. Over the past few years, Marketing and SEO field has become more data-driven than in the past thanks to tools like Google Webmaster Tools …

kfc流程管理炸薯条几秒_炸薯条成为数据科学的最后前沿

kfc流程管理炸薯条几秒In February, our Data Science team had an argument about which restaurant we went to made the best French Fry.2月,我们的数据科学团队对我们去哪家餐厅做得最好的炸薯条产生了争议。 We decided to make it a competition throughout…

bigquery_到Google bigquery的sql查询模板,它将您的报告提升到另一个层次

bigqueryIn this post, we’re sharing report templates that you can build with SQL queries to Google BigQuery data.在本文中,我们将分享您可以使用SQL查询为Google BigQuery数据构建的报告模板。 First, you’ll find out about what you can calculate wit…

分类树/装袋法/随机森林算法的R语言实现

原文首发于简书于[2018.06.12] 本文是我自己动手用R语言写的实现分类树的代码,以及在此基础上写的袋装法(bagging)和随机森林(random forest)的算法实现。全文的结构是: 分类树 基本知识predginisplitrules…

数据科学学习心得_学习数据科学时如何保持动力

数据科学学习心得When trying to learn anything all by yourself, it is easy to lose motivation and get thrown off track.尝试自己学习所有东西时,很容易失去动力并偏离轨道。 In this article, I will provide you with some tips that I used to stay focus…

用php当作cat使用

今天,本来是想敲 node test.js 执行一下,test.js文件,结果 惯性的敲成了 php test.js, 原文输出了 test.js的内容。 突然觉得,这东西 感觉好像是 cat 命令,嘿嘿,以后要是ubuntu 上没装 cat , …

建信01. 间隔删除链表结点

建信01. 间隔删除链表结点 给你一个链表的头结点 head,每隔一个结点删除另一个结点(要求保留头结点)。 请返回最终链表的头结点。 示例 1: 输入:head [1,2,3,4] 输出: [1,3] 解释: 蓝色结点为删除的结点…

python多项式回归_在python中实现多项式回归

python多项式回归Video Link影片连结 You can view the code used in this Episode here: SampleCode您可以在此处查看 此剧 集中使用的代码: SampleCode 导入我们的数据 (Importing our Data) The first step is to import our data into python.第一步是将我们的…

Uboot 命令是如何被使用的?

有什么问题请 发邮件至syyxyoutlook.com, 欢迎交流~ 在uboot代码中命令的模式是这个样子: 这样是如何和命令行交互的呢? 在command.h 中, 我们可以看到如下宏定义 将其拆分出来: #define U_BOOT_CMD(name,maxargs,rep,cmd,usage,help) \ U_…

大数据可视化应用_在数据可视化中应用种族平等意识

大数据可视化应用The following post is a summarized version of the article accepted to the 2020 Visualization for Communication workshop as part of the 2020 IEEE VIS conference to be held in October 2020. The full paper has been published as an OSF Preprint…

Windows10电脑系统时间校准

有时候新安装电脑系统,系统时间不对,需要主动去校准系统时间。1、点击时间 2、日期和时间设置 3、其他日期、时间和区域设置 4、设置时间和日期 5、Internet 时间 6、点击立即更新,如果更新失败就查电脑是否已联网,重试点击立即更…

pd种知道每个数据的类型_每个数据科学家都应该知道的5个概念

pd种知道每个数据的类型意见 (Opinion) 目录 (Table of Contents) Introduction 介绍 Multicollinearity 多重共线性 One-Hot Encoding 一站式编码 Sampling 采样 Error Metrics 错误指标 Storytelling 评书 Summary 摘要 介绍 (Introduction) I have written about common ski…

xgboost keras_用catboost lgbm xgboost和keras预测财务交易

xgboost kerasThe goal of this challenge is to predict whether a customer will make a transaction (“target” 1) or not (“target” 0). For that, we get a data set of 200 incognito variables and our submission is judged based on the Area Under Receiver Op…

2017. 网格游戏

2017. 网格游戏 给你一个下标从 0 开始的二维数组 grid ,数组大小为 2 x n ,其中 grid[r][c] 表示矩阵中 (r, c) 位置上的点数。现在有两个机器人正在矩阵上参与一场游戏。 两个机器人初始位置都是 (0, 0) ,目标位置是 (1, n-1) 。每个机器…

HUST软工1506班第2周作业成绩公布

说明 本次公布的成绩对应的作业为: 第2周个人作业:WordCount编码和测试 如果同学对作业成绩存在异议,在成绩公布的72小时内(截止日期4月26日0点)可以进行申诉,方式如下: 毕博平台的第二周在线答…