Skip to content
Merged
Changes from 5 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
e3586ca
Add assertions settings public api methods
Dec 2, 2020
067a9a5
Fix typo
Dec 2, 2020
7013c5f
Add assertion results methods
Dec 2, 2020
4d599c5
Clean up
Dec 3, 2020
e276feb
Clean up
Dec 3, 2020
ab5f5dc
Clean up
Dec 3, 2020
190676c
Wording
Dec 4, 2020
fe84039
Clarify expected_valid_ratio parameter docstring
Dec 4, 2020
da7a645
Wording
Dec 4, 2020
7b56a08
Simplify exception message
Dec 4, 2020
4bfcf0d
Clarify exception message
Dec 4, 2020
537cd67
Wording
Dec 4, 2020
15343ea
Remove checks for assertion names uniqueness and reanme param to para…
Dec 7, 2020
5d2ab2d
Fix typo
Dec 7, 2020
56ae941
Remove leftover check
Dec 7, 2020
6604136
Rename create_from_* methods to from_*
Dec 7, 2020
86a7c9a
Change expected_range to expected_min and expected_max
Dec 7, 2020
7aeafa2
Wording
Dec 7, 2020
c740435
Rename functions and clean up
Dec 7, 2020
314cbd2
Fix some wording and indent
Dec 8, 2020
0a5d7c6
Clean up
Dec 8, 2020
852eb31
Clean up
Dec 8, 2020
1d541a3
Clean up
Dec 8, 2020
0f883c5
Update variables names after dip variables renaming
Dec 11, 2020
39981e9
Rename from_parts to from_params and fix return types
Dec 14, 2020
62a47bd
Add repr to conditon and assertionParam
Dec 14, 2020
be2dbd2
Add repr to assertionMetrics
Dec 14, 2020
7942ac6
Unify class references
Dec 14, 2020
5c79555
Unify method references
Dec 14, 2020
a04634f
Add blank lines before :param
Dec 16, 2020
cc2b382
Add blank lines before :rtype when no other keyword
Dec 16, 2020
0599c60
Remove breaklines in reprs
Dec 16, 2020
c8f3679
Change metric to metrics
Dec 16, 2020
e020979
Replace access to internal dict by get raw
Dec 16, 2020
8317ada
Add two missing reprs and fix one
Dec 16, 2020
591d6aa
Add comment to help build condition filter
Dec 16, 2020
b10aa6f
Fix typos
Dec 16, 2020
75a755e
Add get_assertions_names
Dec 16, 2020
339cbc9
Fix typo
Dec 16, 2020
c655c56
Unify reprs
Dec 16, 2020
018bed2
Wording
Dec 16, 2020
f2a1886
Nitpicks
Dec 18, 2020
5eecb22
Add forgotten :meth:
Dec 18, 2020
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
108 changes: 52 additions & 56 deletions dataikuapi/dss/ml.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,15 +431,6 @@ def get_split_params(self):
"""
return PredictionSplitParamsHandler(self.mltask_settings)

@property
def assertions_params(self):
"""
Retrieves the assertions parameters for this ml task

:rtype: :class:`dataikuapi.dss.ml.DSSMLAssertionsParams`
"""
return self.get_assertions_params()

def get_assertions_params(self):
"""
Retrieves the assertions parameters for this ml task
Expand Down Expand Up @@ -696,7 +687,6 @@ def add_assertion(self, assertion_params):
"""
if not isinstance(assertion_params, DSSMLAssertionParams):
raise ValueError('Wrong type for assertion parameters: {}'.format(type(assertion_params)))
self.check_assertion_names_are_uniq(self._internal_dict["assertions"] + [assertion_params._internal_dict])

self._internal_dict["assertions"].append(assertion_params._internal_dict)

Expand All @@ -717,13 +707,13 @@ class DSSMLAssertionParams(object):
"""
Object that represents parameters for one assertion
Do not create this object directly, use :meth:`dataikuapi.dss.ml.DSSMLAssertionsParams.get_assertion(assertion_name)` or
`create_from_parts(name, a_filter, condition)` instead
`from_parts(name, a_filter, condition)` instead
"""
def __init__(self, data):
self._internal_dict = data

@staticmethod
def create_from_parts(name, a_filter, condition):
def from_parts(name, a_filter, condition):
"""
Creates assertion parameters from name, filter and condition

