Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2271 feedback reward custom metrics #2289

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/source/examples/feedback_reward_custom_metrics.nblink
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"path": "../../../examples/feedback/reward-accuracy/README.ipynb"
}
Binary file added doc/source/examples/images/grafana-import.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/source/examples/images/model-perf-comp.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/source/examples/images/realtime-accuracy.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/source/examples/images/single-model.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions doc/source/examples/notebooks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Advanced Machine Learning Insights
.. toctree::
:titlesonly:

Real time monitoring of statistical metrics <feedback_reward_custom_metrics>
Tabular, Text and Image Model Explainers <explainer_examples>
Outlier Detection on CIFAR10 <outlier_cifar10>

Expand Down
1 change: 1 addition & 0 deletions examples/feedback/reward-accuracy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.joblib
42 changes: 42 additions & 0 deletions examples/feedback/reward-accuracy/MetricsModel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import joblib


class Score:
def __init__(self, TP, FP, TN, FN):
self.TP = TP
self.FP = FP
self.TN = TN
self.FN = FN


class MetricsModel:
def __init__(self, model_name="binary-lr.joblib"):
self.scores = Score(0, 0, 0, 0)
self.model = joblib.load(model_name)
self.model_name = model_name.split()[0]

def predict(self, X, features_names=None, meta=None):
return self.model.predict(X)

def send_feedback(self, features, feature_names, reward, truth, routing=""):
predicted = self.predict(features)
print(f"Predicted: {predicted[0]}, Truth: {truth[0]}")
if int(truth[0]) == 1:
if int(predicted[0]) == int(truth[0]):
self.scores.TP += 1
else:
self.scores.FN += 1
else:
if int(predicted[0]) == int(truth[0]):
self.scores.TN += 1
else:
self.scores.FP += 1
return [] # Ignore return statement as its not used

def metrics(self):
return [
{"type": "GAUGE", "key": f"true_pos", "value": self.scores.TP},
{"type": "GAUGE", "key": f"true_neg", "value": self.scores.FN},
{"type": "GAUGE", "key": f"false_pos", "value": self.scores.TN},
{"type": "GAUGE", "key": f"false_neg", "value": self.scores.FP},
]
Loading