feat(Model): added own Model class, SkLearnModel wrapper and StaticMomentumModel (#61)

* feat(Model): added own `Model` class, SkLearnModel wrapper and StaticMomentumModel

* fix(Tests): added missing Model variable

* fix(Tests): added missing clone method()
This commit is contained in:
Mark Aron Szulyovszky
2021-12-21 10:30:09 +01:00
committed by GitHub
parent 85ad937078
commit 79d84cf0a3
8 changed files with 122 additions and 45 deletions
+8 -2
View File
@@ -2,7 +2,7 @@
import numpy as np
import pandas as pd
from training.walk_forward import walk_forward_train_test
from sklearn.base import BaseEstimator
from models.base import Model
from utils.evaluate import evaluate_predictions
no_of_rows = 100
@@ -29,12 +29,15 @@ def __generate_even_odd_test_data(no_of_rows) -> tuple[pd.DataFrame, pd.Series]:
return X, y
class EvenOddStubModel(BaseEstimator):
class EvenOddStubModel(Model):
'''
A deteministic model that can predict the future with 100% accuracy
It verifies that the X[n][any_column] == 1 if n is even,
'''
data_scaling = "unscaled"
only_column = None
def __init__(self, window_length) -> None:
super().__init__()
self.window_length = window_length
@@ -47,6 +50,9 @@ class EvenOddStubModel(BaseEstimator):
def predict(self, X):
return np.array([-1 if X[0][0] == 1 else 1])
def clone(self):
return self
def test_evaluation():
X, y = __generate_even_odd_test_data(no_of_rows)
+7 -2
View File
@@ -1,7 +1,7 @@
import numpy as np
import pandas as pd
from training.walk_forward import walk_forward_train_test
from sklearn.base import BaseEstimator
from models.base import Model
no_of_rows = 100
@@ -27,12 +27,15 @@ def __generate_incremental_test_data(no_of_rows) -> tuple[pd.DataFrame, pd.Serie
class IncrementingStubModel(BaseEstimator):
class IncrementingStubModel(Model):
'''
A deteministic model that can predict the future with 100% accuracy
It verifies that the X[n][any_column]+1 == y[n]
'''
data_scaling = "unscaled"
only_column = None
def __init__(self, window_length) -> None:
super().__init__()
self.window_length = window_length
@@ -45,6 +48,8 @@ class IncrementingStubModel(BaseEstimator):
def predict(self, X):
return np.array([X[0][0] + 1])
def clone(self):
return self
def test_walk_forward_train_test():
X, y = __generate_incremental_test_data(no_of_rows)