Code
import numpy as np
from sklearn.datasets import make_classification
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
# Create synthetic data
X, y = make_classification(
n_samples=2000,
n_features=20,
n_informative=10,
n_redundant=5,
random_state=42,
)
# Split into train, calibration, and test sets
X_train, X_temp, y_train, y_temp = train_test_split(X, y, test_size=0.4, random_state=42)
X_calib, X_test, y_calib, y_test = train_test_split(X_temp, y_temp, test_size=0.5, random_state=42)
print(f"Train: {len(y_train)}, Calibration: {len(y_calib)}, Test: {len(y_test)}")
# Train base model
model = RandomForestClassifier(n_estimators=100, random_state=42)
model.fit(X_train, y_train)Train: 1200, Calibration: 400, Test: 400
RandomForestClassifier(random_state=42)In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.