mirror of
https://github.com/webclinic017/drift.git
synced 2026-08-13 10:58:06 +00:00
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:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user