class

Logarithm::ModelEvaluator

Inherits Reference < Object

Model evaluation metrics and utilities.

This class provides comprehensive evaluation metrics for anomaly detection models, including precision, recall, F1-score, AUC-ROC, and confusion matrix analysis.

Instance methods

auc_roc(predictions : Array(Float64), labels : Array(Int32)) : Float64

Calculate AUC-ROC using trapezoidal rule

Source
confusion_matrix(predictions : Array(Float64), labels : Array(Int32), threshold : Float64 = 0.5) : Matrix(Int32)

Generate confusion matrix

Source
evaluate(model : AbstractModel, test_data : Array(Tensor), threshold : Float64 = 0.5) : Hash(String, Float64)

Evaluate model performance on test data.

Parameters:

  • model: The trained model to evaluate
  • test_data: Array of test tensors
  • threshold: Anomaly threshold (0.0 to 1.0)

Returns: Hash with evaluation metrics

Source
f1_score(predictions : Array(Float64), labels : Array(Int32), threshold : Float64 = 0.5) : Float64

Calculate F1 score: 2 * (precision * recall) / (precision + recall)

Source
find_optimal_threshold(predictions : Array(Float64), labels : Array(Int32)) : Float64

Find optimal threshold using Youden's J statistic

Source
precision(predictions : Array(Float64), labels : Array(Int32), threshold : Float64 = 0.5) : Float64

Calculate precision: TP / (TP + FP)

Source
precision_recall_curve(predictions : Array(Float64), labels : Array(Int32)) : Hash(String, Array(Float64))

Calculate precision-recall curve

Source
recall(predictions : Array(Float64), labels : Array(Int32), threshold : Float64 = 0.5) : Float64

Calculate recall: TP / (TP + FN)

Source
roc_curve(predictions : Array(Float64), labels : Array(Int32)) : Hash(String, Array(Float64))

Calculate ROC curve

Source