mirror of
https://github.com/webclinic017/drift.git
synced 2026-08-08 00:27:50 +00:00
Refactor(Training): new outcome types, representative pipeline steps, bet-sizing (#187)
* refactor(Training): added InferenceResult & TrainedModel types * refactor(Pipeline): introduced TrainingOutcome, BetSizingWithMetaOutcome, etc. * fix(Pipeline): getting it to compile * refactor(WalkForward): separate preprocessing step * feat(Pipeline): separate out transformations processing step * refactor(Pipeline): use the Directional model terminology, put bet_sizing into pipeline instead of hiding it in a step * refactor(WalkForward): moved functions to separate folder * fix(WalkForward): use sparse array to store models, process transformations in parallel (lot faster) * fix(Tests): and evaluation * fix(Tests): for realz * fix(Inference): preloading everything now, renamed primary models to directional models * fix(BetSizing): was running transformations on the wrong data, oops * fix(BetSizing): concatenated on the wrong axis accidentally * fix(Reporting): able to use the new Stats type * fix(BetSizing): renamed int column names * fix(Portfolio): name the column properly * fix(Reporting): rename the correct Series, lol * fix(Inference): walk_forwad_inference() can deal with models not being aligned with the starting index * fix(WalkForward): accidentally using the wrong index * fix(WalkForward): use the correct indicies to fetch last model/transformations * fix(CI): changed the name of the results
This commit is contained in:
committed by
GitHub
parent
42a1bc59cb
commit
3eb3ea94e3
@@ -53,9 +53,7 @@ class EvenOddStubModel(Model):
|
||||
|
||||
def clone(self):
|
||||
return self
|
||||
|
||||
def get_name(self) -> str:
|
||||
return 'test'
|
||||
|
||||
|
||||
def initialize_network(self, input_dim: int, output_dim: int):
|
||||
pass
|
||||
@@ -65,28 +63,28 @@ def test_evaluation():
|
||||
X, y = __generate_even_odd_test_data(no_of_rows)
|
||||
|
||||
window_length = 10
|
||||
retrain_every = 10
|
||||
|
||||
model = EvenOddStubModel(window_length = window_length)
|
||||
|
||||
model_over_time, transformations_over_time = walk_forward_train(
|
||||
model_name='test',
|
||||
model_over_time = walk_forward_train(
|
||||
model=model,
|
||||
X=X,
|
||||
y=y,
|
||||
forward_returns=y,
|
||||
expanding_window=False,
|
||||
window_size=window_length,
|
||||
retrain_every=10,
|
||||
retrain_every=retrain_every,
|
||||
from_index=None,
|
||||
transformations=[],
|
||||
preloaded_transformations=None)
|
||||
transformations_over_time=[])
|
||||
predictions, _ = walk_forward_inference(
|
||||
model_name='test',
|
||||
model_over_time=model_over_time,
|
||||
transformations_over_time=transformations_over_time,
|
||||
transformations_over_time=[],
|
||||
X=X,
|
||||
expanding_window=False,
|
||||
window_size=window_length,
|
||||
retrain_every = retrain_every,
|
||||
from_index=None,
|
||||
)
|
||||
|
||||
@@ -98,7 +96,6 @@ def test_evaluation():
|
||||
processed_predictions_to_match_returns = predictions * 0.1
|
||||
|
||||
result = evaluate_predictions(
|
||||
model_name='test',
|
||||
forward_returns=fake_forward_returns,
|
||||
y_pred=processed_predictions_to_match_returns,
|
||||
y_true=y,
|
||||
|
||||
@@ -11,16 +11,16 @@ def __generate_incremental_test_data(no_of_rows) -> tuple[pd.DataFrame, pd.Serie
|
||||
|
||||
no_columns = 6
|
||||
X = [[row] * no_columns for row in range(no_of_rows)]
|
||||
assert X[0][0] == 0
|
||||
assert X[1][0] == 1
|
||||
assert X[2][0] == 2
|
||||
assert X[3][0] == 3
|
||||
assert X[4][0] == 4
|
||||
X = pd.DataFrame(X)
|
||||
|
||||
y = [row+1 for row in range(no_of_rows)]
|
||||
assert y[0] == 1
|
||||
assert y[1] == 2
|
||||
assert y[2] == 3
|
||||
assert y[3] == 4
|
||||
y = pd.Series(y)
|
||||
|
||||
return X, y
|
||||
@@ -52,9 +52,6 @@ class IncrementingStubModel(Model):
|
||||
|
||||
def clone(self):
|
||||
return self
|
||||
|
||||
def get_name(self) -> str:
|
||||
return 'test'
|
||||
|
||||
def initialize_network(self, input_dim: int, output_dim: int):
|
||||
pass
|
||||
@@ -63,29 +60,29 @@ def test_walk_forward_train_test():
|
||||
X, y = __generate_incremental_test_data(no_of_rows)
|
||||
|
||||
window_length = 10
|
||||
retrain_every = 10
|
||||
|
||||
model = IncrementingStubModel(window_length = window_length)
|
||||
|
||||
model_over_time, transformations_over_time = walk_forward_train(
|
||||
model_name='test',
|
||||
model_over_time = walk_forward_train(
|
||||
model=model,
|
||||
X=X,
|
||||
y=y,
|
||||
forward_returns=y,
|
||||
expanding_window=False,
|
||||
window_size=window_length,
|
||||
retrain_every=10,
|
||||
retrain_every=retrain_every,
|
||||
from_index=None,
|
||||
transformations=[],
|
||||
preloaded_transformations=None
|
||||
transformations_over_time=[],
|
||||
)
|
||||
predictions, _ = walk_forward_inference(
|
||||
model_name='test',
|
||||
model_over_time=model_over_time,
|
||||
transformations_over_time=transformations_over_time,
|
||||
transformations_over_time=[],
|
||||
X=X,
|
||||
expanding_window=False,
|
||||
window_size=window_length,
|
||||
retrain_every=retrain_every,
|
||||
from_index=None,
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user