eval_stats_classification

class ClassificationMetric(name: Optional[str] = None, bounds: Tuple[float, float] = (0, 1), requires_probabilities: Optional[bool] = None)[source]

Bases: sensai.evaluation.eval_stats.eval_stats_base.Metric[ClassificationEvalStats], abc.ABC

__init__(name: Optional[str] = None, bounds: Tuple[float, float] = (0, 1), requires_probabilities: Optional[bool] = None)
Parameters
  • name – the name of the metric; if None use the class’ name attribute

  • bounds – the minimum and maximum values the metric can take on

requires_probabilities = False
compute_value_for_eval_stats(eval_stats: sensai.evaluation.eval_stats.eval_stats_classification.ClassificationEvalStats)
compute_value(y_true: Union[numpy.ndarray, pandas.core.series.Series, pandas.core.frame.DataFrame, list], y_predicted: Union[numpy.ndarray, pandas.core.series.Series, pandas.core.frame.DataFrame, list], y_predicted_class_probabilities: Optional[Union[numpy.ndarray, pandas.core.series.Series, pandas.core.frame.DataFrame, list]] = None)
name: str
class ClassificationMetricAccuracy(name: Optional[str] = None, bounds: Tuple[float, float] = (0, 1), requires_probabilities: Optional[bool] = None)[source]

Bases: sensai.evaluation.eval_stats.eval_stats_classification.ClassificationMetric

name: str = 'accuracy'
class ClassificationMetricBalancedAccuracy(name: Optional[str] = None, bounds: Tuple[float, float] = (0, 1), requires_probabilities: Optional[bool] = None)[source]

Bases: sensai.evaluation.eval_stats.eval_stats_classification.ClassificationMetric

name: str = 'balancedAccuracy'
class ClassificationMetricAccuracyWithoutLabels(*labels: Any, probability_threshold=None, zero_value=0.0)[source]

Bases: sensai.evaluation.eval_stats.eval_stats_classification.ClassificationMetric

Accuracy score with set of data points limited to the ones where the ground truth label is not one of the given labels

__init__(*labels: Any, probability_threshold=None, zero_value=0.0)
Parameters
  • labels – one or more labels which are not to be considered (all data points where the ground truth is one of these labels will be ignored)

  • probability_threshold – a probability threshold: the probability of the most likely class must be at least this value for a data point to be considered in the metric computation (analogous to ClassificationMetricAccuracyMaxProbabilityBeyondThreshold)

  • zero_value – the metric value to assume for the case where the condition never applies (no countable instances without the given label/beyond the given threshold)

get_paired_metrics() List[sensai.evaluation.eval_stats.eval_stats_base.TMetric]

Gets a list of metrics that should be considered together with this metric (e.g. for paired visualisations/plots). The direction of the pairing should be such that if this metric is “x”, the other is “y” for x-y type visualisations.

Returns

a list of metrics

name: str
class ClassificationMetricGeometricMeanOfTrueClassProbability(name: Optional[str] = None, bounds: Tuple[float, float] = (0, 1), requires_probabilities: Optional[bool] = None)[source]

Bases: sensai.evaluation.eval_stats.eval_stats_classification.ClassificationMetric

name: str = 'geoMeanTrueClassProb'
requires_probabilities = True
class ClassificationMetricTopNAccuracy(n: int)[source]

Bases: sensai.evaluation.eval_stats.eval_stats_classification.ClassificationMetric

requires_probabilities = True
__init__(n: int)
Parameters
  • name – the name of the metric; if None use the class’ name attribute

  • bounds – the minimum and maximum values the metric can take on

name: str
class ClassificationMetricAccuracyMaxProbabilityBeyondThreshold(threshold: float, zero_value=0.0)[source]

Bases: sensai.evaluation.eval_stats.eval_stats_classification.ClassificationMetric

Accuracy limited to cases where the probability of the most likely class is at least a given threshold

requires_probabilities = True
__init__(threshold: float, zero_value=0.0)
Parameters
  • threshold – minimum probability of the most likely class

  • zero_value – the value of the metric for the case where the probability of the most likely class never reaches the threshold

get_paired_metrics() List[sensai.evaluation.eval_stats.eval_stats_base.TMetric]

Gets a list of metrics that should be considered together with this metric (e.g. for paired visualisations/plots). The direction of the pairing should be such that if this metric is “x”, the other is “y” for x-y type visualisations.

Returns

a list of metrics

