Original link:tecdat.cn/?p=18493

Original source:Tuo End number according to the tribe public number

 

In this paper, we use four time series models to model the weekly temperature series. The first is obtained by auto. Arima, then two are the SARIMA model, and the last is the Buys-Ballot method.

We use the following data


k=620
n=nrow(elec)
futu=(k+1):n
y=electricite$Load[1:k]
plot(y,type="l")
Copy the code

 

We started to model the temperature series (which has a great influence on the power load)

​
y=Temp
plot(y,type="l")
Copy the code

 


abline(lm(y[ :k]~y[( :k)-52]),col="red")


​
Copy the code

 

 

Time series are autocorrelated at order 52

​
acf(y,lag=120)

​
Copy the code

 

 

​
model1=auto.arima(Y)
acf(residuals(model1),120)

​
Copy the code

We save this model in the workspace and look at its predictions. Let’s try SARIMA here

C (Y,order = c(0,0,0))Copy the code

Then let’s try using seasonal unit roots

C = c(0,0,1) c = c(0,0,1) c = c(0, 1)Copy the code

Then, we can try the Buys-Ballot model

​
lm(Temp~0+as.factor(NumWeek),


​
Copy the code

 

Make predictions about the model


plot(y,type="l",xlim=c(0,n )
abline(v=k,col="red")
lines(pre4,col="blue")

​
Copy the code

 


plot(y,type="l",xlim=c(0,n))
abline(v=k,col="red")

​
Copy the code

 

 

​
plot(y,type="l",xlim=c(0,n))

​
Copy the code

 

 

​
plot(y,type="l",xlim=c(0,n))
abline(v=k,col="red")
 
​
Copy the code

 

Finally, the results of the four models are compared


lines( MODEL$y1,col="  
lines( MODEL$y2,col="green")
lines( MODEL$y3,col="orange")
lines( MODEL$y4,col="blue")

​
Copy the code

 

Then, we can try a weighted average to optimize the model, instead of figuring out which of the four models is “optimal”, y ^ T = ∑ I ωiy ^ T (I) where ω= (ω I), ω1+… + omega k = 1. Then, we want to find the “best” weights. We will calibrate our four models on the first m value, and then compare the predicted combinations of 111 values (and true values),

 

We use the first 200 values.

Then, we fit four models on these 200 values

And then we make predictions

 
  y1=predict(model1,n.ahead = 111)$pred,
  y2=predict(model2,n.ahead = 111)$pred,
  y3=predict(model3,n.ahead = 111)$pred,
  y4=predict(model4,n.ahead = 111)$pred+
 
​
Copy the code

To create a linear combination of predictions, we use

A =rep(1/4,4) y_pr = as. Matrix (DOS[,1:4]) %*% aCopy the code

Therefore, we visualize the four predictions, their linear combinations (with equal weights) and their observations

To find the “best” value for the weights and minimize the sum of squares of error, we use the following code

​
function(a) sum( DONN[,1:4  %*% a-DONN[,5 )^2 
 

​
Copy the code

We get the optimal weight

Optim (par = c (0, 0), erreur2) $parCopy the code

Then, we need to ensure the convergence of the two algorithms: the SARIMA parameter estimation algorithm and the weight parameter research algorithm.

If (inherits(TRY, "try-error") arima(y,order = c(4,0,0) seasonal = list(order = c(1,0,0))Copy the code

Then, we look at the weight change over time.

Get the figure below, where pink is Buys-Ballot, pink is SARIMA model, green is seasonal unit root,

 
barplot(va,legend = rownames(counts) 

​
Copy the code

 

We found that the model with the highest weight was the Buys Ballot model.

We can change the loss function, for example, we use 90% of the quantile,

​
tau=.9
function(e) (tau-(e<=0))*e

​
Copy the code

In the function, we use

 

 

This time, the two most heavily weighted models are SARIMA and Buys-Ballot.


Most welcome insight

1. Use LSTM and PyTorch for time series prediction in Python

2. Long and short-term memory model LSTM is used in Python for time series prediction analysis

3. Time series (ARIMA, exponential smoothing) analysis using R language

4. R language multivariate Copula – Garch – model time series prediction

5. R language Copulas and financial time series cases

6. Use R language random wave model SV to process random fluctuations in time series

7. Tar threshold autoregressive model for R language time series

8. R language K-Shape time series clustering method for stock price time series clustering

Python3 uses ARIMA model for time series prediction