Skip to content

Commit

Permalink
Merge 9277db0 into 622d6e5
Browse files Browse the repository at this point in the history
  • Loading branch information
lalmei committed Apr 7, 2021
2 parents 622d6e5 + 9277db0 commit 6149a9a
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 21 deletions.
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.4.4-dev0
current_version = 0.4.5-dev0
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 @@ -101,7 +101,7 @@
# built documents.
#
# The short X.Y version.
version = "0.4.4-dev0"
version = "0.4.5-dev0"
# 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.4.4-dev0
version = 0.4.5-dev0
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.4.4-dev0"
__version__ = "0.4.5-dev0"
21 changes: 11 additions & 10 deletions src/whylogs/core/metrics/model_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,21 @@ def merge(self, other):
"""
if other is None:
return self
if other.confusion_matrix is None and other.regression_metrics is None:
# TODO: return a copy instead
return self
if self.confusion_matrix is None and self.regression_metrics is None:
return other

if self.model_type is None or other.model_type is None:
model_type = ModelType.UNKNOWN
elif other.model_type != self.model_type:
model_type = ModelType.UNKNOWN
model_type = ModelType.UNKNOWN

if (self.model_type not in (ModelType.REGRESSION, ModelType.CLASSIFICATION)):
if other.model_type in (ModelType.REGRESSION, ModelType.CLASSIFICATION):
model_type = other.model_type

elif other.model_type not in (ModelType.REGRESSION, ModelType.CLASSIFICATION):
if self.model_type in (ModelType.REGRESSION, ModelType.CLASSIFICATION):
model_type = self.model_type
else:
model_type = self.model_type

return ModelMetrics(
confusion_matrix=self.confusion_matrix.merge(other.confusion_matrix) if self.confusion_matrix else None,
regression_metrics=self.regression_metrics.merge(other.regression_metrics)if self.regression_metrics else None,
regression_metrics=self.regression_metrics.merge(
other.regression_metrics)if self.regression_metrics else None,
model_type=model_type)
2 changes: 2 additions & 0 deletions src/whylogs/core/metrics/regression_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ def merge(self, other):
Returns:
RegressionMetrics: merged regression metrics
"""
if other is None:
return self

if self.count == 0:
return other
Expand Down
65 changes: 58 additions & 7 deletions tests/unit/core/metrics/test_model_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def tests_model_metrics():
jdx].floats.count == expected_1[idx][jdx]


def tests_model_metrics_to_protobuf():
def tests_model_metrics_to_protobuf_classification():
mod_met = ModelMetrics(model_type=ModelType.CLASSIFICATION)

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

message = mod_met.to_protobuf()

ModelMetrics.from_protobuf(message)
model_metrics = ModelMetrics.from_protobuf(message)
assert model_metrics.model_type == ModelType.CLASSIFICATION
assert model_metrics.confusion_matrix.labels == ["cat", "dog", "pig"]


def tests_no_metrics_to_protobuf_classification():
mod_met = ModelMetrics(model_type=ModelType.CLASSIFICATION)

assert mod_met.model_type == ModelType.CLASSIFICATION
message = mod_met.to_protobuf()

model_metrics = ModelMetrics.from_protobuf(message)
assert model_metrics.model_type == ModelType.CLASSIFICATION

def tests_no_metrics_to_protobuf_regression():

mod_met = ModelMetrics(model_type=ModelType.REGRESSION)
assert mod_met.model_type == ModelType.REGRESSION
message = mod_met.to_protobuf()


model_metrics = ModelMetrics.from_protobuf(message)
assert model_metrics.model_type == ModelType.REGRESSION

def tests_model_metrics_to_protobuf_regression():
regression_model = ModelMetrics(model_type=ModelType.REGRESSION)

targets_1 = [0.1, 0.3, 0.4]
predictions_1 = [0.5, 0.5, 0.5]
regression_model.compute_regression_metrics(predictions_1, targets_1)
regression_message = regression_model.to_protobuf()
model_metrics_from_message = ModelMetrics.from_protobuf(regression_message)
assert model_metrics_from_message.model_type == ModelType.REGRESSION



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


def test_merge_metrics_with_none_confusion_matrix():
Expand All @@ -54,11 +87,28 @@ def test_merge_metrics_with_none_confusion_matrix():
new_metrics = metrics.merge(other)


def test_merge_metrics_model():
metrics = ModelMetrics()
other = ModelMetrics(model_type=ModelType.REGRESSION)
other.regression_metrics = None
new_metrics = metrics.merge(other)
assert new_metrics.model_type==ModelType.REGRESSION
assert new_metrics.confusion_matrix is None

# keep initial model type during merge
metrics = ModelMetrics(model_type=ModelType.REGRESSION)
other = ModelMetrics(model_type=ModelType.CLASSIFICATION)
other.regression_metrics = None
new_metrics = metrics.merge(other)
assert new_metrics.model_type==ModelType.REGRESSION
assert new_metrics.confusion_matrix is None

def test_merge_metrics_with_none_regression_matrix():
metrics = ModelMetrics()
other = ModelMetrics()
other = ModelMetrics(model_type=ModelType.REGRESSION)
other.regression_metrics = None
new_metrics= metrics.merge(other)
new_metrics = metrics.merge(other)
assert new_metrics.model_type==ModelType.REGRESSION

def test_merge_metrics_with_none_confusion_matrix():
metrics = ModelMetrics()
Expand All @@ -67,10 +117,11 @@ def test_merge_metrics_with_none_confusion_matrix():
other.regression_metrics = None

new_metrics = metrics.merge(other)
assert new_metrics.model_type == ModelType.UNKNOWN


def test_model_metrics_init():
reg_met = RegressionMetrics()
conf_ma= ConfusionMatrix()
conf_ma = ConfusionMatrix()
with pytest.raises(NotImplementedError):
metrics = ModelMetrics(confusion_matrix=conf_ma, regression_metrics=reg_met)

0 comments on commit 6149a9a

Please sign in to comment.