-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add regression model, split indicator modules
- Loading branch information
Showing
3 changed files
with
48 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class ZScoreIndicator(RegressionIndicator): | ||
""" | ||
Example regression indicator that uses the Z score as a metric | ||
to determine if the recent test was an outlier | ||
""" | ||
def __init__(self, *args, threshold=3, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.threshold = threshold | ||
|
||
def get_name(self): | ||
return f"ZScoreIndicator(threshold={self.threshold})" | ||
|
||
def regression_test(self, new_result: float, lts_results: np.array) -> RegressionStatus: | ||
""" | ||
Determine if the curr_result is more/less than threshold | ||
standard deviations away from the previous_results | ||
""" | ||
mean = np.mean(lts_results) | ||
std = np.std(lts_results) | ||
z_score = (new_result - mean) / std | ||
|
||
status = 0 | ||
explanation = "z-score not greater than threshold" | ||
details = {"threshold": self.threshold, "zscore": z_score} | ||
if abs(z_score) > self.threshold: | ||
status = 1 | ||
direction = 1 if z_score > 0 else -1, | ||
explanation="z-score greater than threshold", | ||
|
||
return RegressionStatus(0, direction=direction, explanation=explanation, details=details) |