Expand Down Expand Up @@ -788,19 +778,19 @@ def condition(self, condition):
class DSSMLAssertionCondition(object):
"""
Object that represents an assertion condition
Do not create this object directly, use :meth:`dataikuapi.dss.ml.DSSMLAssertionParams.condition`, :meth:`dataikuapi.dss.ml.DSSMLAssertionCondition.create_from_expected_class(expected_valid_ratio, expected_class)`
or :meth:`dataikuapi.dss.ml.DSSMLAssertionCondition.create_from_expected_range(expected_valid_ratio, expected_range)` instead
Do not create this object directly, use :meth:`dataikuapi.dss.ml.DSSMLAssertionParams.condition`, :meth:`dataikuapi.dss.ml.DSSMLAssertionCondition.from_expected_class(expected_valid_ratio, expected_class)`
or :meth:`dataikuapi.dss.ml.DSSMLAssertionCondition.from_expected_range(expected_valid_ratio, expected_min, expected_max)` instead
"""
def __init__(self, data):
self._internal_dict = data

@staticmethod
def create_from_expected_class(expected_valid_ratio, expected_class):
def from_expected_class(expected_valid_ratio, expected_class):
"""
Creates an assertion condition from the expected valid ratio and class

:param float expected_valid_ratio: Ratio of valid rows needed for the assertion to pass
:param str expected_class: Class on which the `expected_valid_ratio` will be calculated
:param float expected_valid_ratio: Assertion passes if this ratio of rows predicted as expected_class is attained
:param str expected_class: Assertion passes if the ratio of rows predicted as expected_class is attained

:rtype: :class:`dataikuapi.dss.ml.DSSMLAssertionCondition`
"""
Expand All @@ -810,19 +800,22 @@ def create_from_expected_class(expected_valid_ratio, expected_class):
return assertion_condition

@staticmethod
def create_from_expected_range(expected_valid_ratio, expected_range):
def from_expected_range(expected_valid_ratio, expected_min, expected_max):
"""
Creates an assertion condition from an expected valid ratio and an expected range
Creates an assertion condition from expected valid ratio and range. The expected range is the
interval between expected_min and expected_max where the predictions and therefore the rows will be considered
valid.

:param float expected_valid_ratio: Assertion passes if this ratio of rows predicted between expected_min and expected_max is attained
:param tuple(float,float) expected_range: Range of values (min, max) where the prediction will be considered as
valid for the `expected_valid_ratio`
:param float expected_min: Min value of the expected range
:param float expected_max: Max value of the expected range

:rtype: :class:`dataikuapi.dss.ml.DSSMLAssertionCondition`
"""
assertion_condition = DSSMLAssertionCondition({})
assertion_condition.expected_valid_ratio = expected_valid_ratio
assertion_condition.expected_range = expected_range
assertion_condition.expected_min = expected_min
assertion_condition.expected_max = expected_max
return assertion_condition

def get_raw(self):
Expand All @@ -835,7 +828,8 @@ def get_raw(self):
@property
def expected_class(self):
"""
Returns the expected class on which the valid ratio will be calculated
Returns the expected class or None if it is not defined. Assertion passes if the ratio of rows predicted
as expected_class is attained
:rtype: str
"""
if "expectedClass" in self._internal_dict:
Expand All @@ -845,14 +839,13 @@ def expected_class(self):

@expected_class.setter
def expected_class(self, expected_class):
if self.expected_range is not None:
raise ValueError("Expected class and expected range can't be both set")
self._internal_dict["expectedClass"] = expected_class

@property
def expected_valid_ratio(self):
"""
Returns the ratio of valid rows to exceed for the assertion to pass
Returns the ratio of valid rows to exceed for the assertion to pass. A row is considered valid if the prediction
is equal to the `expected_class` for classification or in the expected range for regresion
:rtype: str
"""
return self._internal_dict["successRatio"]
Expand All @@ -862,32 +855,42 @@ def expected_valid_ratio(self, expected_valid_ratio):
self._internal_dict["successRatio"] = expected_valid_ratio