name: str
class ClassificationMetricRelFreqMaxProbabilityBeyondThreshold(threshold: float)[source]

Bases: sensai.evaluation.eval_stats.eval_stats_classification.ClassificationMetric

Relative frequency of cases where the probability of the most likely class is at least a given threshold

requires_probabilities = True
__init__(threshold: float)
Parameters

threshold – minimum probability of the most likely class

name: str
class BinaryClassificationMetric(positive_class_label, name: Optional[str] = None)[source]

Bases: sensai.evaluation.eval_stats.eval_stats_classification.ClassificationMetric, abc.ABC

__init__(positive_class_label, name: Optional[str] = None)
Parameters
  • name – the name of the metric; if None use the class’ name attribute

  • bounds – the minimum and maximum values the metric can take on

name: str
class BinaryClassificationMetricPrecision(positive_class_label)[source]

Bases: sensai.evaluation.eval_stats.eval_stats_classification.BinaryClassificationMetric

name: str = 'precision'
__init__(positive_class_label)
Parameters
  • name – the name of the metric; if None use the class’ name attribute

  • bounds – the minimum and maximum values the metric can take on

get_paired_metrics() List[sensai.evaluation.eval_stats.eval_stats_classification.BinaryClassificationMetric]

Gets a list of metrics that should be considered together with this metric (e.g. for paired visualisations/plots). The direction of the pairing should be such that if this metric is “x”, the other is “y” for x-y type visualisations.

Returns

a list of metrics

class BinaryClassificationMetricRecall(positive_class_label)[source]

Bases: sensai.evaluation.eval_stats.eval_stats_classification.BinaryClassificationMetric

name: str = 'recall'
__init__(positive_class_label)
Parameters
  • name – the name of the metric; if None use the class’ name attribute

  • bounds – the minimum and maximum values the metric can take on

class BinaryClassificationMetricF1Score(positive_class_label)[source]

Bases: sensai.evaluation.eval_stats.eval_stats_classification.BinaryClassificationMetric

name: str = 'F1'
__init__(positive_class_label)
Parameters
  • name – the name of the metric; if None use the class’ name attribute

  • bounds – the minimum and maximum values the metric can take on

class BinaryClassificationMetricRecallForPrecision(precision: float, positive_class_label, zero_value=0.0)[source]

Bases: sensai.evaluation.eval_stats.eval_stats_classification.BinaryClassificationMetric

Computes the maximum recall that can be achieved (by varying the decision threshold) in cases where at least the given precision is reached. The given precision may not be achievable at all, in which case the metric value is zeroValue.

__init__(precision: float, positive_class_label, zero_value=0.0)
Parameters
  • precision – the minimum precision value that must be reached

  • positive_class_label – the positive class label

  • zero_value – the value to return for the case where the minimum precision is never reached

compute_value_for_eval_stats(eval_stats: sensai.evaluation.eval_stats.eval_stats_classification.ClassificationEvalStats)
name: str
class BinaryClassificationMetricPrecisionThreshold(threshold: float, positive_class_label: Any, zero_value=0.0)[source]

Bases: sensai.evaluation.eval_stats.eval_stats_classification.BinaryClassificationMetric

Precision for the case where predictions are considered “positive” if predicted probability of the positive class is beyond the given threshold

requires_probabilities = True
__init__(threshold: float, positive_class_label: Any, zero_value=0.0)
Parameters
  • threshold – the minimum predicted probability of the positive class for the prediction to be considered “positive”

  • zero_value – the value of the metric for the case where a positive class probability beyond the threshold is never predicted (denominator = 0)

get_paired_metrics() List[sensai.evaluation.eval_stats.eval_stats_classification.BinaryClassificationMetric]

Gets a list of metrics that should be considered together with this metric (e.g. for paired visualisations/plots). The direction of the pairing should be such that if this metric is “x”, the other is “y” for x-y type visualisations.

Returns

a list of metrics

name: str
class BinaryClassificationMetricRecallThreshold(threshold: float, positive_class_label: Any, zero_value=0.0)[source]

Bases: sensai.evaluation.eval_stats.eval_stats_classification.BinaryClassificationMetric

Recall for the case where predictions are considered “positive” if predicted probability of the positive class is beyond the given threshold

requires_probabilities = True
__init__(threshold: float, positive_class_label: Any, zero_value=0.0)
Parameters
  • threshold – the minimum predicted probability of the positive class for the prediction to be considered “positive”

  • zero_value – the value of the metric for the case where there are no positive instances in the data set (denominator = 0)

