Skip to content

Instantly share code, notes, and snippets.

Embed
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 = data.data, data.target
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()
clf.fit(X_train, 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)
cfp.fit(X_test, 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
You can’t perform that action at this time.