Harriet O’Brien, Vy Tran, Saniyah Khan, Rehinatu Usman
1 Introduction
In this section, we build predictive models to estimate the reimbursement amount based on the engineered features created earlier. Our goal is to evaluate multiple regression models, compare their performance, and identify which algorithm provides the most accurate and stable predictions. We include three models: Linear Regression, Random Forest, and Gradient Boosting; and use standard metrics such as MAE, RMSE, and R^2 for evaluation. We test multiple models to ensure that the strong baseline performance is not accidental and to confirm whether more flexible models offer any measurable improvement.
2 Load Data
# Basic set upimport pandas as pdimport numpy as npfrom sklearn.model_selection import train_test_splitfrom sklearn.metrics import mean_absolute_error, mean_squared_error, r2_scorefrom sklearn.linear_model import LinearRegressionfrom sklearn.ensemble import RandomForestRegressorfrom sklearn.ensemble import GradientBoostingRegressor# Load processed features features = pd.read_csv("../data/features_processed.csv")# Quick check to ensure the dataset loaded correctlyfeatures.head()features.shape
(1000, 11)
3 Train-Test Split
We predict the original reimbursement amount using the engineered features.
# Split the dataset into training and testing sets# We predict 'reimbursement_amount' using the engineered features.X = features.drop(columns=["reimbursement_amount"])y = features["reimbursement_amount"]X_train, X_test, y_train, y_test = train_test_split( X, y, test_size=0.2, random_state=42)
# Linear Regression baseline model# (Executed in terminal to avoid reticulate crash)
4 Baseline Model: Linear Regression
import numpy as npfrom sklearn.linear_model import LinearRegressionfrom sklearn.metrics import mean_absolute_error, mean_squared_error, r2_score# Create and fit the modellr = LinearRegression()lr.fit(X_train, y_train)# Make predictions on the test setlr_preds = lr.predict(X_test)# Evaluate model performancelr_mae = mean_absolute_error(y_test, lr_preds)lr_rmse = np.sqrt(mean_squared_error(y_test, lr_preds))lr_r2 = r2_score(y_test, lr_preds)# Clean formatted outputprint("Linear Regression performance:")print(f" MAE : {lr_mae:.2f}")print(f" RMSE: {lr_rmse:.2f}")print(f" R² : {lr_r2:.3f}")
Linear Regression performance:
MAE : 138.01
RMSE: 167.30
R² : 0.859
Linear Regression provides a simple baseline by modeling a straight-line relationship between features and the target. This helps us understand whether the dataset is linearly predictable before testing more flexible models.
Random Forest performance:
MAE: 45.10
RMSE: 80.62
R²: 0.967
Random Forest uses many decision trees and averages their predictions. This helps reduce variance and capture non-linear patterns that linear models may miss.
Gradient Boosting trains trees sequentially, where each new tree focuses on correcting the errors of the previous ones. This often leads to strong performance on structured datasets.
import matplotlib.pyplot as pltplt.scatter(y_test, rf_preds, alpha=0.6)plt.xlabel("Actual")plt.ylabel("Predicted")plt.title("Random Forest: Actual vs Predicted")plt.grid(True)plt.show()
9 Model Evaluation Summary
All three models demnostrate strong predictive performance, but clear differences emerge when comparing their accuracy and flexibility. Linear Regression performs resonably well as a baseline model, achieving an R^2 of approximately 0.86, but it does not capture the full complexity of the reimbursement data.
The tree-based models, particularly Gradient Boosting, achieve higher accuracy with R^2 values around 0.97 and lower MAE and RMSE. This improvement indicates that the relationship between the engineered features and reimbursement amount is not purely linear and contains meaningful nonlinear patterns.
Random Forest and Gradient Boosting both model these nonlinear relationships effectively. Among them, Gradient Boosting provides the most stable and accurate results, making it the best overall choice for approximating the legacy reimbursement system.
While Linear Regression remains useful as a simple reference model, the performance of Gradient Boosting suggests that a more flexible approach is necessary to reflect the structure and rules embedded in the historical reimbursement data. Interpretability analysis is therefore used in the next section to ensure that the model’s behavior aligns with the expections set.
10 Note on polynomial/interaction features
We briefly considered adding polynomial or interaction terms (for example squared mileage or interactions between miles and receipts). However, the tree-based models already capture nonlinear patterns automatically, and both Random Forest and Gradient Boosting achieve high accuracy eithout requiring additional engineered nonlinear features.
While adding polynomial terms might help Linear Regression slightly, it would also increase model complexity and reduce interpretability. Since the ensemble models already learn these relationships effectively and outperform the linear model, introducing extra polynomial or interaction features was not necessary for achieving strong predictive performance.
11 Export Final Model
import joblib# choose final model (here Gradient boosting due to performance)final_model = gbrjoblib.dump(final_model, "../models/final_model.pkl")print("Model saved as final_model.pkl")