def get_multiline_stat_object(name, list_value, labels=None): """ Create multiline object from list of values. It outputs mulitline from values and legends is index of the values - i.e. 0, 1, .. :param name: Name of stat :param list_value: list of values to embed in multiline value. :return: MLOps Multiline Value object, timeseries stat category """ if isinstance(list_value, list) or isinstance(list_value, np.ndarray): category = StatCategory.TIME_SERIES # if labels are not provided then it will be 0, 1, .. length of list - 1 if labels is None: labels = range(len(list_value)) labels = list(map(lambda x: str(x).strip(), labels)) if (len(labels) == len(list_value)): multiline_object = MultiLineGraph() \ .name(name) \ .labels(labels) multiline_object.data(list(list_value)) return multiline_object, category else: raise MLOpsStatisticsException( "size of labels associated with list of values to get does not match. {}!={}" .format(len(labels), len(list_value))) else: raise MLOpsStatisticsException( "list_value has to be of type list or nd array but got {}". format(type(list_value)))
def _set_classification_stat(self, name, data, model_id, timestamp, **kwargs): mlops_stat_object = None category = StatCategory.TIME_SERIES self._logger.debug( "{} predefined stat called: name: {} data_type: {}".format( Constants.OFFICIAL_NAME, name, type(data))) mlops_stat_object, category = \ ClassificationStatObjectFactory.get_stat_object(name, data=data, **kwargs) if mlops_stat_object is not None: self.set_stat( name=name, data=mlops_stat_object, model_id=model_id, # type of stat will be time series by default category=category, timestamp=timestamp, **kwargs) else: error = "{} predefined stat cannot be output as error happened in creating mlops stat object from {}" \ .format(name, data) raise MLOpsStatisticsException(error)
def get_mlops_classification_report_stat_object(**kwargs): """ Method creates MLOps table value stat object from classification report string. It is not recommended to access this method without understanding single value data structure that it is returning. :param kwargs: classification report string. :return: Table Value stat object which has classification report embedded inside """ cr = kwargs.get('data', None) if cr is not None: if isinstance(cr, string_types): try: array_report = list() for row in cr.split("\n"): parsed_row = [x for x in row.split(" ") if len(x) > 0] if len(parsed_row) > 0: array_report.append(parsed_row) first_header_should_be = [ 'precision', 'recall', 'f1-score', 'support' ] table_object, category = MLStatObjectCreator \ .get_table_value_stat_object(name=ClassificationMetrics.CLASSIFICATION_REPORT.value, list_2d=array_report, match_header_pattern=first_header_should_be) return table_object, category except Exception as e: raise MLOpsStatisticsException( "error happened while outputting classification report as table. Got classification string {}.\n error: {}" .format(cr, e)) else: raise MLOpsStatisticsException( "type of classification should be of string, but received {}" .format(type(cr))) else: raise MLOpsStatisticsException \ ("cr object for outputting classification report cannot be None.")