HYPERLATTICES

Logo

Generalized Lattice data-types for Common Lisp, including Algebraic Lattices, Hyperlattices, and Probabilistic Hyperlattices, which intends to follow the packages-as-types convention.

View the Project on GitHub thephoeron/hyperlattices

Evaluation Metrics: ROC Curve

ROC Curve for Evaluating Probabilistic Hyperlattice Models

The ROC (Receiver Operating Characteristic) curve is a graphical representation of the performance of a binary classifier, such as a probabilistic hyperlattice model. The ROC curve plots the true positive rate (TPR) against the false positive rate (FPR) for different threshold values of the classifier. The TPR is the proportion of true positives (correctly classified positive instances) among all positive instances, while the FPR is the proportion of false positives (incorrectly classified negative instances) among all negative instances.

To generate an ROC curve for a probabilistic hyperlattice model, we can vary the threshold value for the predicted probabilities of the positive class, and compute the TPR and FPR for each threshold value. The resulting curve shows how well the model can distinguish between positive and negative instances, and provides a visual representation of the trade-off between sensitivity (TPR) and specificity (1 - FPR) of the model.

The area under the ROC curve (AUC) is a commonly used metric to evaluate the performance of a binary classifier, including probabilistic hyperlattice models. The AUC measures the overall performance of the model, by computing the area under the ROC curve. A perfect classifier would have an AUC of 1.0, while a random classifier would have an AUC of 0.5. A higher AUC indicates a better performance of the model in distinguishing between positive and negative instances.

The ROC curve and AUC can be used to evaluate the performance of a probabilistic hyperlattice model in a binary classification task, and to compare it to other models and baselines. The ROC curve can also be used to select the optimal threshold value for the classifier, depending on the specific application and the trade-off between sensitivity and specificity.

Implementing the ROC Curve for Evaluating Probabilistic Hyperlattice Models in Common Lisp

To compute the ROC curve and AUC for a probabilistic hyperlattice model in Common Lisp, we can follow these steps:

  1. Generate predicted probabilities for the positive class for the test instances using the predict-probabilities function of the hyperlattice model. This function takes as input the test instances and returns the predicted probabilities for each class.

  2. Compute the true positive rate (TPR) and false positive rate (FPR) for each threshold value of the predicted probabilities. This can be done using the compute-tpr-fpr function, which takes as input the predicted probabilities, the true class labels, and the threshold value, and returns the TPR and FPR values.

  3. Plot the TPR against the FPR for each threshold value to generate the ROC curve. This can be done using a plotting library such as gnuplot or cl-plot.

  4. Compute the area under the ROC curve (AUC) using the trapezoidal rule or another numerical integration method. This can be done using the compute-auc function, which takes as input the TPR and FPR values, and returns the AUC value.

Here is an example implementation of these steps in Common Lisp:

;; Step 1: Generate predicted probabilities for the positive class
(defvar *probs* (predict-probabilities hyperlattice-model test-instances))

;; Step 2: Compute TPR and FPR for each threshold value
(defvar *thresholds* (range 0.0 1.0 0.01))
(defvar *tprs* nil)
(defvar *fprs* nil)
(loop for threshold in *thresholds*
      do (let ((tpr-fpr (compute-tpr-fpr *probs* test-labels threshold)))
           (push (first tpr-fpr) *tprs*)
           (push (second tpr-fpr) *fprs*)))

;; Step 3: Plot the ROC curve
(plot (list (cons *fprs* *tprs*)) :title "ROC Curve" :x-label "False Positive Rate" :y-label "True Positive Rate")

;; Step 4: Compute the AUC
(defvar *auc* (compute-auc *tprs* *fprs*))

This code assumes that the hyperlattice model has been trained and that the test instances and labels are available. The range function generates a list of threshold values between 0.0 and 1.0 with a step size of 0.01. The compute-tpr-fpr function computes the TPR and FPR values for a given threshold value, using the positive-class parameter of the hyperlattice model to determine the positive class. The plot function generates a plot of the ROC curve using the gnuplot library. The compute-auc function computes the AUC value using the trapezoidal rule.