From 2d87b5a0980e478203fc4fee0a9bed2d44b9c2eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Bourhis?= Date: Tue, 5 Oct 2021 18:29:21 +0200 Subject: [PATCH 01/11] Rename get_full_info to get_evaluation_full_info Add getters for properties of DSSModelEvaluationFullInfo Document data drift parameters and results --- dataikuapi/dss/modelevaluationstore.py | 434 ++++++++++++++++++++++++- 1 file changed, 426 insertions(+), 8 deletions(-) diff --git a/dataikuapi/dss/modelevaluationstore.py b/dataikuapi/dss/modelevaluationstore.py index 4d2d2900..f0f2ae3e 100644 --- a/dataikuapi/dss/modelevaluationstore.py +++ b/dataikuapi/dss/modelevaluationstore.py @@ -5,8 +5,6 @@ from .discussion import DSSObjectDiscussions from .future import DSSFuture -from requests import utils - try: basestring except NameError: @@ -271,9 +269,11 @@ def __init__(self, model_evaluation_store, run_id): self.project_key = model_evaluation_store.project_key self.mes_id = model_evaluation_store.mes_id - def get_full_info(self): + def get_evaluation_full_info(self): """ Retrieve the model evaluation with its performance data + + :return: the model evaluation full info, as a :class:`dataikuapi.dss.DSSModelEvaluationInfo` """ data = self.client._perform_json( "GET", "/projects/%s/modelevaluationstores/%s/runs/%s" % (self.project_key, self.mes_id, self.run_id)) @@ -301,21 +301,25 @@ def compute_data_drift(self, reference=None, data_drift_params=None, wait=True): :param reference: saved model version (full ID or DSSTrainedPredictionModelDetails) or model evaluation (full ID or DSSModelEvaluation) to use as reference (optional) :type reference: Union[str, DSSModelEvaluation, DSSTrainedPredictionModelDetails] - :param data_drift_params: data drift computation settings (optional) + :param data_drift_params: data drift computation settings as a :class:`dataikuapi.dss.modelevaluationstore.DataDriftParams` (optional) + :type data_drift_params: DataDriftParams :param wait: data drift computation settings (optional) - :returns: a `dict` containing data drift analysis results if `wait` is `True`, or a :class:`~dataikuapi.dss.future.DSSFuture` handle otherwise + :returns: a :class:`dataikuapi.dss.modelevaluationstore.DataDriftResult` containing data drift analysis results if `wait` is `True`, or a :class:`~dataikuapi.dss.future.DSSFuture` handle otherwise """ if hasattr(reference, 'full_id'): reference = reference.full_id + if data_drift_params: + data_drift_params = data_drift_params.data + future_response = self.client._perform_json( "POST", "/projects/%s/modelevaluationstores/%s/runs/%s/computeDataDrift" % (self.project_key, self.mes_id, self.run_id), body={ "referenceId": reference, "dataDriftParams": data_drift_params }) - future = DSSFuture(self.client, future_response.get('jobId', None), future_response) + future = DSSFuture(self.client, future_response.get('jobId', None), future_response, result_wrapper=DataDriftResult) return future.wait_for_result() if wait else future def get_metrics(self): @@ -356,7 +360,7 @@ class DSSModelEvaluationFullInfo: Includes information such as the full id of the evaluated model, the evaluation params, the performance and drift metrics, if any, etc. - Do not create this class directly, instead use :meth:`dataikuapi.dss.DSSModelEvaluation.get_full_info` + Do not create this class directly, instead use :meth:`dataikuapi.dss.DSSModelEvaluation.get_evaluation_full_info` """ def __init__(self, model_evaluation, full_info): self.model_evaluation = model_evaluation @@ -396,4 +400,418 @@ def get_creation_date(self): :return: the date and time, as an epoch """ - return self.full_info["evaluation"]["created"] \ No newline at end of file + return self.full_info["evaluation"]["created"] + + def get_full_id(self): + """ + Returns the full id of the Model Evaluation. + + :return: the full id, as a string + """ + return self.full_info["evaluation"]["ref"]["fullId"] + + def get_model_full_id(self): + """ + Returns the full id of the evaluated model. + + :return: the model full id, as a string + """ + return self.full_info["evaluation"]["modelRef"]["fullId"] + + def get_model_type(self): + """ + Returns the evaluated model type. + + :return: the model type, as a string + """ + return self.full_info["evaluation"]["modelType"] + + def get_model_parameters(self): + """ + Returns the evaluated model params. + + :return: the model params, as a dict + """ + return self.full_info["evaluation"]["modelParams"] + + def get_prediction_type(self): + """ + Returns the prediction type of the evaluated model. + + :return: the prediction type, as a string + """ + return self.full_info["evaluation"]["predictionType"] + + def get_prediction_variable(self): + """ + Returns the prediction variable used for evaluation. + + :return: the prediction variable, as a string + """ + return self.full_info["evaluation"]["predictionVariable"] + + def get_target_variable(self): + """ + Returns the target variable used for evaluation. + + :return: the target variable, as a string + """ + return self.full_info["evaluation"]["targetVariable"] + + +class DataDriftParams(object): + """ + Object that represents parameters for data drift computation. + Do not create this object directly, use :meth:`dataikuapi.dss.modelevaluationstore.DataDriftParams.from_params` instead. + """ + def __init__(self, data): + self.data = data + + def __repr__(self): + return u"{}({})".format(self.__class__.__name__, self.data) + + @staticmethod + def from_params(columns, nb_bins=10, compute_histograms=True, confidence_level=0.95): + """ + Creates parameters for data drift computation from columns, number of bins, compute histograms and confidence level + + :param dict columns: A dict representing the per column settings. + You should use a :class:`~dataikuapi.dss.modelevaluationstore.PerColumnDriftParamBuilder` to build it. + :param int nb_bins: (optional) Nb. bins in histograms (apply to all columns) - default: 10 + :param bool compute_histograms: (optional) Enable/disable histograms - default: True + :param float confidence_level: (optional) Used to compute confidence interval on drift's model accuracy - default: 0.95 + + :rtype: :class:`dataikuapi.dss.modelevaluationstore.DataDriftParams` + """ + return DataDriftParams({ + "columns": columns, + "nbBins": nb_bins, + "computeHistograms": compute_histograms, + "confidenceLevel": confidence_level + }) + + +class PerColumnDriftParamBuilder(object): + """ + Builder for a map of per column drift params settings. + Used as a helper before computing data drift to build columns param expected in dataikuapi.dss.modelevaluationstore.DataDriftParams.from_params. + """ + def __init__(self): + self.columns = {} + + def build(self): + """Returns the built dict for per column drift params settings""" + return self.columns + + def with_column_drift_param(self, name, handling="AUTO", enabled=False): + """ + Sets the drift params settings for given column name. + + :param: string name: The name of the column + :param: string handling: (optional) The column type, should be either NUMERICAL, CATEGORICAL or AUTO (default: AUTO) + :param: bool name: (optional) If the column should be enabled (default: False) + """ + self.columns[name] = { + "handling": handling, + "enabled": enabled + } + return self + + +class DataDriftResult(object): + """ + A handle on the data drift result of a model evaluation. + + Do not create this class directly, instead use :meth:`dataikuapi.dss.DSSModelEvaluation.compute_data_drift` + """ + def __init__(self, data): + self.data = data + + def get_raw(self): + """ + Get the raw data drift result. + + :return: the raw data drift result + :rtype: dict + """ + return self.data + + def get_drift_model_result(self): + """ + Get the drift analysis based on drift modeling. + + :return: A handle on the drift model result + :rtype: :class:`dataikuapi.dss.modelevaluationstore.DriftModelResult` + """ + return DriftModelResult(self.data["driftModelResult"]) + + def get_univariate_drift_result(self): + """ + Get a per-column drift analysis based on comparison of distributions. + + :return: A handle on the univariate drift result + :rtype: :class:`dataikuapi.dss.modelevaluationstore.UnivariateDriftResult` + """ + return UnivariateDriftResult(self.data["univariateDriftResult"]) + + def get_per_column_report(self): + """ + Get the information about column handling that has been used (errors, types, etc). + + :return: A list of handles on column reports + :rtype: list of :class:`dataikuapi.dss.modelevaluationstore.ColumnReport` + """ + return map(ColumnReport, self.data["perColumnReport"]) + + def get_reference_sample_size(self): + """ + Get the size of the reference ME sample. + + :return: the size of the reference sample + :rtype: int + """ + return self.data["referenceSampleSize"] + + def get_current_sample_size(self): + """ + Size of the current ME sample. + + :return: the size of the current ME + :rtype: int + """ + return self.data["currentSampleSize"] + + +class DriftModelResult(object): + """ + A handle on the drift model result. + + Do not create this class directly, instead use :meth:`dataikuapi.dss.modelevaluationstore.DataDriftResult.get_drift_model_result` + """ + def __init__(self, data): + self.data = data + + def get_raw(self): + """ + Get the raw drift model result. + + :return: the raw drift model result + :rtype: dict + """ + return self.data + + def get_reference_sample_size(self): + """ + Get the number of rows coming from reference ME in the drift model trainset. + + :return: the number of rows coming from reference ME + :rtype: int + """ + return self.data["referenceSampleSize"] + + def get_current_sample_size(self): + """ + Get the number of rows coming from current ME in the drift model trainset. + + :return: the number of rows coming from current ME + :rtype: int + """ + return self.data["currentSampleSize"] + + def get_drift_model_accuracy(self): + """ + Get the drift model accuracy information. + + :return: A handle to interact with the drift model accuracy information + :rtype: :class:`dataiku.dss.modelevaluationstore.DriftModelAccuracy` + """ + return DriftModelAccuracy(self.data["driftModelAccuracy"]) + + def get_feature_drift_importance(self): + """ + Get the feature drift importance chart data. + + :return: A handle on feature drift importance chart data + :rtype: :class:`dataiku.dss.modelevaluationstore.DriftVersusImportanceChart` + """ + return DriftVersusImportanceChart(self.data["driftVersusImportance"]) + + +class UnivariateDriftResult(object): + """ + A handle on the univariate data drift. + + Do not create this class directly, instead use :meth:`dataikuapi.dss.modelevaluationstore.DataDriftResult.get_univariate_drift_result` + """ + def __init__(self, data): + self.data = data + + def get_raw(self): + """ + Get the raw univariate data drift. + It consists of a map with column name as keys, and a `dict ` with drift data as value. + + :return: the raw univariate data drift + :rtype: dict + """ + return self.data["columns"] + + +class ColumnReport(object): + """ + A handle on column handling information. + + Do not create this class directly, instead use :meth:`dataikuapi.dss.modelevaluationstore.DataDriftResult.get_per_column_report` + """ + def __init__(self, data): + self.data = data + + def get_raw(self): + """ + Get the raw column handling information. + + :return: the raw column handling information + :rtype: dict + """ + return self.data + + def get_name(self): + """ + Get the column name. + + :return: the column name + :rtype: string + """ + return self.data["name"] + + def get_actual_column_handling(self): + """ + Get the actual column handling (either forced via drift params or inferred from ME preprocessings). + It can be any of NUMERICAL, CATEGORICAL, or IGNORED. + + :return: the actual column handling + :rtype: string + """ + return self.data["actualHandling"] + + def get_default_column_handling(self): + """ + Get the default column handling (based on ME preprocessing only). + It can be any of NUMERICAL, CATEGORICAL, or IGNORED. + + :return: the default column handling + :rtype: string + """ + return self.data["defaultHandling"] + + def get_error_message(self): + """ + Get the error message. + For example: "could not treat column as numerical" (in this case, the column handling is forced to 'IGNORED'). + + :return: the error message, if there is any + :rtype: string + """ + return self.data["errorMessage"] + + +class DriftModelAccuracy(object): + """ + A handle on the drift model accuracy. + + Do not create this class directly, instead use :meth:`dataikuapi.dss.modelevaluationstore.DriftModelResult.get_drift_model_accuracy` + """ + def __init__(self, data): + self.data = data + + def get_raw(self): + """ + Get the raw drift model accuracy data. + + :return: the drift model accuracy data + :rtype: dict + """ + return self.data + + def get_value(self): + """ + Get the drift model accuracy value. + + :return: the accuracy value + :rtype: float + """ + return self.data["value"] + + def get_lower_confidence_interval(self): + """ + Get the drift model accuracy lower confidence interval. + + :return: the lower confidence interval + :rtype: float + """ + return self.data["lower"] + + def get_upper_confidence_interval(self): + """ + Get the drift model accuracy upper confidence interval. + + :return: the upper confidence interval + :rtype: float + """ + return self.data["upper"] + + def get_pvalue(self): + """ + Get the drift model accuracy pvalue for H0: "there is no drift". + + :return: the accuracy pvalue for H0: "there is no drift" + :rtype: float + """ + return self.data["pvalue"] + + +class DriftVersusImportanceChart(object): + """ + A handle on the feature drift importance chart data. + + Do not create this class directly, instead use :meth:`dataikuapi.dss.modelevaluationstore.DriftModelResult.get_feature_drift_importance` + """ + def __init__(self, data): + self.data = data + + def get_raw(self): + """ + Get the raw feature drift importance chart data. + + :return: the feature drift importance chart data + :rtype: dict + """ + return self.data + + def get_column_names(self): + """ + Get the column names. + + :return: a `list` of the column names + :rtype: list of string + """ + return self.data["columns"] + + def get_column_drift_scores(self): + """ + Get the importance of the columns in the drift model. + + :return: the `list` of the importance of the columns in the drift model + :rtype: list of float + """ + return self.data["columnDriftScores"] + + def get_column_original_scores(self): + """ + Get the importance of the columns in the original model. + Returns None when it can't be computed. + + :return: the `list` of the importance of the columns in the original model + :rtype: list of float + """ + return self.data["columnImportanceScores"] From a5b7aa4c22cfb291da76a9e01a745d17045a6934 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Bourhis?= Date: Thu, 7 Oct 2021 20:10:15 +0200 Subject: [PATCH 02/11] Rollback renaming of get_full_info to get_evaluation_full_info --- dataikuapi/dss/modelevaluationstore.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dataikuapi/dss/modelevaluationstore.py b/dataikuapi/dss/modelevaluationstore.py index f0f2ae3e..e630ad5c 100644 --- a/dataikuapi/dss/modelevaluationstore.py +++ b/dataikuapi/dss/modelevaluationstore.py @@ -269,7 +269,7 @@ def __init__(self, model_evaluation_store, run_id): self.project_key = model_evaluation_store.project_key self.mes_id = model_evaluation_store.mes_id - def get_evaluation_full_info(self): + def get_full_info(self): """ Retrieve the model evaluation with its performance data @@ -360,7 +360,7 @@ class DSSModelEvaluationFullInfo: Includes information such as the full id of the evaluated model, the evaluation params, the performance and drift metrics, if any, etc. - Do not create this class directly, instead use :meth:`dataikuapi.dss.DSSModelEvaluation.get_evaluation_full_info` + Do not create this class directly, instead use :meth:`dataikuapi.dss.DSSModelEvaluation.get_full_info` """ def __init__(self, model_evaluation, full_info): self.model_evaluation = model_evaluation From e1c23129422313e3a16b1f6d2cba604460f14f5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Bourhis?= Date: Fri, 8 Oct 2021 17:33:41 +0200 Subject: [PATCH 03/11] Add consistency to naming styles in the documentation --- dataikuapi/dss/modelevaluationstore.py | 32 +++++++++++++------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/dataikuapi/dss/modelevaluationstore.py b/dataikuapi/dss/modelevaluationstore.py index e630ad5c..29eabfc2 100644 --- a/dataikuapi/dss/modelevaluationstore.py +++ b/dataikuapi/dss/modelevaluationstore.py @@ -167,7 +167,7 @@ def delete_model_evaluations(self, evaluations): def build(self, job_type="NON_RECURSIVE_FORCED_BUILD", wait=True, no_fail=False): """ - Starts a new job to build this Model Evaluation Store and wait for it to complete. + Starts a new job to build this model evaluation store and wait for it to complete. Raises if the job failed. .. code-block:: python @@ -379,7 +379,7 @@ def get_metrics(self): def get_labels(self): """ - Get the labels of the Model Evaluation + Get the labels of the model evaluation :return: a dict containing the labels """ @@ -396,7 +396,7 @@ def get_evaluation_parameters(self): def get_creation_date(self): """ - Return the date and time of the creation of the Model Evaluation + Return the date and time of the creation of the model evaluation :return: the date and time, as an epoch """ @@ -404,7 +404,7 @@ def get_creation_date(self): def get_full_id(self): """ - Returns the full id of the Model Evaluation. + Returns the full id of the model evaluation. :return: the full id, as a string """ @@ -565,18 +565,18 @@ def get_per_column_report(self): def get_reference_sample_size(self): """ - Get the size of the reference ME sample. + Get the size of the reference model evaluation sample. - :return: the size of the reference sample + :return: the size of the reference model evaluation sample :rtype: int """ return self.data["referenceSampleSize"] def get_current_sample_size(self): """ - Size of the current ME sample. + Size of the current model evaluation sample. - :return: the size of the current ME + :return: the size of the current model evaluation sample :rtype: int """ return self.data["currentSampleSize"] @@ -602,18 +602,18 @@ def get_raw(self): def get_reference_sample_size(self): """ - Get the number of rows coming from reference ME in the drift model trainset. + Get the number of rows coming from reference model evaluation in the drift model trainset. - :return: the number of rows coming from reference ME + :return: the number of rows coming from reference model evaluation :rtype: int """ return self.data["referenceSampleSize"] def get_current_sample_size(self): """ - Get the number of rows coming from current ME in the drift model trainset. + Get the number of rows coming from current model evaluation in the drift model trainset. - :return: the number of rows coming from current ME + :return: the number of rows coming from current model evaluation :rtype: int """ return self.data["currentSampleSize"] @@ -686,7 +686,7 @@ def get_name(self): def get_actual_column_handling(self): """ - Get the actual column handling (either forced via drift params or inferred from ME preprocessings). + Get the actual column handling (either forced via drift params or inferred from model evaluation preprocessings). It can be any of NUMERICAL, CATEGORICAL, or IGNORED. :return: the actual column handling @@ -696,7 +696,7 @@ def get_actual_column_handling(self): def get_default_column_handling(self): """ - Get the default column handling (based on ME preprocessing only). + Get the default column handling (based on model evaluation preprocessing only). It can be any of NUMERICAL, CATEGORICAL, or IGNORED. :return: the default column handling @@ -762,9 +762,9 @@ def get_upper_confidence_interval(self): def get_pvalue(self): """ - Get the drift model accuracy pvalue for H0: "there is no drift". + Get the drift model accuracy pvalue for null hypothesis: "there is no drift". - :return: the accuracy pvalue for H0: "there is no drift" + :return: the accuracy pvalue for null hypothesis :rtype: float """ return self.data["pvalue"] From fe26f3f1238d2d8def0250fdfb2609efbe391baa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Bourhis?= Date: Tue, 12 Oct 2021 11:02:26 +0200 Subject: [PATCH 04/11] Rename ColumnReport to ColumnSettings --- dataikuapi/dss/modelevaluationstore.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dataikuapi/dss/modelevaluationstore.py b/dataikuapi/dss/modelevaluationstore.py index adb31339..0694176e 100644 --- a/dataikuapi/dss/modelevaluationstore.py +++ b/dataikuapi/dss/modelevaluationstore.py @@ -554,14 +554,14 @@ def get_univariate_drift_result(self): """ return UnivariateDriftResult(self.data["univariateDriftResult"]) - def get_per_column_report(self): + def get_per_column_settings(self): """ Get the information about column handling that has been used (errors, types, etc). - :return: A list of handles on column reports - :rtype: list of :class:`dataikuapi.dss.modelevaluationstore.ColumnReport` + :return: A list of handles on column settings + :rtype: list of :class:`dataikuapi.dss.modelevaluationstore.ColumnSettings` """ - return map(ColumnReport, self.data["perColumnReport"]) + return map(ColumnSettings, self.data["perColumnSettings"]) def get_reference_sample_size(self): """ @@ -657,11 +657,11 @@ def get_raw(self): return self.data["columns"] -class ColumnReport(object): +class ColumnSettings(object): """ A handle on column handling information. - Do not create this class directly, instead use :meth:`dataikuapi.dss.modelevaluationstore.DataDriftResult.get_per_column_report` + Do not create this class directly, instead use :meth:`dataikuapi.dss.modelevaluationstore.DataDriftResult.get_per_column_settings` """ def __init__(self, data): self.data = data From fbc1217b51ea1e3dcfbd8cad6329a9f1a18318ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Bourhis?= Date: Tue, 12 Oct 2021 12:30:54 +0200 Subject: [PATCH 05/11] Change some getters to properties for primitive types Return raw data for get_raw in UnivariateDriftResult and add a property for getting per column data drift info. --- dataikuapi/dss/modelevaluationstore.py | 90 ++++++++++++++++++-------- 1 file changed, 63 insertions(+), 27 deletions(-) diff --git a/dataikuapi/dss/modelevaluationstore.py b/dataikuapi/dss/modelevaluationstore.py index 0694176e..c7ddd334 100644 --- a/dataikuapi/dss/modelevaluationstore.py +++ b/dataikuapi/dss/modelevaluationstore.py @@ -369,7 +369,8 @@ def __init__(self, model_evaluation, full_info): def get_raw(self): return self.full_info - def get_metrics(self): + @property + def metrics(self): """ Get the metrics evaluated, if any. @@ -377,7 +378,8 @@ def get_metrics(self): """ return self.full_info["metrics"] - def get_labels(self): + @property + def labels(self): """ Get the labels of the model evaluation @@ -385,7 +387,8 @@ def get_labels(self): """ return self.full_info["evaluation"]["labels"] - def get_evaluation_parameters(self): + @property + def evaluation_parameters(self): """ Get info on the evaluation parameters, most noticeably the evaluation metric (evaluationMetric field of the returned dict) @@ -394,7 +397,8 @@ def get_evaluation_parameters(self): """ return self.full_info["evaluation"]["metricParams"] - def get_creation_date(self): + @property + def creation_date(self): """ Return the date and time of the creation of the model evaluation @@ -402,7 +406,8 @@ def get_creation_date(self): """ return self.full_info["evaluation"]["created"] - def get_full_id(self): + @property + def full_id(self): """ Returns the full id of the model evaluation. @@ -410,7 +415,8 @@ def get_full_id(self): """ return self.full_info["evaluation"]["ref"]["fullId"] - def get_model_full_id(self): + @property + def model_full_id(self): """ Returns the full id of the evaluated model. @@ -418,7 +424,8 @@ def get_model_full_id(self): """ return self.full_info["evaluation"]["modelRef"]["fullId"] - def get_model_type(self): + @property + def model_type(self): """ Returns the evaluated model type. @@ -426,7 +433,8 @@ def get_model_type(self): """ return self.full_info["evaluation"]["modelType"] - def get_model_parameters(self): + @property + def model_parameters(self): """ Returns the evaluated model params. @@ -434,7 +442,8 @@ def get_model_parameters(self): """ return self.full_info["evaluation"]["modelParams"] - def get_prediction_type(self): + @property + def prediction_type(self): """ Returns the prediction type of the evaluated model. @@ -442,7 +451,8 @@ def get_prediction_type(self): """ return self.full_info["evaluation"]["predictionType"] - def get_prediction_variable(self): + @property + def prediction_variable(self): """ Returns the prediction variable used for evaluation. @@ -450,7 +460,8 @@ def get_prediction_variable(self): """ return self.full_info["evaluation"]["predictionVariable"] - def get_target_variable(self): + @property + def target_variable(self): """ Returns the target variable used for evaluation. @@ -563,7 +574,8 @@ def get_per_column_settings(self): """ return map(ColumnSettings, self.data["perColumnSettings"]) - def get_reference_sample_size(self): + @property + def reference_sample_size(self): """ Get the size of the reference model evaluation sample. @@ -572,7 +584,8 @@ def get_reference_sample_size(self): """ return self.data["referenceSampleSize"] - def get_current_sample_size(self): + @property + def current_sample_size(self): """ Size of the current model evaluation sample. @@ -600,7 +613,8 @@ def get_raw(self): """ return self.data - def get_reference_sample_size(self): + @property + def reference_sample_size(self): """ Get the number of rows coming from reference model evaluation in the drift model trainset. @@ -609,7 +623,8 @@ def get_reference_sample_size(self): """ return self.data["referenceSampleSize"] - def get_current_sample_size(self): + @property + def current_sample_size(self): """ Get the number of rows coming from current model evaluation in the drift model trainset. @@ -649,11 +664,21 @@ def __init__(self, data): def get_raw(self): """ Get the raw univariate data drift. - It consists of a map with column name as keys, and a `dict ` with drift data as value. :return: the raw univariate data drift :rtype: dict """ + return self.data + + @property + def drift_data_per_column(self): + """ + Get the drift data per column. + It consists of a map with column name as keys, and a `dict ` with drift data as value. + + :return: the drift data per column + :rtype: dict + """ return self.data["columns"] @@ -675,7 +700,8 @@ def get_raw(self): """ return self.data - def get_name(self): + @property + def name(self): """ Get the column name. @@ -684,7 +710,8 @@ def get_name(self): """ return self.data["name"] - def get_actual_column_handling(self): + @property + def actual_column_handling(self): """ Get the actual column handling (either forced via drift params or inferred from model evaluation preprocessings). It can be any of NUMERICAL, CATEGORICAL, or IGNORED. @@ -694,7 +721,8 @@ def get_actual_column_handling(self): """ return self.data["actualHandling"] - def get_default_column_handling(self): + @property + def default_column_handling(self): """ Get the default column handling (based on model evaluation preprocessing only). It can be any of NUMERICAL, CATEGORICAL, or IGNORED. @@ -704,7 +732,8 @@ def get_default_column_handling(self): """ return self.data["defaultHandling"] - def get_error_message(self): + @property + def error_message(self): """ Get the error message. For example: "could not treat column as numerical" (in this case, the column handling is forced to 'IGNORED'). @@ -733,7 +762,8 @@ def get_raw(self): """ return self.data - def get_value(self): + @property + def value(self): """ Get the drift model accuracy value. @@ -742,7 +772,8 @@ def get_value(self): """ return self.data["value"] - def get_lower_confidence_interval(self): + @property + def lower_confidence_interval(self): """ Get the drift model accuracy lower confidence interval. @@ -751,7 +782,8 @@ def get_lower_confidence_interval(self): """ return self.data["lower"] - def get_upper_confidence_interval(self): + @property + def upper_confidence_interval(self): """ Get the drift model accuracy upper confidence interval. @@ -760,7 +792,8 @@ def get_upper_confidence_interval(self): """ return self.data["upper"] - def get_pvalue(self): + @property + def pvalue(self): """ Get the drift model accuracy pvalue for null hypothesis: "there is no drift". @@ -788,7 +821,8 @@ def get_raw(self): """ return self.data - def get_column_names(self): + @property + def column_names(self): """ Get the column names. @@ -797,7 +831,8 @@ def get_column_names(self): """ return self.data["columns"] - def get_column_drift_scores(self): + @property + def column_drift_scores(self): """ Get the importance of the columns in the drift model. @@ -806,7 +841,8 @@ def get_column_drift_scores(self): """ return self.data["columnDriftScores"] - def get_column_original_scores(self): + @property + def column_original_scores(self): """ Get the importance of the columns in the original model. Returns None when it can't be computed. From 10c6f67e7766516f29f50732461bede7ef474979 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Bourhis?= Date: Mon, 18 Oct 2021 12:26:29 +0200 Subject: [PATCH 06/11] Taking into account PR review --- dataikuapi/dss/modelevaluationstore.py | 360 ++++--------------------- 1 file changed, 51 insertions(+), 309 deletions(-) diff --git a/dataikuapi/dss/modelevaluationstore.py b/dataikuapi/dss/modelevaluationstore.py index c7ddd334..af3d6b15 100644 --- a/dataikuapi/dss/modelevaluationstore.py +++ b/dataikuapi/dss/modelevaluationstore.py @@ -365,109 +365,30 @@ class DSSModelEvaluationFullInfo: def __init__(self, model_evaluation, full_info): self.model_evaluation = model_evaluation self.full_info = full_info + self.metrics = self.full_info["metrics"] # type: dict + """The performance and data drift metric, if any.""" + self.evaluation_parameters = self.full_info["evaluation"]["metricParams"] # type: dict + """Information on the evaluation parameters, most noticeably the evaluation metric (evaluationMetric field of the returned dict).""" + self.creation_date = self.full_info["evaluation"]["created"] # type: int + """The date and time of the creation of the model evaluation, as an epoch.""" + self.full_id = self.full_info["evaluation"]["ref"]["fullId"] # type: str + self.model_full_id = self.full_info["evaluation"]["modelRef"]["fullId"] # type: str + self.model_type = self.full_info["evaluation"]["modelType"] # type: str + self.model_parameters = self.full_info["evaluation"]["modelParams"] + self.prediction_type = self.full_info["evaluation"]["predictionType"] # type: str + self.prediction_variable = self.full_info["evaluation"]["predictionVariable"] # type: str + self.target_variable = self.full_info["evaluation"]["targetVariable"] # type: str + self.user_meta = self.full_info["evaluation"]["userMeta"] # type: dict + """The user-accessible metadata (name, labels) + Returns the original object, not a copy. Changes to the returned object are persisted to DSS by calling :meth:`save_user_meta`.""" def get_raw(self): return self.full_info - @property - def metrics(self): - """ - Get the metrics evaluated, if any. - - :return: a dict containing the performance and data drift metric, if any - """ - return self.full_info["metrics"] - - @property - def labels(self): - """ - Get the labels of the model evaluation - - :return: a dict containing the labels - """ - return self.full_info["evaluation"]["labels"] - - @property - def evaluation_parameters(self): - """ - Get info on the evaluation parameters, most noticeably the evaluation metric (evaluationMetric field - of the returned dict) - - :return: a dict - """ - return self.full_info["evaluation"]["metricParams"] - - @property - def creation_date(self): - """ - Return the date and time of the creation of the model evaluation - - :return: the date and time, as an epoch - """ - return self.full_info["evaluation"]["created"] - - @property - def full_id(self): - """ - Returns the full id of the model evaluation. - - :return: the full id, as a string - """ - return self.full_info["evaluation"]["ref"]["fullId"] - - @property - def model_full_id(self): - """ - Returns the full id of the evaluated model. - - :return: the model full id, as a string - """ - return self.full_info["evaluation"]["modelRef"]["fullId"] - - @property - def model_type(self): - """ - Returns the evaluated model type. - - :return: the model type, as a string - """ - return self.full_info["evaluation"]["modelType"] - - @property - def model_parameters(self): - """ - Returns the evaluated model params. - - :return: the model params, as a dict - """ - return self.full_info["evaluation"]["modelParams"] - - @property - def prediction_type(self): - """ - Returns the prediction type of the evaluated model. - - :return: the prediction type, as a string - """ - return self.full_info["evaluation"]["predictionType"] - - @property - def prediction_variable(self): - """ - Returns the prediction variable used for evaluation. - - :return: the prediction variable, as a string - """ - return self.full_info["evaluation"]["predictionVariable"] - - @property - def target_variable(self): - """ - Returns the target variable used for evaluation. - - :return: the target variable, as a string - """ - return self.full_info["evaluation"]["targetVariable"] + def save_user_meta(self): + return self.model_evaluation.client._perform_text( + "PUT", "/projects/%s/modelevaluationstores/%s/evaluations/%s/user-meta" % + (self.model_evaluation.project_key, self.model_evaluation.mes_id, self.model_evaluation.evaluation_id), body=self.user_meta) class DataDriftParams(object): @@ -537,6 +458,14 @@ class DataDriftResult(object): """ def __init__(self, data): self.data = data + self.drift_model_result = DriftModelResult(self.data["driftModelResult"]) + """Drift analysis based on drift modeling.""" + self.univariate_drift_result = UnivariateDriftResult(self.data["univariateDriftResult"]) + """Per-column drift analysis based on comparison of distributions.""" + self.per_column_settings = list(map(ColumnSettings, self.data["perColumnSettings"])) + """Information about column handling that has been used (errors, types, etc).""" + self.reference_sample_size = self.data["referenceSampleSize"] # type: int + self.current_sample_size = self.data["currentSampleSize"] # type: int def get_raw(self): """ @@ -547,53 +476,6 @@ def get_raw(self): """ return self.data - def get_drift_model_result(self): - """ - Get the drift analysis based on drift modeling. - - :return: A handle on the drift model result - :rtype: :class:`dataikuapi.dss.modelevaluationstore.DriftModelResult` - """ - return DriftModelResult(self.data["driftModelResult"]) - - def get_univariate_drift_result(self): - """ - Get a per-column drift analysis based on comparison of distributions. - - :return: A handle on the univariate drift result - :rtype: :class:`dataikuapi.dss.modelevaluationstore.UnivariateDriftResult` - """ - return UnivariateDriftResult(self.data["univariateDriftResult"]) - - def get_per_column_settings(self): - """ - Get the information about column handling that has been used (errors, types, etc). - - :return: A list of handles on column settings - :rtype: list of :class:`dataikuapi.dss.modelevaluationstore.ColumnSettings` - """ - return map(ColumnSettings, self.data["perColumnSettings"]) - - @property - def reference_sample_size(self): - """ - Get the size of the reference model evaluation sample. - - :return: the size of the reference model evaluation sample - :rtype: int - """ - return self.data["referenceSampleSize"] - - @property - def current_sample_size(self): - """ - Size of the current model evaluation sample. - - :return: the size of the current model evaluation sample - :rtype: int - """ - return self.data["currentSampleSize"] - class DriftModelResult(object): """ @@ -603,6 +485,12 @@ class DriftModelResult(object): """ def __init__(self, data): self.data = data + self.reference_sample_size = self.data["referenceSampleSize"] # type: int + """Number of rows coming from reference model evaluation in the drift model trainset.""" + self.current_sample_size = self.data["currentSampleSize"] # type: int + """Number of rows coming from current model evaluation in the drift model trainset.""" + self.drift_model_accuracy = DriftModelAccuracy(self.data["driftModelAccuracy"]) + self.feature_drift_importance = DriftVersusImportanceChart(self.data["driftVersusImportance"]) def get_raw(self): """ @@ -613,44 +501,6 @@ def get_raw(self): """ return self.data - @property - def reference_sample_size(self): - """ - Get the number of rows coming from reference model evaluation in the drift model trainset. - - :return: the number of rows coming from reference model evaluation - :rtype: int - """ - return self.data["referenceSampleSize"] - - @property - def current_sample_size(self): - """ - Get the number of rows coming from current model evaluation in the drift model trainset. - - :return: the number of rows coming from current model evaluation - :rtype: int - """ - return self.data["currentSampleSize"] - - def get_drift_model_accuracy(self): - """ - Get the drift model accuracy information. - - :return: A handle to interact with the drift model accuracy information - :rtype: :class:`dataiku.dss.modelevaluationstore.DriftModelAccuracy` - """ - return DriftModelAccuracy(self.data["driftModelAccuracy"]) - - def get_feature_drift_importance(self): - """ - Get the feature drift importance chart data. - - :return: A handle on feature drift importance chart data - :rtype: :class:`dataiku.dss.modelevaluationstore.DriftVersusImportanceChart` - """ - return DriftVersusImportanceChart(self.data["driftVersusImportance"]) - class UnivariateDriftResult(object): """ @@ -660,6 +510,8 @@ class UnivariateDriftResult(object): """ def __init__(self, data): self.data = data + self.per_column_drift_data = self.data["columns"] # type: dict + """Drift data per column, as a dict of column name -> drift data.""" def get_raw(self): """ @@ -670,17 +522,6 @@ def get_raw(self): """ return self.data - @property - def drift_data_per_column(self): - """ - Get the drift data per column. - It consists of a map with column name as keys, and a `dict ` with drift data as value. - - :return: the drift data per column - :rtype: dict - """ - return self.data["columns"] - class ColumnSettings(object): """ @@ -690,6 +531,14 @@ class ColumnSettings(object): """ def __init__(self, data): self.data = data + self.name = self.data["name"] # type: str + self.actual_column_handling = self.data["actualHandling"] # type: str + """The actual column handling (either forced via drift params or inferred from model evaluation preprocessings). + It can be any of NUMERICAL, CATEGORICAL, or IGNORED.""" + self.default_column_handling = self.data["defaultHandling"] # type: str + """The default column handling (based on model evaluation preprocessing only). + It can be any of NUMERICAL, CATEGORICAL, or IGNORED.""" + self.error_message = self.data.get("errorMessage", None) def get_raw(self): """ @@ -700,49 +549,6 @@ def get_raw(self): """ return self.data - @property - def name(self): - """ - Get the column name. - - :return: the column name - :rtype: string - """ - return self.data["name"] - - @property - def actual_column_handling(self): - """ - Get the actual column handling (either forced via drift params or inferred from model evaluation preprocessings). - It can be any of NUMERICAL, CATEGORICAL, or IGNORED. - - :return: the actual column handling - :rtype: string - """ - return self.data["actualHandling"] - - @property - def default_column_handling(self): - """ - Get the default column handling (based on model evaluation preprocessing only). - It can be any of NUMERICAL, CATEGORICAL, or IGNORED. - - :return: the default column handling - :rtype: string - """ - return self.data["defaultHandling"] - - @property - def error_message(self): - """ - Get the error message. - For example: "could not treat column as numerical" (in this case, the column handling is forced to 'IGNORED'). - - :return: the error message, if there is any - :rtype: string - """ - return self.data["errorMessage"] - class DriftModelAccuracy(object): """ @@ -752,6 +558,10 @@ class DriftModelAccuracy(object): """ def __init__(self, data): self.data = data + self.value = self.data["value"] # type: float + self.lower_confidence_interval = self.data["lower"] # type: float + self.upper_confidence_interval = self.data["upper"] # type: float + self.pvalue = self.data["pvalue"] # type: float def get_raw(self): """ @@ -762,46 +572,6 @@ def get_raw(self): """ return self.data - @property - def value(self): - """ - Get the drift model accuracy value. - - :return: the accuracy value - :rtype: float - """ - return self.data["value"] - - @property - def lower_confidence_interval(self): - """ - Get the drift model accuracy lower confidence interval. - - :return: the lower confidence interval - :rtype: float - """ - return self.data["lower"] - - @property - def upper_confidence_interval(self): - """ - Get the drift model accuracy upper confidence interval. - - :return: the upper confidence interval - :rtype: float - """ - return self.data["upper"] - - @property - def pvalue(self): - """ - Get the drift model accuracy pvalue for null hypothesis: "there is no drift". - - :return: the accuracy pvalue for null hypothesis - :rtype: float - """ - return self.data["pvalue"] - class DriftVersusImportanceChart(object): """ @@ -811,6 +581,9 @@ class DriftVersusImportanceChart(object): """ def __init__(self, data): self.data = data + self.column_names = self.data["columns"] # type: list + self.column_drift_scores = self.data["columnDriftScores"] # type: list + self.column_original_scores = self.data["columnImportanceScores"] # type: list def get_raw(self): """ @@ -820,34 +593,3 @@ def get_raw(self): :rtype: dict """ return self.data - - @property - def column_names(self): - """ - Get the column names. - - :return: a `list` of the column names - :rtype: list of string - """ - return self.data["columns"] - - @property - def column_drift_scores(self): - """ - Get the importance of the columns in the drift model. - - :return: the `list` of the importance of the columns in the drift model - :rtype: list of float - """ - return self.data["columnDriftScores"] - - @property - def column_original_scores(self): - """ - Get the importance of the columns in the original model. - Returns None when it can't be computed. - - :return: the `list` of the importance of the columns in the original model - :rtype: list of float - """ - return self.data["columnImportanceScores"] From 7efb7f7d3df5260322bf472fcfcfcf282be49071 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Bourhis?= Date: Mon, 18 Oct 2021 14:50:39 +0200 Subject: [PATCH 07/11] Removing unimportant helpers --- dataikuapi/dss/modelevaluationstore.py | 34 +++----------------------- 1 file changed, 4 insertions(+), 30 deletions(-) diff --git a/dataikuapi/dss/modelevaluationstore.py b/dataikuapi/dss/modelevaluationstore.py index af3d6b15..3b5b0e5a 100644 --- a/dataikuapi/dss/modelevaluationstore.py +++ b/dataikuapi/dss/modelevaluationstore.py @@ -367,14 +367,10 @@ def __init__(self, model_evaluation, full_info): self.full_info = full_info self.metrics = self.full_info["metrics"] # type: dict """The performance and data drift metric, if any.""" - self.evaluation_parameters = self.full_info["evaluation"]["metricParams"] # type: dict - """Information on the evaluation parameters, most noticeably the evaluation metric (evaluationMetric field of the returned dict).""" self.creation_date = self.full_info["evaluation"]["created"] # type: int """The date and time of the creation of the model evaluation, as an epoch.""" self.full_id = self.full_info["evaluation"]["ref"]["fullId"] # type: str self.model_full_id = self.full_info["evaluation"]["modelRef"]["fullId"] # type: str - self.model_type = self.full_info["evaluation"]["modelType"] # type: str - self.model_parameters = self.full_info["evaluation"]["modelParams"] self.prediction_type = self.full_info["evaluation"]["predictionType"] # type: str self.prediction_variable = self.full_info["evaluation"]["predictionVariable"] # type: str self.target_variable = self.full_info["evaluation"]["targetVariable"] # type: str @@ -481,7 +477,7 @@ class DriftModelResult(object): """ A handle on the drift model result. - Do not create this class directly, instead use :meth:`dataikuapi.dss.modelevaluationstore.DataDriftResult.get_drift_model_result` + Do not create this class directly, instead use :attr:`dataikuapi.dss.modelevaluationstore.DataDriftResult.drift_model_result` """ def __init__(self, data): self.data = data @@ -490,7 +486,7 @@ def __init__(self, data): self.current_sample_size = self.data["currentSampleSize"] # type: int """Number of rows coming from current model evaluation in the drift model trainset.""" self.drift_model_accuracy = DriftModelAccuracy(self.data["driftModelAccuracy"]) - self.feature_drift_importance = DriftVersusImportanceChart(self.data["driftVersusImportance"]) + self.feature_drift_importance = self.data["driftVersusImportance"] # type: dict def get_raw(self): """ @@ -506,7 +502,7 @@ class UnivariateDriftResult(object): """ A handle on the univariate data drift. - Do not create this class directly, instead use :meth:`dataikuapi.dss.modelevaluationstore.DataDriftResult.get_univariate_drift_result` + Do not create this class directly, instead use :attr:`dataikuapi.dss.modelevaluationstore.DataDriftResult.univariate_drift_result` """ def __init__(self, data): self.data = data @@ -554,7 +550,7 @@ class DriftModelAccuracy(object): """ A handle on the drift model accuracy. - Do not create this class directly, instead use :meth:`dataikuapi.dss.modelevaluationstore.DriftModelResult.get_drift_model_accuracy` + Do not create this class directly, instead use :attr:`dataikuapi.dss.modelevaluationstore.DriftModelResult.drift_model_accuracy` """ def __init__(self, data): self.data = data @@ -571,25 +567,3 @@ def get_raw(self): :rtype: dict """ return self.data - - -class DriftVersusImportanceChart(object): - """ - A handle on the feature drift importance chart data. - - Do not create this class directly, instead use :meth:`dataikuapi.dss.modelevaluationstore.DriftModelResult.get_feature_drift_importance` - """ - def __init__(self, data): - self.data = data - self.column_names = self.data["columns"] # type: list - self.column_drift_scores = self.data["columnDriftScores"] # type: list - self.column_original_scores = self.data["columnImportanceScores"] # type: list - - def get_raw(self): - """ - Get the raw feature drift importance chart data. - - :return: the feature drift importance chart data - :rtype: dict - """ - return self.data From 671d763e88e58ef79e9666a2832c2abae6d363ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Bourhis?= Date: Mon, 18 Oct 2021 14:51:00 +0200 Subject: [PATCH 08/11] Use a list comprehension instead of a `list(map())` for wider compatibility --- dataikuapi/dss/modelevaluationstore.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dataikuapi/dss/modelevaluationstore.py b/dataikuapi/dss/modelevaluationstore.py index 3b5b0e5a..da9184fa 100644 --- a/dataikuapi/dss/modelevaluationstore.py +++ b/dataikuapi/dss/modelevaluationstore.py @@ -458,7 +458,7 @@ def __init__(self, data): """Drift analysis based on drift modeling.""" self.univariate_drift_result = UnivariateDriftResult(self.data["univariateDriftResult"]) """Per-column drift analysis based on comparison of distributions.""" - self.per_column_settings = list(map(ColumnSettings, self.data["perColumnSettings"])) + self.per_column_settings = [ColumnSettings(cs) for cs in self.data["perColumnSettings"]] """Information about column handling that has been used (errors, types, etc).""" self.reference_sample_size = self.data["referenceSampleSize"] # type: int self.current_sample_size = self.data["currentSampleSize"] # type: int From 0636feb0d2ccf25bbe2badbe1175d71d67a8b5bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Bourhis?= Date: Mon, 18 Oct 2021 15:55:48 +0200 Subject: [PATCH 09/11] Remove _sample_size attributes --- dataikuapi/dss/modelevaluationstore.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/dataikuapi/dss/modelevaluationstore.py b/dataikuapi/dss/modelevaluationstore.py index da9184fa..1b42e35f 100644 --- a/dataikuapi/dss/modelevaluationstore.py +++ b/dataikuapi/dss/modelevaluationstore.py @@ -460,8 +460,6 @@ def __init__(self, data): """Per-column drift analysis based on comparison of distributions.""" self.per_column_settings = [ColumnSettings(cs) for cs in self.data["perColumnSettings"]] """Information about column handling that has been used (errors, types, etc).""" - self.reference_sample_size = self.data["referenceSampleSize"] # type: int - self.current_sample_size = self.data["currentSampleSize"] # type: int def get_raw(self): """ @@ -481,10 +479,6 @@ class DriftModelResult(object): """ def __init__(self, data): self.data = data - self.reference_sample_size = self.data["referenceSampleSize"] # type: int - """Number of rows coming from reference model evaluation in the drift model trainset.""" - self.current_sample_size = self.data["currentSampleSize"] # type: int - """Number of rows coming from current model evaluation in the drift model trainset.""" self.drift_model_accuracy = DriftModelAccuracy(self.data["driftModelAccuracy"]) self.feature_drift_importance = self.data["driftVersusImportance"] # type: dict From 29851f6e3447c775d6c771adea466fd414999691 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Bourhis?= Date: Tue, 19 Oct 2021 15:04:26 +0200 Subject: [PATCH 10/11] Fix parameter naming & doc --- dataikuapi/dss/modelevaluationstore.py | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/dataikuapi/dss/modelevaluationstore.py b/dataikuapi/dss/modelevaluationstore.py index 1b42e35f..5b8b5637 100644 --- a/dataikuapi/dss/modelevaluationstore.py +++ b/dataikuapi/dss/modelevaluationstore.py @@ -399,11 +399,11 @@ def __repr__(self): return u"{}({})".format(self.__class__.__name__, self.data) @staticmethod - def from_params(columns, nb_bins=10, compute_histograms=True, confidence_level=0.95): + def from_params(per_column_settings, nb_bins=10, compute_histograms=True, confidence_level=0.95): """ Creates parameters for data drift computation from columns, number of bins, compute histograms and confidence level - :param dict columns: A dict representing the per column settings. + :param dict per_column_settings: A dict representing the per column settings. You should use a :class:`~dataikuapi.dss.modelevaluationstore.PerColumnDriftParamBuilder` to build it. :param int nb_bins: (optional) Nb. bins in histograms (apply to all columns) - default: 10 :param bool compute_histograms: (optional) Enable/disable histograms - default: True @@ -412,7 +412,7 @@ def from_params(columns, nb_bins=10, compute_histograms=True, confidence_level=0 :rtype: :class:`dataikuapi.dss.modelevaluationstore.DataDriftParams` """ return DataDriftParams({ - "columns": columns, + "columns": per_column_settings, "nbBins": nb_bins, "computeHistograms": compute_histograms, "confidenceLevel": confidence_level @@ -422,7 +422,8 @@ def from_params(columns, nb_bins=10, compute_histograms=True, confidence_level=0 class PerColumnDriftParamBuilder(object): """ Builder for a map of per column drift params settings. - Used as a helper before computing data drift to build columns param expected in dataikuapi.dss.modelevaluationstore.DataDriftParams.from_params. + Used as a helper before computing data drift to build columns param expected in + :meth:`dataikuapi.dss.modelevaluationstore.DataDriftParams.from_params`. """ def __init__(self): self.columns = {} @@ -431,13 +432,13 @@ def build(self): """Returns the built dict for per column drift params settings""" return self.columns - def with_column_drift_param(self, name, handling="AUTO", enabled=False): + def with_column_drift_param(self, name, handling="AUTO", enabled=True): """ Sets the drift params settings for given column name. :param: string name: The name of the column :param: string handling: (optional) The column type, should be either NUMERICAL, CATEGORICAL or AUTO (default: AUTO) - :param: bool name: (optional) If the column should be enabled (default: False) + :param: bool enabled: (optional) If the column should be enabled in drift computation (default: True) """ self.columns[name] = { "handling": handling, @@ -457,14 +458,12 @@ def __init__(self, data): self.drift_model_result = DriftModelResult(self.data["driftModelResult"]) """Drift analysis based on drift modeling.""" self.univariate_drift_result = UnivariateDriftResult(self.data["univariateDriftResult"]) - """Per-column drift analysis based on comparison of distributions.""" + """Per-column drift analysis based on pairwise comparison of distributions.""" self.per_column_settings = [ColumnSettings(cs) for cs in self.data["perColumnSettings"]] """Information about column handling that has been used (errors, types, etc).""" def get_raw(self): """ - Get the raw data drift result. - :return: the raw data drift result :rtype: dict """ @@ -484,8 +483,6 @@ def __init__(self, data): def get_raw(self): """ - Get the raw drift model result. - :return: the raw drift model result :rtype: dict """ @@ -505,8 +502,6 @@ def __init__(self, data): def get_raw(self): """ - Get the raw univariate data drift. - :return: the raw univariate data drift :rtype: dict """ @@ -532,8 +527,6 @@ def __init__(self, data): def get_raw(self): """ - Get the raw column handling information. - :return: the raw column handling information :rtype: dict """ @@ -555,8 +548,6 @@ def __init__(self, data): def get_raw(self): """ - Get the raw drift model accuracy data. - :return: the drift model accuracy data :rtype: dict """ From 27e711f0fad2cc8d8d056717c368d75e3f561dc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Bourhis?= Date: Tue, 19 Oct 2021 16:08:03 +0200 Subject: [PATCH 11/11] Better doc for `enabled` param of `PerColumnDriftParamBuilder.with_column_drift_param` --- dataikuapi/dss/modelevaluationstore.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dataikuapi/dss/modelevaluationstore.py b/dataikuapi/dss/modelevaluationstore.py index 5b8b5637..9ab69a23 100644 --- a/dataikuapi/dss/modelevaluationstore.py +++ b/dataikuapi/dss/modelevaluationstore.py @@ -438,7 +438,7 @@ def with_column_drift_param(self, name, handling="AUTO", enabled=True): :param: string name: The name of the column :param: string handling: (optional) The column type, should be either NUMERICAL, CATEGORICAL or AUTO (default: AUTO) - :param: bool enabled: (optional) If the column should be enabled in drift computation (default: True) + :param: bool enabled: (optional) False means the column is ignored in drift computation (default: True) """ self.columns[name] = { "handling": handling,