mlm_insights.core.metrics.interfaces package

Submodules

mlm_insights.core.metrics.interfaces.dataset_metric_base module

class mlm_insights.core.metrics.interfaces.dataset_metric_base.DatasetMetricBase(config: ~typing.Dict[str, ~mlm_insights.constants.definitions.ConfigParameter] = <factory>)

Bases: ABC

Abstract Base Class for defining an Insights Dataset Metric. Dataset Metric is a metric applicable at the Dataset level. Metric-subclasses must override get_result method to produce the computed value of a Metric

compute(dataset: DataFrame, **kwargs: Any) None

Calculate the metric value(s) from the passed DataFrame , set the internal state with the value(s). When a metric is being computed for a partitioned data set, this method is invoked for each partition. Write logic required to derive the metric value in this method for that specific partition

Parameters

dataset : pd.DataFrame DataFrame object for either the entire dataset or a partition on which a Metric is being computed

config: Dict[str, ConfigParameter]
abstract classmethod create(config: Dict[str, ConfigParameter] | None = None, **kwargs: Any) DatasetMetricBase

Factory Method to create an object. The configuration will be available in config.

Returns

MetricBase

An Instance of MetricBase.

classmethod do_deserialize(metric_message: MetricMessage) DatasetMetricBase
do_serialize() MetricMessage

Method to do metric serialization. It handles both OOB and custom serialization of metric

Returns

MetricMessage protobuf message

get_config() Dict[str, ConfigParameter]
classmethod get_name() str
get_required_shareable_dataset_components(**kwargs: Any) List[SDCMetaData]

Returns the Shareable Dataset Components that a Metric requires to compute its state and values Metrics which do not require SDC need not override this property

Returns

List of SDCMetaData. Each SDCMetaData must contain the klass attribute which points to the SDC class

get_required_shareable_feature_components(**kwargs: Any) Dict[str, List[SFCMetaData]]

Returns the Shareable Feature Components that a Metric requires to compute its state and values Metrics which do not require SFC need not override this property

Returns

Dict where feature_name as key and List of SFCMetadata as value. Each SFCMetadata must contain the klass attribute which points to the SFC class

abstract get_result(**kwargs: Any) Dict[str, Any]

Returns the computed value of the metric

Returns

Dict[str, Any]: Dictionary with key as string and value as any metric property.

get_standard_metric_result(**kwargs: Any) StandardMetricResult

This method returns metric output in standard format.

Returns

StandardMetricResult

merge(other_metric: DatasetMetricBase, **kwargs: Any) DatasetMetricBase

Merge the other metric with the current metric and return a new instance of metric. Use this method to merge the states of the 2 metrics to produce a statistically-correctly state Note: you should not mutate the current metric but create a new instance.

Parameters

other_metric : DatasetMetricBase The second metric which the current metric is being merged with

Returns

DatasetMetricBase: New, merged DatasetMetricBase instance

set_config(config: Dict[str, ConfigParameter]) DatasetMetricBase

mlm_insights.core.metrics.interfaces.metric_base module

class mlm_insights.core.metrics.interfaces.metric_base.MetricBase(config: ~typing.Dict[str, ~mlm_insights.constants.definitions.ConfigParameter] = <factory>)

Bases: ABC

Abstract Base Class for defining an Insights Metric. Metric-subclasses must override get_result method to produce the computed value of a Metric

compute(column: Series, **kwargs: Any) None

Calculate the metric value(s) from the passed series object, set the internal state with the value(s). When a metric is being computed for a partitioned data set, this method is invoked for each partition. Write logic required to derive the metric value in this method for that specific partition Shareable Feature Component(s) can be accessed using kwargs

Parameters

column : pd.Series Series object for a Feature on which a Metric is being computed

config: Dict[str, ConfigParameter]
abstract classmethod create(config: Dict[str, ConfigParameter] | None = None) MetricBase

Factory Method to create an object. The configuration will be available in config.

Returns

MetricBase

An Instance of MetricBase.

classmethod do_deserialize(metric_message: MetricMessage) MetricBase
do_serialize() MetricMessage

Method to do metric serialization. It handles both OOB and custom serialization of metric

Returns

MetricMessage protobuf message

get_config() Dict[str, ConfigParameter]
classmethod get_name() str
get_required_shareable_feature_components() List[SFCMetaData]

Returns the Shareable Feature Components that a Metric requires to compute its state and values Metrics which do not require SFC need not override this property

Returns

List of SFCMetadata. Each SFCMetadata must contain the klass attribute which points to the SFC class

abstract get_result(**kwargs: Any) Dict[str, Any]

Returns the computed value of the metric Shareable Feature Component(s) can be accessed using kwargs

Returns

Dict[str, Any]: Dictionary with key as string and value as any metric property.

get_standard_metric_result(**kwargs: Any) StandardMetricResult

This method returns metric output in standard format.

Returns

StandardMetricResult

classmethod get_supported_variable_types() List[VariableType]

Method to retrieve the list of Feature Variable type supported for the metric

Returns

List of Feature Variable type supported by the metric

merge(other_metric: MetricBase, **kwargs: Any) MetricBase

Merge the other metric with the current metric and return a new instance of metric. Use this method to merge the states of the 2 metrics to produce a statistically-correctly state Note: you should not mutate the current metric but create a new instance. Shareable Feature Component(s) can be accessed using kwargs

Parameters

other_metric : MetricBase The second metric which the current metric is being merged with

Returns

MetricBase: New, merged Metric instance

set_config(config: Dict[str, ConfigParameter]) MetricBase

Module contents