mirror of
https://github.com/webclinic017/drift.git
synced 2026-08-09 09:07:49 +00:00
feat(Selection): added toggleable feature selection step into the pipeline (#83)
* feat(Selection): added prototype feature selection python script * feat(Utils): added some helpers for the future from Advances in Financial ML book * feat(Selection): added RFECV * feat(Selection): added configurable feature selection step into pipeline * feat(Config): added level_1 & level_2 default config, PCA before feature selection process starts * feat(Selection): added backup feature selector models if current one can't output feature importance, removed unnecessary array for level-2 models * fix(Training): deal with zero first value coming out of static models * feat(Sweep): added feature selection sweep * fix(Sweep): config problem * fix(Sweep): config * chore(Utils): removed unnecessary purged k-fold crossval class * feat(Config): added dimensionality_reduction as a separate flag * fix(Sweep): config updated * fix(Sweep): sweep name * chore(Config): updated level_2 config to the best performing configuation
This commit is contained in:
committed by
GitHub
parent
a9b05dbd42
commit
cc70d3f907
+2
-1
@@ -6,9 +6,10 @@ class StaticAverageModel(Model):
|
||||
Model that averages .
|
||||
'''
|
||||
|
||||
# data_format = 'dataframe'
|
||||
data_scaling = 'unscaled'
|
||||
only_column = 'model_'
|
||||
feature_selection = 'off'
|
||||
model_type = 'static'
|
||||
|
||||
def fit(self, X, y, prev_model):
|
||||
# This is a static model, it can' learn anything
|
||||
|
||||
+4
-2
@@ -5,10 +5,11 @@ from abc import ABC, abstractmethod, abstractproperty
|
||||
|
||||
class Model(ABC):
|
||||
|
||||
# data_format: Literal['dataframe', 'numpy']
|
||||
data_scaling: Literal["scaled", "unscaled"]
|
||||
feature_selection: Literal["on", "off"]
|
||||
# data_format: Literal["wide", "narrow"]
|
||||
only_column: Optional[str]
|
||||
model_type: Literal['ml', 'static']
|
||||
|
||||
@abstractmethod
|
||||
def fit(self, X, y, prev_model):
|
||||
@@ -25,9 +26,10 @@ class Model(ABC):
|
||||
|
||||
class SKLearnModel(Model):
|
||||
|
||||
# data_format = 'numpy'
|
||||
data_scaling = 'scaled'
|
||||
only_column = None
|
||||
feature_selection = 'on'
|
||||
model_type = 'ml'
|
||||
|
||||
def __init__(self, model):
|
||||
self.model = model
|
||||
|
||||
+7
-5
@@ -22,12 +22,12 @@ model_map = {
|
||||
KNN = SKLearnModel(KNeighborsRegressor(n_neighbors=25)),
|
||||
AB = SKLearnModel(AdaBoostRegressor(random_state=1)),
|
||||
MLP = SKLearnModel(MLPRegressor(hidden_layer_sizes=(100,20), max_iter=1000)),
|
||||
RF = SKLearnModel(RandomForestRegressor(n_jobs=-1, random_state=1)),
|
||||
RF = SKLearnModel(RandomForestRegressor(n_jobs=-1, max_depth=20, random_state=1)),
|
||||
SVR = SKLearnModel(SVR(kernel='rbf', C=1e3, gamma=0.1)),
|
||||
StaticNaive = StaticNaiveModel(),
|
||||
),
|
||||
"classification_models": dict(
|
||||
LR= SKLearnModel(LogisticRegression(C=10, random_state=1, max_iter=1000)),
|
||||
LR= SKLearnModel(LogisticRegression(C=10, random_state=1, max_iter=1000, n_jobs=-1)),
|
||||
LDA= SKLearnModel(LinearDiscriminantAnalysis()),
|
||||
KNN= SKLearnModel(KNeighborsClassifier()),
|
||||
CART= SKLearnModel(DecisionTreeClassifier(max_depth=15, random_state=1)),
|
||||
@@ -42,10 +42,12 @@ model_map = {
|
||||
model_names_classification = list(model_map["classification_models"].keys())
|
||||
model_names_regression = list(model_map["regression_models"].keys())
|
||||
|
||||
default_feature_selector_regression = model_map['regression_models']['RF']
|
||||
default_feature_selector_classification = model_map['classification_models']['RF']
|
||||
|
||||
def map_model_name_to_function(model_config:dict, method:str) -> dict:
|
||||
for level in ['level_1_models', 'level_2_models']:
|
||||
model_category = method + '_models'
|
||||
model_config[level] = [(model_name, model_map[model_category][model_name]) for model_name in model_config[level]]
|
||||
model_config['level_1_models'] = [(model_name, model_map[method + '_models'][model_name]) for model_name in model_config['level_1_models']]
|
||||
if model_config['level_2_model'] is not None:
|
||||
model_config['level_2_model'] = (model_config['level_2_model'], model_map[method + '_models'][model_config['level_2_model']])
|
||||
|
||||
return model_config
|
||||
+2
-1
@@ -6,9 +6,10 @@ class StaticMomentumModel(Model):
|
||||
Model that uses only one feature: momentum. It's positive if momentum is greater than 0, otherwise it's negative.
|
||||
'''
|
||||
|
||||
# data_format = 'dataframe'
|
||||
data_scaling = 'unscaled'
|
||||
only_column = 'mom'
|
||||
feature_selection = 'off'
|
||||
model_type = 'static'
|
||||
|
||||
def __init__(self, allow_short: bool) -> None:
|
||||
super().__init__()
|
||||
|
||||
+2
-1
@@ -6,9 +6,10 @@ class StaticNaiveModel(Model):
|
||||
Model that carries the last observation (from returns) to the next one, naively.
|
||||
'''
|
||||
|
||||
# data_format = 'dataframe'
|
||||
data_scaling = 'unscaled'
|
||||
only_column = None
|
||||
feature_selection = 'off'
|
||||
model_type = 'static'
|
||||
|
||||
def fit(self, X, y, prev_model):
|
||||
# This is a static model, it can' learn anything
|
||||
|
||||
Reference in New Issue
Block a user