Sales Forecast: October 9, 2020
Sales Forecast: October 9, 2020
Sales Forecast: October 9, 2020
October 9, 2020
1
Date Sales
<dttm> <dbl>
1995-01-01 1463.9
1995-02-01 1373.3
A tibble: 6 Œ 2
1995-03-01 1533.7
1995-04-01 1420.6
1995-05-01 1576.3
1995-06-01 1607.5
2
In [13]: monthly <- sales_df %>% group_by(month) %>% summarize(mean=mean(Sales))
sales_df$year <- lubridate::year(sales_df$Date)
lastYear <- sales_df %>% filter(year==2009)
In [14]: head(sales_df)
In [15]: install.packages("forecast")
also installing the dependencies 'xts', 'TTR', 'quadprog', 'quantmod', 'fracdiff', 'tseries', '
In [21]: sales_df.ts
3
Jan Feb Mar Apr May Jun Jul Aug Sep O
1 1463.9 1373.3 1533.7 1420.6 1576.3 1607.5 1545.7 1550.8 1583.0 16
2 1580.7 1485.5 1582.6 1498.9 1644.5 1610.9 1695.0 1664.9 1583.8 17
3 1686.0 1576.9 1608.8 1610.8 1712.9 1664.3 1698.0 1662.9 1678.9 18
4 1724.9 1531.3 1660.0 1602.0 1677.0 1668.8 1699.6 1649.9 1685.0 17
5 1775.4 1597.2 1733.6 1681.0 1764.5 1779.0 1817.4 1830.7 1894.3 20
6 1924.7 1813.6 1919.9 1769.8 1985.7 2346.3 1875.7 2013.1 2015.7 20
7 2095.8 1887.4 2063.2 1982.7 2118.3 2205.1 2217.5 2253.1 2188.7 24
A Time Series: 15 Œ 12
8 2438.8 2123.9 2296.4 2336.0 2478.6 2475.0 2465.3 2501.2 2460.6 26
9 2528.5 2231.8 2430.7 2368.9 2539.9 2595.6 2675.1 2665.2 2726.7 29
10 2829.9 2545.4 2746.3 2569.2 2675.2 2793.8 2843.3 2798.1 2848.0 30
11 2963.1 2622.9 2782.9 2787.4 2879.3 2969.3 2964.4 2984.4 2971.0 30
12 3036.0 2692.5 2953.4 2804.1 3026.2 3148.2 3120.4 3150.1 3196.1 33
13 3332.3 2963.4 3283.3 3010.1 3239.8 3399.0 3333.5 3433.6 3443.2 35
14 3535.1 3142.9 3212.5 3238.4 3349.2 3443.7 3413.8 3411.0 3327.8 35
15 3560.7 2968.2 3301.6 3203.9 3379.7 3620.6 3452.3 3467.7 3406.1 36
4
In [24]: ntrain = 168
ntest = 12
In [33]: devtools::install_github("mlr-org/measures")
5
v checking for file 'C:\Users\woosh\AppData\Local\Temp\Rtmp6ppStO\remotes41681cad3a2a\pat-s-me
- preparing 'measures': (548ms)
v checking DESCRIPTION meta-information
- checking for LF line-endings in source and make files and shell scripts (543ms)
- checking for empty or unneeded directories
- building 'measures_0.2.tar.gz'
1426.6870075458
Call:
lm(formula = Sales ~ time, data = sales_df)
Residuals:
Min 1Q Median 3Q Max
-623 -196 -48 81 1344
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1299.41 46.40 28 <2e-16 ***
time 13.48 0.44 30 <2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
6
In [40]: mod <- lm(Sales ~ time + I(time^2) + factor(month), data=sales_df)
print(summary(mod), digits=2)
Call:
lm(formula = Sales ~ time + I(timeˆ2) + factor(month), data = sales_df)
Residuals:
Min 1Q Median 3Q Max
-441 -79 6 98 464
Coefficients:
Estimate Std. Error t value Pr(>|t|)
7
(Intercept) 1.4e+03 4.7e+01 30.2 <2e-16 ***
time 9.3e+00 8.2e-01 11.4 <2e-16 ***
I(timeˆ2) 2.2e-02 4.4e-03 5.0 2e-06 ***
factor(month)10 6.9e+01 5.2e+01 1.3 0.188
factor(month)11 1.5e+02 5.2e+01 2.8 0.005 **
factor(month)12 8.4e+02 5.2e+01 16.2 <2e-16 ***
factor(month)2 -2.7e+02 5.2e+01 -5.3 4e-07 ***
factor(month)3 -1.2e+02 5.2e+01 -2.3 0.025 *
factor(month)4 -2.1e+02 5.2e+01 -4.1 7e-05 ***
factor(month)5 -8.1e+01 5.2e+01 -1.6 0.121
factor(month)6 -8.8e+00 5.2e+01 -0.2 0.865
factor(month)7 -5.6e+01 5.2e+01 -1.1 0.282
factor(month)8 -5.5e+01 5.2e+01 -1.1 0.293
factor(month)9 -7.0e+01 5.2e+01 -1.3 0.180
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
8
In [ ]: