mirror of
https://github.com/webclinic017/drift.git
synced 2026-08-19 05:48:09 +00:00
refactor(Evaluate): print out accuracy, f1, etc. for the final & meta predictions, separated out evaluation step (#228)
* refactor(Evaluate): print out accuracy, f1, etc. for the final & meta predictions, separated out evaluation step * fix(Linter): ran * fix(Tests): syntax change * fix(Inference): runs now again * fix(Linter): ran
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import pandas as pd
|
||||
from data_loader.types import ForwardReturnSeries
|
||||
from labeling.types import EventsDataFrame
|
||||
from typing import Callable
|
||||
import numpy as np
|
||||
|
||||
|
||||
def create_forward_returns(series: pd.Series, period: int) -> ForwardReturnSeries:
|
||||
@@ -22,3 +24,31 @@ def purge_overlapping_events(events: EventsDataFrame) -> EventsDataFrame:
|
||||
last_event_end = row["end"]
|
||||
events.drop(indicies_to_remove, inplace=True)
|
||||
return events
|
||||
|
||||
|
||||
def discretize_binary(x):
|
||||
return 1 if x > 0 else -1
|
||||
|
||||
|
||||
def discretize_binary_zero_one(x):
|
||||
return 1 if x > 0 else 0
|
||||
|
||||
|
||||
def discretize_threeway(x):
|
||||
return 0 if x == 0 else 1 if x > 0 else -1
|
||||
|
||||
|
||||
def discretize_threeway_threshold(threshold: float) -> Callable:
|
||||
def discretize(current_value):
|
||||
lower_threshold = -threshold
|
||||
upper_threshold = threshold
|
||||
if np.isnan(current_value):
|
||||
return np.nan
|
||||
elif current_value <= lower_threshold:
|
||||
return -1
|
||||
elif current_value > lower_threshold and current_value < upper_threshold:
|
||||
return 0
|
||||
else:
|
||||
return 1
|
||||
|
||||
return discretize
|
||||
|
||||
Reference in New Issue
Block a user