Giter VIP home page Giter VIP logo

Comments (1)

M-Mouhcine avatar M-Mouhcine commented on September 22, 2024

Hi @akshat-suwalka-dream11,

Thanks for the post.

I'm not able to recreate the error. I've tried with synthetic data and your code works fine (see below). Can you give me some pointers to reproduce the problem ?

from sklearn.datasets import make_regression
from sklearn.model_selection import train_test_split
from catboost import CatBoostRegressor
import numpy as np
from deel.puncc.api.prediction import DualPredictor
from deel.puncc.regression import CQR
from deel.puncc.metrics import regression_mean_coverage, regression_sharpness

# Generate a random regression problem
X, y = make_regression(
    n_samples=1000, n_features=4, n_informative=2, random_state=0, shuffle=False
)

# Split data into train and test
X, X_test, y, y_test = train_test_split(X, y, test_size=0.2, random_state=0)

# Split train data into fit and calibration
X_fit, X_calib, y_fit, y_calib = train_test_split(
    X, y, test_size=0.2, random_state=0
)

# reg_low catboost model
param = {
    "loss_function": "Quantile:alpha=0.05",
    "learning_rate": 0.4607417710785185,
    "l2_leaf_reg": 0.03572230525884548,
    "depth": 4,
    "boosting_type": "Plain",
    "bootstrap_type": "MVS",
    "min_data_in_leaf": 8,
}
reg_low = CatBoostRegressor(**param)

# reg_high catboost parameters
param = {
    "loss_function": "Quantile:alpha=0.95",
    "learning_rate": 0.002097382718709981,
    "l2_leaf_reg": 0.07411180923916862,
    "depth": 1,
    "boosting_type": "Plain",
    "bootstrap_type": "Bayesian",
    "min_data_in_leaf": 5,
    "bagging_temperature": 9.119533192831474,
}
reg_high = CatBoostRegressor(**param)

# Dual predictor definition
predictor = DualPredictor(models=[reg_low, reg_high])

# Initialization of CQR conformalizer
crq = CQR(predictor)

# Fitting/calibration
crq.fit(X_fit=X_fit, y_fit=y_fit, X_calib=X_calib, y_calib=y_calib)

# Conformal prediction for alpha = 5%
y_pred, y_pred_lower, y_pred_upper = crq.predict(X_test, alpha=0.05)

# Results
coverage = regression_mean_coverage(y_test, y_pred_lower, y_pred_upper)
width = regression_sharpness(y_pred_lower=y_pred_lower,
y_pred_upper=y_pred_upper)
print(f"Marginal coverage: {np.round(coverage, 2)}")
print(f"Average width: {np.round(width, 2)}")

from puncc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.