mirror of
https://github.com/webclinic017/drift.git
synced 2026-08-01 21:27:46 +00:00
feat(Core): added the first classification model & the feature necessary (#4)
* feat(Core): added the first classification model & the feature necessary * feat(Models): added basic transformers model
This commit is contained in:
committed by
GitHub
parent
797791d2f4
commit
1d6eed3a94
@@ -65,4 +65,29 @@ def __load_df(path: str, prefix: str, add_features: bool, log_returns: bool, nar
|
||||
def create_target_cum_forward_returns(df: pd.DataFrame, source_column: str, period: int) -> pd.DataFrame:
|
||||
df['target'] = df[source_column].diff(period).shift(-period)
|
||||
df = df.iloc[:-period]
|
||||
return df
|
||||
|
||||
|
||||
#%%
|
||||
def create_target_pos_neg_classes(df: pd.DataFrame, source_column: str, period: int) -> pd.DataFrame:
|
||||
df['target'] = df[source_column].diff(period).shift(-period)
|
||||
df['target'] = df['target'].map(lambda x: 0 if x <= 0.0 else 1)
|
||||
df = df.iloc[:-period]
|
||||
return df
|
||||
|
||||
def create_target_four_classes(df: pd.DataFrame, source_column: str, period: int) -> pd.DataFrame:
|
||||
def __get_class(x):
|
||||
treshold = 0.08
|
||||
if x <= -treshold:
|
||||
return 0
|
||||
elif x > -treshold and x <= 0:
|
||||
return 1
|
||||
elif x > 0 and x <= treshold:
|
||||
return 2
|
||||
else:
|
||||
return 3
|
||||
|
||||
df['target'] = df[source_column].diff(period).shift(-period)
|
||||
df['target'] = df['target'].map(__get_class)
|
||||
df = df.iloc[:-period]
|
||||
return df
|
||||
Reference in New Issue
Block a user