mlnext.score.ConfusionMatrix#
- class mlnext.score.ConfusionMatrix(TP: int = 0, FN: int = 0, TN: int = 0, FP: int = 0, DA: int = 0, TA: int = 0)[source]#
Bases:
object
ConfusionMatrix
is a confusion matrix for a binary classification problem. See https://en.wikipedia.org/wiki/Confusion_matrix.- Parameters:
TP (int) – true positives, the number of samples from the positive class that are correctly assigned to the positive class.
FN (int) – false negatives, the number of samples from the positive class that are wrongly assigned to the negative class.
TN (int) – true negatives, the number of samples from the negative class that are correctly assigned to negative class.
FP (int) – true negatives, the number of samples from the negative class that are wrongly assigned to the positive class.
DA (int) – detected anomalies segments by at least one point.
TA (int) – total number of anomaly segments.
Methods
Returns all metrics.
Attributes
DA
FN
FP
TA
TN
TP
Calculates the accuracy
(TP + TN) / (TP + TN + FP + FN)
.Calculates the F1-Score
2 * (precision * recall) / (precision + recall)
.Calculates the precision
TP / (TP + FP)
.Calculates the recall
TP / (TP + FN)
.Calculates the percentage of detected anomaly segments.
- __add__(cm: ConfusionMatrix) ConfusionMatrix [source]#
Overrides the add operator.
- Returns:
Returns a new matrix with feature-wise added values.
- Return type:
- property accuracy: float#
Calculates the accuracy
(TP + TN) / (TP + TN + FP + FN)
.- Returns:
Returns the accuracy.
- Return type:
np.ndarray
- property f1: float#
Calculates the F1-Score
2 * (precision * recall) / (precision + recall)
.- Returns:
Returns the F1-score.
- Return type:
np.ndarray
- metrics() Dict[str, float] [source]#
Returns all metrics.
- Returns:
Returns an mapping of all performance metrics.
- Return type:
T.Dict[str, float]
- property precision: float#
Calculates the precision
TP / (TP + FP)
.- Returns:
Returns the precision.
- Return type:
float
- property recall: float#
Calculates the recall
TP / (TP + FN)
.- Returns:
Returns the recall.
- Return type:
float
- property recall_anomalies: float#
Calculates the percentage of detected anomaly segments.
- Returns:
Returns the percentage of detected segments.
- Return type:
float