-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlgorithm.py
More file actions
61 lines (49 loc) · 1.77 KB
/
Algorithm.py
File metadata and controls
61 lines (49 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from matplotlib import pyplot as plt
class Algorithm:
def __init__(self, **kwargs):
"""
Initialize the Algorithm.
:param data: time series data (pandas Series or numpy array)
:param **kwargs: options for algorithm
"""
self.options = kwargs
self.data = None
self.results = None
self.model = None
def fit(self, **kwargs):
"""
Train the model on the provided data.
"""
pass
def predict(self, steps=1):
"""
Make predictions for future values using the trained model.
:param steps: number of future steps to forecast
:return: array of predictions
"""
if not self.model:
raise ValueError("Model is not trained. Call the fit() method before making predictions.")
return self.results.predict(start=len(self.data), end=len(self.data) + steps - 1)
def get_options(self):
"""
:return: dict of options
"""
return self.options
def summary(self):
"""
Print a statistical summary of the model.
"""
if not self.model:
raise ValueError("Model is not trained. Call the fit() method before printing the summary.")
print(self.results)
print(self.results.summary())
def plot_results(self, ax, actual_data, predicted_data, color, lines):
"""
Plot the actual vs. predicted values.
:param actual_data: actual time series data
:param predicted_data: predicted time series data
"""
ax.plot(actual_data, marker="o", color="black")
ax.plot(self.results.fittedvalues, marker="o", color=color)
(line1,) = ax.plot(predicted_data, marker="o", color=color)
lines.append(line1)