-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Fix #599: - Make Aimodel do classification (not regression), where classifier outputs probabilities of up vs down - In sim_engine predictoor: model two-sided prediction - In sim_engine trader: use up/down confidence level to decide amt of $ to put in - In sim_engine trader: sell when predict down, then buy back - In sim_engine: add contour plots to visualize models, when 2 input vars (and hide plot when not 2 vars) - In predictoor_agent approach 1: stake up/down as 50/50 - In predictoor_agent approach 3: stake up=prob_up*stake_amt, down=(1-prob_up)*stake_amt - rename predictoor approach 3 --> approach 2 - predictoor.md README updated
- Loading branch information
Showing
43 changed files
with
1,412 additions
and
1,087 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
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,49 @@ | ||
from typing import Tuple | ||
|
||
from enforce_typing import enforce_types | ||
import numpy as np | ||
|
||
|
||
@enforce_types | ||
class Aimodel: | ||
|
||
def __init__(self, skm, scaler): | ||
self._skm = skm # sklearn model | ||
self._scaler = scaler | ||
|
||
def predict_true(self, X): | ||
""" | ||
@description | ||
Classify each input sample, with lower fidelity: just True vs False | ||
@arguments | ||
X -- 2d array of [sample_i, var_i]:cont_value -- model inputs | ||
@return | ||
ytrue -- 1d array of [sample_i]:bool_value -- classifier model outputs | ||
""" | ||
# We explicitly don't call skm.predict() here, because it's | ||
# inconsistent with predict_proba() for svc and maybe others. | ||
# Rather, draw on the probability output to guarantee consistency. | ||
yptrue = self.predict_ptrue(X) | ||
print(f"in predict_true(); yptrue[:10] = {yptrue[:10]}") | ||
ytrue = yptrue > 0.5 | ||
return ytrue | ||
|
||
def predict_ptrue(self, X: np.ndarray) -> np.ndarray: | ||
""" | ||
@description | ||
Classify each input sample, with higher fidelity: prob of being True | ||
@arguments | ||
X -- 2d array of [sample_i, var_i]:cont_value -- model inputs | ||
@return | ||
yptrue - 1d array of [sample_i]: prob_of_being_true -- model outputs | ||
""" | ||
X = self._scaler.transform(X) | ||
T = self._skm.predict_proba(X) # [sample_i][class_i] | ||
N = T.shape[0] | ||
class_i = 1 # this is the class for "True" | ||
yptrue = np.array([T[i, class_i] for i in range(N)]) | ||
return yptrue |
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
Oops, something went wrong.