Skip to content

Instantly share code, notes, and snippets.

@mjesusugarte
Created March 5, 2021 12:57
Show Gist options
  • Save mjesusugarte/993fba44f739e80d8cfac5e7941958b3 to your computer and use it in GitHub Desktop.
Save mjesusugarte/993fba44f739e80d8cfac5e7941958b3 to your computer and use it in GitHub Desktop.
from nonconformist.cp import IcpRegressor
from nonconformist.cp import IcpClassifier
from nonconformist.nc import NcFactory
import lightgbm as lgbm
# Create the underlying model
model = lgbm.LGBMRegressor()
# Default nonconformity measure
nc = NcFactory.create_nc(model)
# Inductive conformal regressor
icp = IcpRegressor(nc)
# Fit the ICP using the proper training set
icp.fit(x_train, y_train)
# Calibrate the ICP using the calibration set
icp.calibrate(x_cal, y_cal)
# Desired coverage
confidence = 0.8
# Produce predictions for the test set
prediction = icp.predict(x_test, significance=(1-confidence))
lower_b = prediction[:, 0]
upper_b = prediction[:, 1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment