Files
drift/data_loader/process_data.py
T
Daniel Szemerey 31dc847be1 Feature(Speed): Python launches faster by conditionally importing models. (#169)
* feat: Added optional import of models.

* fix: Models weren't wrapped into abstract class, fixed it.

* chore: Deleted leftover comments.

* fix: Same merge commit as on remote.

* fix: System wasn't putting in RF because there was no differentiation between RF as regressor and RF as classificator.

* fix(Models): use the XGBoostModel wrapper

Co-authored-by: Daniel Szemerey <szemereydaniel@gmail.com>
Co-authored-by: Mark Aron Szulyovszky <mark.szulyovszky@gmail.com>
2022-01-14 14:29:24 +01:00

36 lines
1.4 KiB
Python

import pandas as pd
from operator import itemgetter
from utils.helpers import has_enough_samples_to_train
from feature_selection.dim_reduction import reduce_dimensionality
from models.model_map import get_model_map
from feature_selection.feature_selection import select_features
import warnings
def process_data(X:pd.DataFrame, y:pd.Series, configs: dict) -> tuple[pd.DataFrame,pd.DataFrame]:
model_config, training_config, data_config = itemgetter('model_config', 'training_config', 'data_config')(configs)
_, _, _, default_feature_selector_regression, default_feature_selector_classification = get_model_map(model_config)
original_X = X.copy()
# 2b. Feature Selection
print("Feature Selection started")
# TODO: this needs to be done per model!
backup_model = default_feature_selector_regression if data_config['method'] == 'regression' else default_feature_selector_classification
X = select_features(X = X, y = y, model = model_config['primary_models'][0][1], n_features_to_select = training_config['n_features_to_select'], backup_model = backup_model, scaling = training_config['scaler'])
return X, original_X
def check_data(X:pd.DataFrame, y:pd.Series, training_config:dict):
""" Returns True if data is valid, else returns False."""
if has_enough_samples_to_train(X, y, training_config) == False:
warnings.warn("Not enough samples to train")
return False
return True