name: str
create_default_binary_classification_metrics(positive_class_label: Any) List[sensai.evaluation.eval_stats.eval_stats_classification.BinaryClassificationMetric][source]
class ClassificationEvalStats(y_predicted: Optional[Union[numpy.ndarray, pandas.core.series.Series, pandas.core.frame.DataFrame, list]] = None, y_true: Optional[Union[numpy.ndarray, pandas.core.series.Series, pandas.core.frame.DataFrame, list]] = None, y_predicted_class_probabilities: Optional[pandas.core.frame.DataFrame] = None, labels: Optional[Union[numpy.ndarray, pandas.core.series.Series, pandas.core.frame.DataFrame, list]] = None, metrics: Optional[Sequence[sensai.evaluation.eval_stats.eval_stats_classification.ClassificationMetric]] = None, additional_metrics: Optional[Sequence[sensai.evaluation.eval_stats.eval_stats_classification.ClassificationMetric]] = None, binary_positive_label=('__guess',))[source]

Bases: sensai.evaluation.eval_stats.eval_stats_base.PredictionEvalStats[ClassificationMetric]

__init__(y_predicted: Optional[Union[numpy.ndarray, pandas.core.series.Series, pandas.core.frame.DataFrame, list]] = None, y_true: Optional[Union[numpy.ndarray, pandas.core.series.Series, pandas.core.frame.DataFrame, list]] = None, y_predicted_class_probabilities: Optional[pandas.core.frame.DataFrame] = None, labels: Optional[Union[numpy.ndarray, pandas.core.series.Series, pandas.core.frame.DataFrame, list]] = None, metrics: Optional[Sequence[sensai.evaluation.eval_stats.eval_stats_classification.ClassificationMetric]] = None, additional_metrics: Optional[Sequence[sensai.evaluation.eval_stats.eval_stats_classification.ClassificationMetric]] = None, binary_positive_label=('__guess',))
Parameters
  • y_predicted – the predicted class labels

  • y_true – the true class labels

  • y_predicted_class_probabilities – a data frame whose columns are the class labels and whose values are probabilities

  • labels – the list of class labels

  • metrics – the metrics to compute for evaluation; if None, use default metrics (see DEFAULT_MULTICLASS_CLASSIFICATION_METRICS and create_default_binary_classification_metrics())

  • additional_metrics – the metrics to additionally compute

  • binary_positive_label – the label of the positive class for the case where it is a binary classification, adding further binary metrics by default; if GUESS (default), check labels (if length 2) for occurrence of one of BINARY_CLASSIFICATION_POSITIVE_LABEL_CANDIDATES in the respective order and use the first one found (if any); if None, treat the problem as non-binary, regardless of the labels being used.

get_confusion_matrix() sensai.evaluation.eval_stats.eval_stats_classification.ConfusionMatrix
get_binary_classification_probability_threshold_variation_data() sensai.evaluation.eval_stats.eval_stats_classification.BinaryClassificationProbabilityThresholdVariationData
get_accuracy()
metrics_dict() Dict[str, float]

Computes all metrics

Returns

a dictionary mapping metric names to values

get_misclassified_indices() List[int]
plot_confusion_matrix(normalize=True, title_add: Optional[str] = None) matplotlib.figure.Figure
plot_precision_recall_curve(title_add: Optional[str] = None) matplotlib.figure.Figure
class ClassificationEvalStatsCollection(eval_stats_list: List[sensai.evaluation.eval_stats.eval_stats_classification.ClassificationEvalStats])[source]

Bases: sensai.evaluation.eval_stats.eval_stats_base.EvalStatsCollection[sensai.evaluation.eval_stats.eval_stats_classification.ClassificationEvalStats, sensai.evaluation.eval_stats.eval_stats_classification.ClassificationMetric]

__init__(eval_stats_list: List[sensai.evaluation.eval_stats.eval_stats_classification.ClassificationEvalStats])
get_combined_eval_stats() sensai.evaluation.eval_stats.eval_stats_classification.ClassificationEvalStats

Combines the data from all contained EvalStats objects into a single object. Note that this is only possible if all EvalStats objects use the same set of class labels.

Returns

an EvalStats object that combines the data from all contained EvalStats objects

class ConfusionMatrix(y_true: Union[numpy.ndarray, pandas.core.series.Series, pandas.core.frame.DataFrame, list], y_predicted: Union[numpy.ndarray, pandas.core.series.Series, pandas.core.frame.DataFrame, list])[source]