@property
def expected_range(self):
def expected_min(self):
"""
Returns the min (included) of the expected range or None if it is not defined. Assertion passes if the ratio of rows predicted
between expected_min and expected_max is attained
:rtype: float
"""
if "expectedMinValue" in self._internal_dict:
return self._internal_dict["expectedMinValue"]
else:
return None

@expected_min.setter
def expected_min(self, expected_min):
self._internal_dict["expectedMinValue"] = expected_min

@property
def expected_max(self):
"""
Returns the expected range on which the valid ratio will be calculated
:rtype: tuple(float,float)
Returns the max (included) of the expected range or None if it is not defined. Assertion passes if the ratio of rows predicted
between expected_min and expected_max is attained
:rtype: float
"""
if "expectedMinValue" in self._internal_dict and "expectedMaxValue" in self._internal_dict:
return self._internal_dict["expectedMinValue"], self._internal_dict["expectedMaxValue"]
if "expectedMaxValue" in self._internal_dict:
return self._internal_dict["expectedMaxValue"]
else:
return None

@expected_range.setter
def expected_range(self, expected_range):
if not isinstance(expected_range, tuple):
raise ValueError("Expected range needs to be a tuple")
if self.expected_class is not None:
raise ValueError("Expected class and expected range can't be both set")
if expected_range[0] > expected_range:
raise ValueError("Expected range needs to be sorted in ascending order. (min value, max value)")
self._internal_dict["expectedMinValue"] = expected_range[0]
self._internal_dict["expectedMaxValue"] = expected_range[1]
@expected_max.setter
def expected_max(self, expected_max):
self._internal_dict["expectedMaxValue"] = expected_max


class DSSMLAssertionsMetrics(object):
"""
Object that represents the per assertion metrics for all assertions on a trained model
Do not create this object directly, use :meth:`dataikuapi.dss.ml.DSSTrainedPredictionModelDetails.get_per_assertion_metrics()` instead
Do not create this object directly, use :meth:`dataikuapi.dss.ml.DSSTrainedPredictionModelDetails.get_assertions_metrics()` instead
"""
def __init__(self, data):
self._internal_dict = data
Expand All @@ -899,13 +902,14 @@ def get_raw(self):
"""
return self._internal_dict

def get_per_assertion_metric(self, assertion_name):
def get_metric(self, assertion_name):
"""
Retrieves the metric computed for this trained model for the assertion with the provided name (or None)
Retrieves the metric computed for this trained model for the assertion with the provided name (or None if no
assertion with that name exists)

:param str assertion_name: Name of the assertion

:returns: an object representing assertion metrics
:returns: an object representing assertion metrics or None if if no assertion with that name exists
:rtype: :class:`dataikuapi.dss.ml.DSSMLAssertionMetric`
"""
for assertion_metric_dict in self._internal_dict["perAssertion"]:
Expand All @@ -925,7 +929,7 @@ def positive_assertion_ratio(self):
class DSSMLAssertionMetric(object):
"""
Object that represents the result of an assertion on a trained model
Do not create this object directly, use :meth:`dataikuapi.dss.ml.DSSMLPerAssertionMetrics.get_assertion_metric(self, assertion_name)` instead
Do not create this object directly, use :meth:`dataikuapi.dss.ml.DSSMLAssertionMetrics.get_metric(self, assertion_name)` instead
"""
def __init__(self, data):
self._internal_dict = data
Expand Down Expand Up @@ -956,7 +960,8 @@ def result(self):
@property
def valid_ratio(self):
"""
Returns the ratio of passing rows in the assertion population
Returns the ratio of rows in the assertion population with prediction equals to the expected class
for classification or in the expected range for regression
:rtype: float
"""
return self._internal_dict["validRatio"]
Expand Down Expand Up @@ -1136,15 +1141,6 @@ def get_performance_metrics(self):
del clean_snippet[x]
return clean_snippet

@property
def assertions_metrics(self):
"""
Retrieves assertions metrics computed for this trained model
:returns: an object representing assertion metrics
:rtype: :class:`dataikuapi.dss.ml.DSSMLAssertionsMetrics`
"""
return self.get_assertions_metrics()

def get_assertions_metrics(self):
"""
Retrieves assertions metrics computed for this trained model
Expand Down