Skip to content

Commit c8130ba

Browse files
committed
add helper for metric
1 parent 5852eeb commit c8130ba

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

dataikuapi/dss/ml.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,22 @@ def set_algorithm_enabled(self, algorithm_name, enabled):
214214
"""
215215
self.get_algorithm_settings(algorithm_name)["enabled"] = enabled
216216

217+
def set_metric(self, metric=None, custom_metric=None, custom_metric_greater_is_better=True, custom_metric_use_probas=False):
218+
"""
219+
Set a metric on a prediction ML task
220+
221+
:param str metric: metric to use. Leave empty for custom_metric
222+
:param str custom_metric: code of the custom metric
223+
:param bool custom_metric_greater_is_better: whether the custom metric is a score or a loss
224+
:param bool custom_metric_use_probas: whether to use the classes' probas or the predicted value (for classification)
225+
"""
226+
if custom_metric is None and metric is None:
227+
raise ValueError("Either metric or custom_metric must be defined")
228+
self.mltask_settings["modeling"]["metrics"]["evaluationMetric"] = metric if custom_metric is None else 'CUSTOM'
229+
self.mltask_settings["modeling"]["metrics"]["customEvaluationMetricCode"] = custom_metric
230+
self.mltask_settings["modeling"]["metrics"]["customEvaluationMetricGIB"] = custom_metric_greater_is_better
231+
self.mltask_settings["modeling"]["metrics"]["customEvaluationMetricNeedsProba"] = custom_metric_use_probas
232+
217233
def save(self):
218234
"""Saves back these settings to the ML Task"""
219235

0 commit comments

Comments
 (0)