Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2022-211
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2022-211
2022-211
Commits
91c987f3
Commit
91c987f3
authored
May 13, 2022
by
H.C.K. De Silva
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ARIMA model commit
parent
6e459804
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
0 deletions
+59
-0
arima.py
arima.py
+59
-0
No files found.
arima.py
0 → 100644
View file @
91c987f3
import
pandas
as
pd
import
numpy
as
np
from
statsmodels.tsa.stattools
import
adfuller
from
pmdarima
import
auto_arima
from
statsmodels.tsa.arima_model
import
ARIMA
from
sklearn.metrics
import
mean_squared_error
from
math
import
sqrt
import
warnings
warnings
.
filterwarnings
(
"ignore"
)
df
=
pd
.
read_csv
(
'processed_data/nikewaratiya_train.csv'
,
index_col
=
'ds'
,
parse_dates
=
True
)
df
=
df
.
dropna
()
print
(
'Shape of data'
,
df
.
shape
)
print
(
df
.
head
())
def
adf_test
(
dataset
):
dftest
=
adfuller
(
dataset
,
autolag
=
'AIC'
)
print
(
"1. ADF : "
,
dftest
[
0
])
print
(
"2. P-Value : "
,
dftest
[
1
])
print
(
"3. Num Of Lags : "
,
dftest
[
2
])
print
(
"4. Num Of Observations Used For ADF Regression and Critical Values Calculation :"
,
dftest
[
3
])
print
(
"5. Critical Values :"
)
for
key
,
val
in
dftest
[
4
]
.
items
():
print
(
"
\t
"
,
key
,
": "
,
val
)
adf_test
(
df
[
'y'
])
stepwise_fit
=
auto_arima
(
df
[
'y'
],
suppress_warnings
=
True
)
print
(
stepwise_fit
.
summary
())
print
(
df
.
shape
)
train
=
df
.
iloc
[:
-
30
]
test
=
df
.
iloc
[
-
30
:]
print
(
train
.
shape
,
test
.
shape
)
print
(
test
.
iloc
[
0
],
test
.
iloc
[
-
1
])
model
=
ARIMA
(
train
[
'y'
],
order
=
(
1
,
0
,
0
))
model
=
model
.
fit
()
model
.
summary
()
start
=
len
(
train
)
end
=
len
(
train
)
+
len
(
test
)
-
1
pred
=
model
.
predict
(
start
=
start
,
end
=
end
,
typ
=
'y'
)
.
rename
(
'ARIMA predictions'
)
# pred.index=index_future_dates
pred
.
plot
(
legend
=
True
)
test
[
'y'
]
.
plot
(
legend
=
True
)
rmse
=
sqrt
(
mean_squared_error
(
pred
,
test
[
'y'
]))
print
(
rmse
)
model2
=
ARIMA
(
df
[
'y'
],
order
=
(
2
,
1
,
1
))
model2
=
model2
.
fit
()
df
.
tail
()
# model2.save('model.pkl')
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment