https://github.com/smac-group/pcoqs
https://github.com/smac-group/pcoqs
Last synced: 12 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/smac-group/pcoqs
- Owner: SMAC-Group
- License: gpl-3.0
- Created: 2025-07-15T21:00:45.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-07-15T22:48:09.000Z (about 1 year ago)
- Last Synced: 2025-07-16T19:31:04.859Z (about 1 year ago)
- Language: R
- Size: 1.61 MB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
README
---
title: "pcoqs"
output: github_document
---

**Differentially Private Conformal Prediction**
An R package for producing differentially private interval and set-valued predictions for regression and classification.
---
## ๐ Overview
`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
---
## ๐งช Installation
```r
# Install from GitHub (requires devtools)
devtools::install_github("SMAC-Group/pcoqs")
```
---
## ๐ Quick Start
### Regression Example
```r
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)
```
### Classification Example
```r
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)
```
---
## ๐ Documentation
See function documentation using `?pcoqs`, `?priv_quant`, and `?noisy_rc` once installed.
---
## ๐ก๏ธ License
MIT ยฉ Roberto Molinari
---
## ๐ฆ Peacocks for Privacy
Because statistical elegance deserves visual elegance.