Forecasting:Principles and Practice 读书小笔记(一)

Chapter 1   Getting Started


影响预测的因素包括:

    1. 对于主要影响因子的理解、使用程度

    2. 数据量

    3. 预测值是否会影响事物发展

预测vs目标vs计划的差异性:

    预测:尽可能精准的预估未来,要提供尽可能全面的信息,包括历史数据及可能影响预测的未来事件

    目标:你希望发生的事情。需要和预测及计划相关联【通常无计划和无预测】

    计划:对预测、目标的相应。预测主要有为使得预测结果匹配目标所必须的拆解动作    

预测方法:

    Qualitative forecasting:没有可用数据或数据与预测不相关

    Quantitative forcasting:

        1. 需要满足以下两点:

                a. 过去的数字化信息可获取;

                b. 过去周期的某些特征在未来是可持续的

        2. 数据类型:

                a. 时间序列数据

                b. cross-section data(collected at a single point in time)

预测项目的的基本步骤:

    1. 定义问题:需要了解预测的应用场景,要求预测的需求方,此项预测如何fit公司组织的宏观预测。预测人员需要去和所有涉及到数据收集、数据库管理及基于未来规划提出预测的人进行充分的沟通交流

    2. 收集信息:两类必须包含的信息有统计数据和应用预测、收集数据的人的累计经验。

    3. 初步(探索性)分析:将数据图形化,看是否有周期性?是否有显著的趋势?季节性是否重要?是否有当前的商业周期证据?是否有需要被解释的outliers?可用变量间的关联性如何?

    4. 选择and建立模型:最佳模型的使用取决于可使用的历史数据、预测变量间的相关性、解释变量以及预测的使用方式。通常比较2-3个有潜力模型。(备选有:线性回归、指数平滑、Box-Jennkins ARIMA、动态回归、层级预测、神经网络、变量自动回归等先进模型)

    5. 使用并评估预测模型:模型的表现只能通过预测值与实际值的比较。

预估值:所谓预估值,实际是指预估分布的平均值(中位数)。

Chapter 2 Time series graphics


####基于R,library(fpp2)####

时间序列:可以将其视为一串数字及数字相关的信息。这些相关信息可以被存储为ts对象

x<-ts(b$gmv,start=2016,frequency = 12)

Time plots: the observations are plotted against the time of observation, with consecutive observations joined by straight lines.观测值是基于时间绘制的,并用一条直线将他们连接。

autoplot(melsyd[,"Economy.Class"]) + 

    ggtitle("Economy class passengers: Melbourne-Sydney") + 

    xlab("Year") + 

    ylab("Thousands")

We will use the autoplot() command frequently. It automatically produces an appropriate plot of whatever you pass to it in the first argument. 

Time Series Patterns:

    1. Trend【趋势】:当数据存在长期的增长或下降时才有“trend”。不一定是线性的,有时也说trend是一个变化方向。

    2. Seasonal【季节性】:当时间序列受季节性因素影响时会出现seasonal pattern。季节性是一个固定的已知的发生率。 

    3. Cyclic【循环】:当数据表现为非固定周期的上升或下降时则出现了循环。这些波动通常是受经济条件影响,通常表现为经济周期。这些波动通常至少持续2年。

cyclic behavior vs seasonal behavior:波动不固定时是cyclic,如果发生率不变且某些方面受时间周期影响则是seasonal。通常来说,cycle比seasonal长,并且cycle的波动幅度更大。


Seasonal Plot: A seasonal plot is similar to a time plot except that the data are plotted against the individual “seasons” in which the data were observed. 观测值是基于其“季节”所绘制的。A seasonal plot allows the underlying seasonal pattern to be seen more clearly, and is especially useful in identifying years in which the pattern changes. Seasonal Plot可以让不显著的季节性pattern更清晰,特别是有助于辨别pattern发生变化的年份。

ggseasonplot(a10, year.labels=TRUE, year.labels.left=TRUE) +

    ylab("$ million") +

    ggtitle("Seasonal plot: antidiabetic drug sales")

tips: A useful variation on the seasonal plot uses polar coordinates. Setting polar=TRUE makes the time series axis circular rather than horizontal, as shown below.

ggseasonplot(a10, polar=TRUE) + 

    ylab("$ million") + 

    ggtitle("Polar seasonal plot: antidiabetic drug sales")

Seasonal subseries plots: emphasises the seasonal patterns is where the data for each season are collected together in separate mini time plots.在每一个按季节集合在一起的小图中强调季节性pattern

ggsubseriesplot(a10) +

    ylab("$ million") +

    ggtitle("Seasonal subseries plot: antidiabetic drug sales")


横线为每月均值

--------time plots和seasonal plot都是反映单一时间序列的---------

1. scatterplot 散点图:观测两组变量间的关系

qplot(Temperature, Demand, data=as.data.frame(elecdemand)) + ylab("Demand (GW)") + xlab("Temperature (Celsius)")


lag plot 滞后图: Plot time series against lagged versions of themselves. Helps visualizing ‘auto-dependence’ even when auto-correlations vanish.

###lag plot:可以用来检查数据或时间序列是不是随机序列。如果是随机的,那么在lag plot中是看不出任何结构的。###探索性数据分析

beer2 <- window(ausbeer, start=1992)

gglagplot(beer2)


取1992往后澳大利亚每个季度的啤酒产量。lag 1是错位一个q的图,lag 2是错位两个q的图。由此可见lag 4和lag 8有极强的正相关性,反应了极强的周期性。lag 2和lag 4的负相关性,是q2和q4的比。

【图中,X轴表示一个数据点在t时刻的数值,而Y轴表示这个时间点在前lag个时刻的数值,左上图lag就是1。可以看到中间有一条等值线,代表该时刻与前lag个时刻的值相等的情况。如果很多值都在等值线附近,说明t与t-lag时刻情况类似,可能存在长度为lag的周期。-----from 天元大神的小笔记:R语言时间序列分析(四):时滞图、自相关、白噪声 - 知乎】

autocorrelation 自相关:measures the linear relationship between lagged values of a time series. 

【同样一个指标,如果时间靠的比较近,那么它们的数值也可能相近。一个序列,与它的延时序列(t-n时刻的序列),所存在的相关关系,称之为自相关,一般使用相关系数来计算。】

在lag plot的多个panel中存在多个自相关系数(autocorrelation coefficient ),如r1衡量yt和yt-1间的关系,r2衡量yt和yt-2间的关系,等等。因此rk可以被写作:【其中T是时间周期的长度】

###趋势性序列,lag越小自相关系数越大,因为相邻样本时间接近大小也相近。季节性序列,在季节周期的lag时,自相关系数会大于其他lag。

white noise 白噪声:Time series that show no autocorrelation are called white noise. 数据前后之间无相关性

For a white noise series, we expect 95% of the spikes in the ACF to lie within ±2/√T±2/T where TT is the length of the time series. It is common to plot these bounds on a graph of the ACF (the blue dashed lines above). If one or more large spikes are outside these bounds, or if substantially more than 5% of spikes are outside these bounds, then the series is probably not white noise.

你可能感兴趣的:(Forecasting:Principles and Practice 读书小笔记(一))