Bases: object

__init__(y_true: Union[numpy.ndarray, pandas.core.series.Series, pandas.core.frame.DataFrame, list], y_predicted: Union[numpy.ndarray, pandas.core.series.Series, pandas.core.frame.DataFrame, list])
plot(normalize: bool = True, title_add: Optional[str] = None)
class BinaryClassificationCounts(is_positive_prediction: Sequence[bool], is_positive_ground_truth: Sequence[bool], zero_denominator_metric_value: float = 0.0)[source]

Bases: object

__init__(is_positive_prediction: Sequence[bool], is_positive_ground_truth: Sequence[bool], zero_denominator_metric_value: float = 0.0)
Parameters
  • is_positive_prediction – the sequence of Booleans indicating whether the model predicted the positive class

  • is_positive_ground_truth – the sequence of Booleans indicating whether the true class is the positive class

  • zero_denominator_metric_value – the result to return for metrics such as precision and recall in case the denominator is zero (i.e. zero counted cases)

classmethod from_probability_threshold(probabilities: Sequence[float], threshold: float, is_positive_ground_truth: Sequence[bool]) sensai.evaluation.eval_stats.eval_stats_classification.BinaryClassificationCounts
classmethod from_eval_stats(eval_stats: sensai.evaluation.eval_stats.eval_stats_classification.ClassificationEvalStats, threshold=0.5) sensai.evaluation.eval_stats.eval_stats_classification.BinaryClassificationCounts
get_precision()
get_recall()
get_f1()
get_rel_freq_positive()
class BinaryClassificationProbabilityThresholdVariationData(eval_stats: sensai.evaluation.eval_stats.eval_stats_classification.ClassificationEvalStats)[source]

Bases: object

__init__(eval_stats: sensai.evaluation.eval_stats.eval_stats_classification.ClassificationEvalStats)
plot_precision_recall(subtitle=None) matplotlib.figure.Figure
plot_counts(subtitle=None)
class ClassificationEvalStatsPlot(*args, **kwds)[source]

Bases: sensai.evaluation.eval_stats.eval_stats_base.EvalStatsPlot[sensai.evaluation.eval_stats.eval_stats_classification.ClassificationEvalStats], abc.ABC

class ClassificationEvalStatsPlotConfusionMatrix(normalise=True)[source]

Bases: sensai.evaluation.eval_stats.eval_stats_classification.ClassificationEvalStatsPlot

__init__(normalise=True)
create_figure(eval_stats: sensai.evaluation.eval_stats.eval_stats_classification.ClassificationEvalStats, subtitle: str) matplotlib.figure.Figure
Parameters
  • eval_stats – the evaluation stats from which to generate the plot

  • subtitle – the plot’s subtitle

Returns

the figure or None if this plot is not applicable/cannot be created

class ClassificationEvalStatsPlotPrecisionRecall(*args, **kwds)[source]

Bases: sensai.evaluation.eval_stats.eval_stats_classification.ClassificationEvalStatsPlot

create_figure(eval_stats: sensai.evaluation.eval_stats.eval_stats_classification.ClassificationEvalStats, subtitle: str) Optional[matplotlib.figure.Figure]
Parameters
  • eval_stats – the evaluation stats from which to generate the plot

  • subtitle – the plot’s subtitle

Returns

the figure or None if this plot is not applicable/cannot be created

class ClassificationEvalStatsPlotProbabilityThresholdPrecisionRecall(*args, **kwds)[source]

Bases: sensai.evaluation.eval_stats.eval_stats_classification.ClassificationEvalStatsPlot

create_figure(eval_stats: sensai.evaluation.eval_stats.eval_stats_classification.ClassificationEvalStats, subtitle: str) Optional[matplotlib.figure.Figure]
Parameters
  • eval_stats – the evaluation stats from which to generate the plot

  • subtitle – the plot’s subtitle

Returns

the figure or None if this plot is not applicable/cannot be created

class ClassificationEvalStatsPlotProbabilityThresholdCounts(*args, **kwds)[source]

Bases: sensai.evaluation.eval_stats.eval_stats_classification.ClassificationEvalStatsPlot

create_figure(eval_stats: sensai.evaluation.eval_stats.eval_stats_classification.ClassificationEvalStats, subtitle: str) Optional[matplotlib.figure.Figure]
Parameters
  • eval_stats – the evaluation stats from which to generate the plot

  • subtitle – the plot’s subtitle

Returns

the figure or None if this plot is not applicable/cannot be created