mirror of
https://github.com/webclinic017/drift.git
synced 2026-08-22 07:18:08 +00:00
refactor(Core): small refactor in the pipeline to streamline classification/regression model handling (#60)
This commit is contained in:
+34
-34
@@ -21,41 +21,12 @@ from typing import Tuple
|
|||||||
|
|
||||||
|
|
||||||
def get_config()->Tuple[dict, dict, dict]:
|
def get_config()->Tuple[dict, dict, dict]:
|
||||||
# Parameters
|
|
||||||
model_config = dict(
|
|
||||||
regression_models = [
|
|
||||||
# ('Lasso', Lasso(alpha=0.1, max_iter=1000)),
|
|
||||||
('Ridge', Ridge(alpha=0.1)),
|
|
||||||
('BayesianRidge', BayesianRidge()),
|
|
||||||
# ('KNN', KNeighborsRegressor(n_neighbors=25)),
|
|
||||||
# ('AB', AdaBoostRegressor(random_state=1)),
|
|
||||||
# ('LR', LinearRegression(n_jobs=-1)),
|
|
||||||
# ('MLP', MLPRegressor(hidden_layer_sizes=(100,20), max_iter=1000)),
|
|
||||||
# ('RF', RandomForestRegressor(n_jobs=-1)),
|
|
||||||
# ('SVR', SVR(kernel='rbf', C=1e3, gamma=0.1))
|
|
||||||
],
|
|
||||||
regression_ensemble_model = [('Ensemble - Ridge', Ridge(alpha=0.1))],
|
|
||||||
|
|
||||||
classification_models = [
|
|
||||||
('LR', LogisticRegression(n_jobs=-1)),
|
|
||||||
# ('LDA', LinearDiscriminantAnalysis()),
|
|
||||||
# ('KNN', KNeighborsClassifier()),
|
|
||||||
# ('CART', DecisionTreeClassifier()),
|
|
||||||
# ('NB', GaussianNB()),
|
|
||||||
# ('AB', AdaBoostClassifier()),
|
|
||||||
# ('RF', RandomForestClassifier(n_jobs=-1))
|
|
||||||
],
|
|
||||||
classification_ensemble_model = [('Ensemble - CART', DecisionTreeClassifier())]
|
|
||||||
)
|
|
||||||
|
|
||||||
training_config = dict(
|
training_config = dict(
|
||||||
# path = 'data/',
|
|
||||||
sliding_window_size = 150,
|
sliding_window_size = 150,
|
||||||
retrain_every = 20,
|
retrain_every = 20,
|
||||||
scaler = 'minmax', # 'normalize' 'minmax' 'standardize' 'none'
|
scaler = 'minmax', # 'normalize' 'minmax' 'standardize' 'none'
|
||||||
include_original_data_in_ensemble = True,
|
include_original_data_in_ensemble = True,
|
||||||
# method = 'regression',
|
|
||||||
# forecasting_horizon = 1
|
|
||||||
)
|
)
|
||||||
|
|
||||||
data_config = dict(
|
data_config = dict(
|
||||||
@@ -67,9 +38,38 @@ def get_config()->Tuple[dict, dict, dict]:
|
|||||||
own_features= feature_extractor_presets.date + feature_extractor_presets.level1,
|
own_features= feature_extractor_presets.date + feature_extractor_presets.level1,
|
||||||
other_features= [],
|
other_features= [],
|
||||||
index_column= 'int',
|
index_column= 'int',
|
||||||
method= 'regression',
|
method= 'classification',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
classification_models = [
|
||||||
|
('LR', LogisticRegression(n_jobs=-1)),
|
||||||
|
# ('LDA', LinearDiscriminantAnalysis()),
|
||||||
|
('KNN', KNeighborsClassifier()),
|
||||||
|
# ('CART', DecisionTreeClassifier()),
|
||||||
|
# ('NB', GaussianNB()),
|
||||||
|
# ('AB', AdaBoostClassifier()),
|
||||||
|
# ('RF', RandomForestClassifier(n_jobs=-1))
|
||||||
|
]
|
||||||
|
|
||||||
|
regression_models = [
|
||||||
|
# ('Lasso', Lasso(alpha=0.1, max_iter=1000)),
|
||||||
|
('Ridge', Ridge(alpha=0.1)),
|
||||||
|
('BayesianRidge', BayesianRidge()),
|
||||||
|
# ('KNN', KNeighborsRegressor(n_neighbors=25)),
|
||||||
|
# ('AB', AdaBoostRegressor(random_state=1)),
|
||||||
|
# ('LR', LinearRegression(n_jobs=-1)),
|
||||||
|
# ('MLP', MLPRegressor(hidden_layer_sizes=(100,20), max_iter=1000)),
|
||||||
|
# ('RF', RandomForestRegressor(n_jobs=-1)),
|
||||||
|
# ('SVR', SVR(kernel='rbf', C=1e3, gamma=0.1))
|
||||||
|
]
|
||||||
|
|
||||||
|
regression_ensemble_model = [('Ensemble - Ridge', Ridge(alpha=0.1))]
|
||||||
|
classification_ensemble_model = [('Ensemble - CART', DecisionTreeClassifier())]
|
||||||
|
|
||||||
|
model_config = dict(
|
||||||
|
level_1_models = regression_models if data_config['method'] == 'regression' else classification_models,
|
||||||
|
level_2_model = regression_ensemble_model if data_config['method'] == 'regression' else classification_ensemble_model,
|
||||||
|
)
|
||||||
return model_config, training_config, data_config
|
return model_config, training_config, data_config
|
||||||
|
|
||||||
def launch_wandb(config, sweep=False):
|
def launch_wandb(config, sweep=False):
|
||||||
@@ -86,7 +86,7 @@ def launch_wandb(config, sweep=False):
|
|||||||
return wandb
|
return wandb
|
||||||
|
|
||||||
|
|
||||||
def run_pipeline(with_wandb, sweep):
|
def run_pipeline(with_wandb: bool, sweep: bool):
|
||||||
model_config, training_config, data_config = get_config()
|
model_config, training_config, data_config = get_config()
|
||||||
|
|
||||||
wandb = None
|
wandb = None
|
||||||
@@ -122,7 +122,7 @@ def pipeline(model_config:dict, training_config:dict, data_config:dict, wandb):
|
|||||||
X = X,
|
X = X,
|
||||||
y = y,
|
y = y,
|
||||||
target_returns = target_returns,
|
target_returns = target_returns,
|
||||||
models = model_config['regression_models'] if data_config['method'] == 'regression' else model_config['classification_models'],
|
models = model_config['level_1_models'],
|
||||||
method = data_config['method'],
|
method = data_config['method'],
|
||||||
sliding_window_size = training_config['sliding_window_size'],
|
sliding_window_size = training_config['sliding_window_size'],
|
||||||
retrain_every = training_config['retrain_every'],
|
retrain_every = training_config['retrain_every'],
|
||||||
@@ -142,7 +142,7 @@ def pipeline(model_config:dict, training_config:dict, data_config:dict, wandb):
|
|||||||
X = ensemble_X,
|
X = ensemble_X,
|
||||||
y = y,
|
y = y,
|
||||||
target_returns = target_returns,
|
target_returns = target_returns,
|
||||||
models = model_config['regression_ensemble_model'] if data_config['method'] == 'regression' else model_config['classification_ensemble_model'],
|
models = model_config['level_2_model'],
|
||||||
method = data_config['method'],
|
method = data_config['method'],
|
||||||
sliding_window_size = training_config['sliding_window_size'],
|
sliding_window_size = training_config['sliding_window_size'],
|
||||||
retrain_every = training_config['retrain_every'],
|
retrain_every = training_config['retrain_every'],
|
||||||
@@ -165,4 +165,4 @@ def pipeline(model_config:dict, training_config:dict, data_config:dict, wandb):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
run_pipeline(False, False)
|
run_pipeline(with_wandb = False, sweep = False)
|
||||||
+9
-20
@@ -7,33 +7,22 @@ early_terminate:
|
|||||||
min_iter: 2000
|
min_iter: 2000
|
||||||
metric:
|
metric:
|
||||||
goal: maximize
|
goal: maximize
|
||||||
name: accuracy_test
|
name: sharpe
|
||||||
parameters:
|
parameters:
|
||||||
path : 'data/'
|
path : 'data/'
|
||||||
sliding_window_size:
|
sliding_window_size:
|
||||||
values:
|
values: [50, 90, 130, 160, 180, 280, 380, 500]
|
||||||
- 90
|
|
||||||
- 150
|
|
||||||
- 365
|
|
||||||
- 730
|
|
||||||
distribution: categorical
|
distribution: categorical
|
||||||
retrain_every:
|
retrain_every:
|
||||||
values:
|
values: [7, 14, 30, 60, 100]
|
||||||
- 7
|
scaler:
|
||||||
- 14
|
values: ['minmax', 'normalize', 'minmax', 'standardize', 'none']
|
||||||
- 30
|
include_original_data_in_ensemble:
|
||||||
- 60
|
values: [True, False]
|
||||||
distribution: categorical
|
|
||||||
scaler: 'minmax' # 'normalize' 'minmax' 'standardize' 'none'
|
|
||||||
include_original_data_in_ensemble: True
|
|
||||||
method:
|
method:
|
||||||
values:
|
values: ['classification', 'regression']
|
||||||
- 'classification'
|
|
||||||
- 'regression'
|
|
||||||
distribution: categorical
|
|
||||||
forecasting_horizon:
|
forecasting_horizon:
|
||||||
value: 1
|
values: [1,2,3,4,5,6,7,8,9,10]
|
||||||
distribution: constant
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user