Here's a basic example of how you could approach this task. This assumes that your csv files have a column named 'DBWT' that you want to predict and that you have installed the necessary libraries (like catboost and mapie).
import pandas as pd
from catboost import CatBoostRegressor
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder
from mapie.estimators import MapieRegressor
# Load data
train = pd.read_csv('train.csv')
test = pd.read_csv('test.csv')
# Identify categorical columns
cat_cols = train.select_dtypes(include=['object']).columns
# Preprocess categorical columns
label_encoder = LabelEncoder()
for col in cat_cols:
train[col] = label_encoder.fit_transform(train[col].astype(str))
test[col] = label_encoder.transform(test[col].astype(str))
# Identify target column
y_train = train['DBWT']
X_train = train.drop('DBWT', axis=1)
y_test = test['DBWT']
X_test = test.drop('DBWT', axis=1)
# Train model
model = CatBoostRegressor()
model.fit(X_train, y_train, cat_features=cat_cols)
# Wrap the model with MapieRegressor for prediction intervals
mapie = MapieRegressor(model, method="plus")
mapie.fit(X_train, y_train)
# Make predictions and prediction intervals
y_pred, y_pis = mapie.predict(X_test, alpha=0.1)
# Print the first 5 predictions and prediction intervals
for pred, pi_low, pi_upp in zip(y_pred[:5], y_pis[:, 0, :5], y_pis[:, 1, :5]):
print(f"Prediction: {pred}, 90% PI: ({pi_low}, {pi_upp})")
Please note that this is a very basic example and might need adjustments based on the specifics of your data and task. For instance, more sophisticated preprocessing might be necessary for both numerical and categorical data. Also, CatBoostRegressor might need tuning for optimal performance.
You might also want to handle missing data and outliers in your datasets and possibly do some feature engineering to improve the performance of your model.