mirror of
https://github.com/webclinic017/drift.git
synced 2026-08-06 15:47:52 +00:00
fix(Reporting): use weighted average (with no_of_samples as weights) and only report level-1 OR level-2 model performance (#91)
* fix(Reporting): use weighted average (with no_of_samples as weights) and only report level-1 OR level-2 model performance * chore(Config): updated sweep config * fix(Reporting): missing import * fix(Evaluation): get_first_valid_return_index can deal with zero valid indexes * fix(Training): increase threshold for skipping assets * fix(DataLoader): target asset should be always the first column
This commit is contained in:
committed by
GitHub
parent
fc4e59a7d2
commit
a9b05dbd42
+19
-2
@@ -3,7 +3,24 @@ import pandas as pd
|
||||
import numpy as np
|
||||
|
||||
def get_first_valid_return_index(series: pd.Series) -> int:
|
||||
return np.where(np.logical_and(series != 0, np.logical_not(np.isnan(series))))[0][0]
|
||||
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]
|
||||
return [item for sublist in list_of_lists for item in sublist]
|
||||
|
||||
def weighted_average(df: pd.DataFrame, weights_source: str) -> pd.DataFrame:
|
||||
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
|
||||
|
||||
|
||||
+3
-2
@@ -35,9 +35,10 @@ def load_data(path: str,
|
||||
- Series `forward_returns` with the target asset returns shifted by 1 day
|
||||
"""
|
||||
|
||||
|
||||
files = [f for f in os.listdir(path) if os.path.isfile(os.path.join(path,f)) and not f.startswith('.')]
|
||||
files = [f for f in files if load_other_assets == True or (load_other_assets == False and f.startswith(target_asset))]
|
||||
target_file = [f for f in files if f.startswith(target_asset)]
|
||||
other_files = [f for f in files if load_other_assets == True and f.startswith(target_asset) == False]
|
||||
files = target_file + other_files
|
||||
def is_target_asset(target_asset: str, file: str): return file.split('.')[0].startswith(target_asset)
|
||||
dfs = [__load_df(
|
||||
path=os.path.join(path,f),
|
||||
|
||||
Reference in New Issue
Block a user