US race (matlab self-study) time series

Deterministic time series analysis

Here Insert Picture Description

Moving Average Method

Here Insert Picture Description

example

Here Insert Picture Description
Were taken N = 4, N = 5;

clc,clear
y=[533.8, 574.6, 606.9, 649.8, 705.1, 772.0, 816.4, 892.7, 963 .9, 1015.1 ,1102.7];
m= length(y);
n=[4,5];%n为移动平均的项数
for i =1:length(n)%由于n的取值不同,因此下面使用了细胞数组.
for j =1:m-n(i) +1
yhat{i}(j) =sum(y(j:j +n(i) -1))/n(i);
end 
y12(i) =yhat{i}(end);%提出12月的预测值
s(i) = sqrt( mean((y(n(i) +1:end) -yhat{i}(1:end-1)).^2));%求预测的标准误差
end
y12, s%分别显示两种方法的预测值和预测的标准误差

Here Insert Picture Description

Exponential Smoothing
Exponential Smoothing

Here Insert Picture Description

example

Here Insert Picture Description

clc,clear
yt = load('dianqi .txt');%实际销售额数据以列向量的方式存放在纯文本文件中
n= length(yt); alpha=[0.2 0.5 0.8]; m= length( alpha);
yhat(1,[1:m]) =(yt(1) +yt(2))/2;
for i =2:n
yhat(i,:) =alpha *yt(i-1) +(1 -alpha). *yhat(i -1,:);
end
yhat
err = sqrt(mean( ( repmat(yt,1 ,m) -yhat).^2))
xlswrite( 'dianqi .xls' ,yhat)%把预测数据写到Excel文件,准备在Word表格中使用
yhat1988 =alpha*yt(n) +(1 -alpha). *yhat(n,:)
Secondary Exponential Smoothing

Here Insert Picture Description

Three exponential smoothing

Here Insert Picture Description

Exponential Smoothing Difference

First difference exponential smoothing
Here Insert Picture Description
template code

clc,clear
yt = load( 'ranliao.txt');%实际燃料消耗量数据以列向量的方式存放在纯文本文件中.
n= length(yt); alpha=0.4;
dyt =diff(yt); %求yt的一阶向前差分
dyt =[0;dyt]; %这里使用的是一阶向后差分,加“0”补位
dyhat(2) =dyt(2); %指数平滑值的初始值
for i =2:n
dyhat(i +1) =alpha *dyt(i) +(1 - alpha) * dyhat(i);
end
for i =1:n
yhat(i +1) =dyhat(i +1) +yt(i);  
end
yhat
xlswrite( 'ranliao .xls' ,[yt ,dyt])
xlswrite( 'ranliao .x1s',[ dyhat' ,yhat'], 'Sheet1','C1')

Exponential Smoothing second order difference
Here Insert Picture Description

Time series prediction is seasonal

Here Insert Picture Description

Published 20 original articles · won praise 0 · Views 3862

Guess you like

Origin blog.csdn.net/weixin_44544406/article/details/104233846