Skip to content

Instantly share code, notes, and snippets.

@dsleo
Created July 14, 2020 21:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dsleo/3a860e009b3b987dec4f0ad048bcbc78 to your computer and use it in GitHub Desktop.
Save dsleo/3a860e009b3b987dec4f0ad048bcbc78 to your computer and use it in GitHub Desktop.
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