Differentially Private Conformal Prediction
An R package for producing differentially private interval and
set-valued predictions for regression and classification.
pcoqs provides functionality for conformal prediction enhanced with
differential privacy. It supports:
- Regression prediction intervals
- Classification prediction sets (multiclass + binary)
- Custom nonconformity scores and model/predict wrappers
- Gaussian noise injection for private quantile estimation
# Install from GitHub (requires devtools)
devtools::install_github("SMAC-Group/pcoqs")library(pcoqs)
set.seed(123)
X <- matrix(rnorm(100 * 3), ncol = 3)
Y <- X %*% c(1, -2, 1) + rnorm(100)
model <- lm(Y ~ ., data = data.frame(Y, X))
result <- pcoqs(model, X, Y, X, alpha = 0.1, rho = 1.0)
head(result$output)library(pcoqs)
library(nnet)
set.seed(456)
X <- matrix(rnorm(200 * 3), ncol = 3)
probs <- t(apply(X, 1, function(row) {
logits <- c(0, row[1], -row[2])
exp_logits <- exp(logits)
exp_logits / sum(exp_logits)
}))
Y <- apply(probs, 1, function(p) sample(1:3, 1, prob = p))
model <- multinom(as.factor(Y) ~ ., data = data.frame(Y = as.factor(Y), X), trace = FALSE)
result <- pcoqs(
model, X, Y, X,
alpha = 0.1, rho = 1.0,
predict_fun = function(model, X, ...) predict(model, data.frame(X), type = "probs"),
score_fun = function(y, probs) sapply(1:length(y), function(i) 1 - probs[i, y[i]]),
output_fun = function(probs, q) {
data.frame(predicted_set = apply(probs, 1, function(p) paste(which(p >= 1 - q), collapse = ",")))
},
lower_bound = 0, upper_bound = 1
)
head(result$output)The methods implemented in this package are based on the paper:
Differentially Private Conformal Prediction via Quantile Binary Search
Ogonnaya Michael Romanus and Roberto Molinari
Transactions on Machine Learning Research (TMLR)
All Python code used to generate the experimental results in the paper (including simulations and real-data experiments) is available in the repository under the folder:
paper_codes/
This folder is provided for full reproducibility of the empirical results reported in the manuscript.
See function documentation using ?pcoqs, ?priv_quant, and
?noisy_rc once installed.
MIT © Roberto Molinari
