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

Handle None case in Confusion matrix merging #163

Merged
merged 2 commits into from
Feb 24, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.3.3-dev0
current_version = 0.3.3-dev1
commit = True
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+)(?P<build>\d+))?
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def setup(app):
# built documents.
#
# The short X.Y version.
version = "0.3.3-dev0"
version = "0.3.3-dev1"
# The full version, including alpha/beta/rc tags.
release = "" # Is set by calling `setup.py docs`

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[metadata]
name = whylogs
version = 0.3.3-dev0
version = 0.3.3-dev1
description = Profile and monitor your ML data pipeline end-to-end
author = WhyLabs.ai
author-email = support@whylabs.ai
Expand Down
2 changes: 1 addition & 1 deletion src/whylogs/_version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""WhyLabs version number."""

__version__ = "0.3.3-dev0"
__version__ = "0.3.3-dev1"
6 changes: 5 additions & 1 deletion src/whylogs/core/metrics/model_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class ModelMetrics:
confusion_matrix (ConfusionMatrix): ConfusionMatrix which keeps it track of counts with NumberTracker
"""

def __init__(self, confusion_matrix: ConfusionMatrix = ConfusionMatrix()):
def __init__(self, confusion_matrix: ConfusionMatrix = None):
if confusion_matrix is None:
confusion_matrix = ConfusionMatrix()
self.confusion_matrix = confusion_matrix

def to_protobuf(self, ) -> ModelMetricsMessage:
Expand Down Expand Up @@ -61,5 +63,7 @@ def merge(self, other):
return self
if other.confusion_matrix is None:
# TODO: return a copy instead
return self
if self.confusion_matrix is None:
return other
return ModelMetrics(confusion_matrix=self.confusion_matrix.merge(other.confusion_matrix))
20 changes: 13 additions & 7 deletions tests/unit/core/metrics/test_model_metrics.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@

import pytest
import numpy as np
from sklearn.utils.multiclass import type_of_target

from whylogs.core.metrics.model_metrics import ModelMetrics


Expand All @@ -26,7 +21,6 @@ def tests_model_metrics():


def tests_model_metrics_to_protobuf():

mod_met = ModelMetrics()

targets_1 = ["cat", "dog", "pig"]
Expand All @@ -39,4 +33,16 @@ def tests_model_metrics_to_protobuf():

message = mod_met.to_protobuf()

read_mod_met = ModelMetrics.from_protobuf(message)
ModelMetrics.from_protobuf(message)


def test_merge_none():
metrics = ModelMetrics()
metrics.merge(None)


def test_merge_metrics_with_none_confusion_matrix():
metrics = ModelMetrics()
other = ModelMetrics()
other.confusion_matrix = None
metrics.merge(other)