Package 'conformalpvalue'

Title: Computes Conformal p-Values
Description: Computes marginal conformal p-values using conformal prediction in binary classification tasks. Conformal prediction is a framework that augments machine learning algorithms with a measure of uncertainty, in the form of prediction regions that attain a user-specified level of confidence. This package specifically focuses on providing conformal p-values that can be used to assess the confidence of the classification predictions. For more details, see Tyagi and Guo (2023) <https://proceedings.mlr.press/v204/tyagi23a.html>.
Authors: Chhavi Tyagi [aut, cre]
Maintainer: Chhavi Tyagi <[email protected]>
License: MIT + file LICENSE
Version: 0.1.0
Built: 2025-03-08 03:30:12 UTC
Source: https://github.com/cran/conformalpvalue

Help Index


Conformal P-values Calculation

Description

This function calculates conformal p-values based of binary class labels for test data.

Usage

conformal_pvalues(train_data, calib_data, test_data, target_col, method)

Arguments

train_data

A data frame containing the training data with the target variable.

calib_data

A data frame containing the calibration data with the target variable.

test_data

A data frame containing the test data.

target_col

The name of the target variable column.

method

A character string specifying the classification method to use. Options are 'naiveBayes', 'svm', and 'glm'.

This function trains a Naive Bayes classifier, computes non-conformity scores on the calibration data and test data, and calculates conformal p-values of both classes "0" and "1" using the conformal prediction for a binary classification problem.

Value

A matrix containing p-values for each test case and class.

Examples

# Create dummy train_data, calib_data, and test_data
train_data <- data.frame(
  x1 = as.numeric(rnorm(50, 1, 2)),
  x2 = as.numeric(rnorm(50, 2.5, 3)),
  target = as.factor(rbinom(50, 1, 0.5))
)
calib_data <- data.frame(
  x1 = as.numeric(rnorm(50, 1, 2)),
  x2 = as.numeric(rnorm(50, 2.5, 3)),
  target = as.factor(rbinom(50, 1, 0.5))
)
test_data <- data.frame(
  x1 = as.numeric(rnorm(50, 1, 2)),
  x2 = as.numeric(rnorm(50, 2.5, 3))
)
p_values <- conformal_pvalues(train_data, calib_data, test_data, target="target", method="svm")