Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from conformal.conformal_predictor import InductiveConformalPredictor
data = load_digits()
X, y =,
alpha = 0.05
seed = 41
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3,
stratify=y, random_state=seed)
# Fitting classifier to train data
clf = LogisticRegression(), y_train)
# Further splitting of data into test and calibration
X_test, X_calib, y_test, y_calib = train_test_split(X_test, y_test, test_size=0.5,
stratify=y_test, random_state=seed)
# Fitting conformal predictor
cfp = InductiveConformalPredictor(predictor=clf), y_test)
# Scoring of classifier and conformal predictor
y_test_conf = cfp.predict(X_calib, alpha=alpha)
y_pred = clf.predict(X_calib)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment