An End-to-End Machine Learning Pipeline
Presented by: Jayan Gupta
Imports the necessary libraries and loads the dataset from the CSV file.
Checks the structural matrix of the dataset and confirms there are absolutely zero missing values.
Reveals extreme class imbalance. A model guessing 'Legitimate' every time would achieve 99.82% accuracy, making raw metrics highly deceptive.
Splits the dataset and calculates summary statistics. Fraudulent transactions have a higher average amount but are capped at lower maximums.
Visualizes transactions over time. Fraud occurs consistently across all hours, bypassing standard diurnal patterns observed in legitimate activity.
PCA features (V1-V28) show zero correlation with each other. Noticeable negative correlations exist between the Fraud Class and specific features like V14, V17.
Splits the dataset into 80% training and 20% testing sets. The 'stratify' parameter ensures the extreme class imbalance is preserved in both sets.
Scales numerical features (like Amount) to have a mean of 0 and variance of 1, preventing features with larger scales from dominating the distance metrics.
Trains a K-Nearest Neighbors classifier on a subset of the data. It maps multidimensional spatial zones to cluster similar transactions.
Evaluates the KNN model. While it achieves high accuracy, standard accuracy fails to expose hidden errors due to severe class imbalance.
Trains an XGBoost classifier. We balance class weights via the 'scale_pos_weight' parameter to heavily penalize missing fraud cases sequentially.
Evaluates the XGBoost model. It significantly outperforms KNN, especially in Recall, correctly flagging more total fraud occurrences.
Exhaustively searches over a specified parameter grid to find the optimal model settings. It checks every combination iteratively to maximize recall.
Randomly samples from parameter distributions, offering a computationally efficient alternative to Grid Search while still finding highly optimized parameters.
Final Model Comparison. XGBoost outscores KNN across every operational checkpoint metric, notably boosting Recall parameters and tracking fewer false negatives.