mlm_insights.core.sdcs.confusion_matrix package

Submodules

mlm_insights.core.sdcs.confusion_matrix.multi_class_confusion_matrix module

class mlm_insights.core.sdcs.confusion_matrix.multi_class_confusion_matrix.ConfusionMatrixCounts(true_positive_counts: numpy.ndarray[Any, numpy.dtype[numpy.int32]], false_positive_counts: numpy.ndarray[Any, numpy.dtype[numpy.int32]], true_negative_counts: numpy.ndarray[Any, numpy.dtype[numpy.int32]], false_negative_counts: numpy.ndarray[Any, numpy.dtype[numpy.int32]])

Bases: object

false_negative_counts: ndarray[Any, dtype[int32]]
false_positive_counts: ndarray[Any, dtype[int32]]
true_negative_counts: ndarray[Any, dtype[int32]]
true_positive_counts: ndarray[Any, dtype[int32]]
class mlm_insights.core.sdcs.confusion_matrix.multi_class_confusion_matrix.MultiClassConfusionMatrix(class_map: Dict[str, int], matrix: List[List[int]])

Bases: object

This class stores the confusion matrix and provides simple APIs.

class_map: Dict[str, int] = Field(name=None,type=None,default=<dataclasses._MISSING_TYPE object>,default_factory=<class 'dict'>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=None)
get_average_by_weights(numerator: Any, denominator: ndarray[Any, dtype[int32]]) Any

Helper method to get the weighted average

Parameter

  • numerator: Any
    • Numerator array

  • denominator: npt.NDArray[np.int32]
    • Denominator array

Returns

Any: Weighted average

get_classes() List[str]

Get the list of the classes in confusion matrix

Returns

List[str]:
  • A list of string representing the classes used in confusion matrix. The classes will be sorted in lexicographical order.

get_counts() ConfusionMatrixCounts

Get True Positive, False Positive, True Negative, False Negative per class.

Returns

ConfusionMatrixCounts

An object that contain TP, FP, TN, and FN per class.

get_encoded_value(label: str | int) int
Get the encoded value of a class label. The returned value represents the index of class label in confusion matrix.

Returns

int: Index of class label.

get_false_negative_counts() ndarray[Any, dtype[int32]]

This method returns False Negative (FN) count per class.

Returns

npt.NDArray

One dimensional numpy array contains the FN per class

get_false_positive_counts() ndarray[Any, dtype[int32]]

This method returns False Positive (FP) count per class.

Returns

npt.NDArray

One dimensional numpy array contains the FP per class

get_number_of_classes() int

Get the total count of the classes in confusion matrix

Returns

int

The total count of the classes in confusion matrix

get_precision_scores_per_class() Any

Get the Precision score per class.

Returns

Any: List of precision score for each class

get_recall_scores_per_class() Any

Get the Recall score per class.

Returns

Any: List of recall score for each class

get_true_negative_counts() ndarray[Any, dtype[int32]]

This method returns True Negative (TN) count per class.

Returns

npt.NDArray

One dimensional numpy array contains the TN per class

get_true_positive_counts() ndarray[Any, dtype[int32]]

This method returns True Positive (TP) count per class.

Returns

npt.NDArray

One dimensional numpy array contains the TP per class

is_binary_classes() bool
matrix: ndarray[Any, dtype[int32]]

mlm_insights.core.sdcs.confusion_matrix.multi_threshold_metric_summary module

https://github.com/scikit-learn/scikit-learn/blob/main/COPYING

BSD 3-Clause License

Copyright (c) 2007-2023 The scikit-learn developers. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  • Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

class mlm_insights.core.sdcs.confusion_matrix.multi_threshold_metric_summary.MultiThresholdMetricSummary(tp: ndarray[Any, dtype[Any]], fp: ndarray[Any, dtype[Any]], tn: ndarray[Any, dtype[Any]], fn: ndarray[Any, dtype[Any]], thresholds: ndarray[Any, dtype[Any]])

Bases: object

Store Required multi threshold metrics.

tp: True Positive for multiple thresholds. fp: False Positive for multiple thresholds. tn: True Negative for multiple thresholds. fn: False Negative for multiple thresholds. thresholds: Thresholds.

fn: ndarray[Any, dtype[Any]]
fp: ndarray[Any, dtype[Any]]
get_precision_recall_curve() Tuple[ndarray[Any, dtype[Any]], ndarray[Any, dtype[Any]], ndarray[Any, dtype[Any]]]

Compute precision-recall pairs for different probability thresholds.

Part of the implementation is taken from sklearn: https://github.com/scikit-learn/scikit-learn/blob/main/sklearn/metrics/_ranking.py Returns

predictions with score >= thresholds[i] and the last element is 1.

recallndarray of shape (n_thresholds + 1,)

Decreasing recall values such that element i is the recall of predictions with score >= thresholds[i] and the last element is 0.

thresholdsndarray of shape (n_thresholds,)

Increasing thresholds on the decision function used to compute precision and recall.

get_roc_curve() Tuple[ndarray[Any, dtype[Any]], ndarray[Any, dtype[Any]], ndarray[Any, dtype[Any]]]

Compute Receiver operating characteristic (ROC).

Part of the implementation is taken from sklearn: https://github.com/scikit-learn/scikit-learn/blob/main/sklearn/metrics/_ranking.py

Returns

fprndarray of shape (>2,)

Increasing false positive rates such that element i is the false positive rate of predictions with score >= thresholds[i].

tprndarray of shape (>2,)

Increasing true positive rates such that element i is the true positive rate of predictions with score >= thresholds[i].

thresholdsndarray of shape = (n_thresholds,)

Decreasing thresholds on the decision function used to compute fpr and tpr.

thresholds: ndarray[Any, dtype[Any]]
tn: ndarray[Any, dtype[Any]]
tp: ndarray[Any, dtype[Any]]

Module contents