donlnz / nonconformist

Python implementation of the conformal prediction framework.
MIT License
436 stars 96 forks source link

Not able to recognize classes after fitting #41

Open sanket1105 opened 1 year ago

sanket1105 commented 1 year ago

What's wrong with this code? Given my "y_train" has 2 unique values: 0 and 1.

Output: Unique values in target variable: 2 Classes in IcpClassifier before fit: None Classes in IcpClassifier after fit: None

`from nonconformist.icp import IcpClassifier from nonconformist.nc import ClassifierNc, MarginErrFunc import catboost import numpy as np

Create a CatBoost classifier

model = catboost.CatBoostClassifier(iterations=100, loss_function='Logloss', depth=5, eval_metric='Logloss', random_seed=42, learning_rate=0.1, leaf_estimation_iterations=10, verbose=False)

Initialing the model

model.fit(train_X, train_y) nc = ClassifierNc(model) icp = IcpClassifier(nc)

Print information about the target variable

print("Unique values in target variable:", train_y.nunique())

Print classes in IcpClassifier before fit

print("Classes in IcpClassifier before fit:", icp.classes)

Fit the IcpClassifier with the training data

icp.fit(train_X, train_y)

Print classes in IcpClassifier after fit

print("Classes in IcpClassifier after fit:", icp.classes)

Obtain prediction intervals for the test set

prediction_intervals = icp.predict(test_X, significance=0.05) `