Files
drift/utils/helpers.py
T
Mark Aron Szulyovszky cc70d3f907 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
2021-12-27 21:59:22 +01:00

29 lines
875 B
Python

from typing import Literal
import pandas as pd
import numpy as np
def get_first_valid_return_index(series: pd.Series) -> int:
double_nested_results = np.where(np.logical_and(series != 0, np.logical_not(np.isnan(series))))
if len(double_nested_results) == 0:
return 0
nested_result = double_nested_results[0]
if len(nested_result) == 0:
return 0
return nested_result[0]
def flatten(list_of_lists: list) -> list:
return [item for sublist in list_of_lists for item in sublist]
def weighted_average(df: pd.DataFrame, weights_source: str) -> pd.DataFrame:
if df.shape[0] == 0:
return df
mean_df = df.iloc[:,0]
weights = df.loc[weights_source]
for i, row in df.iterrows():
if i == weights_source: continue
mean_df.loc[i] = (row * weights).sum() / df.loc[weights_source].sum()
return mean_df