Modular, production style project for the Porto Seguro's Safe Driver Prediction dataset. Contains EDA, notebooks, figures, training scripts and final artifacts.
Predictions on anonymised dataset of Porto Seguro's drivers. Spent a good amount of time looking at distributions of every feature. Gained preliminary understanding of feature importance by grouping column values by their target mean. Obtained confident feature importance after training model and checking it's feature importance. Settled to XGBoost after trying multiple models, which was more or less expected. After the creation of a few new features through engineering and several hours of tuning, was able to obtain the above results. A bunch of things that I tried did not help. These include ensembling, a few more columns that I engineered, and tuning a very large amount of parameters. Overall, a really fun project.
- Develop a robust probability-based model for binary classification on the selected dataset
- Learn handling and interpreting datasets with anonymized features, and understand their behaviour
- Apply effective data cleaning, feature engineering, preprocessing, and pipeline design for reliable model performance
- Try multiple models, hypothesize their performances and compare with true results
- Use visualizations to better understand the data and preserve key insights for future reference
Porto Seguro's Safe Driver Prediction
Kaggle link: https://www.kaggle.com/competitions/porto-seguro-safe-driver-prediction/data
[I have not included the dataset in the repo. Kindly get it through Kaggle, or through various GitHub repos hosting the dataset]
- Explore features and check basic performance on non imputed and imputed data
- Train basic models to get a rough understanding of performances
- Tune best performing model from step 2 to improve performance
- Extract feature importance from tuned model, and try engineering new features from important features. Try various other preprocessing as well
- Train on entire data once again to obtain best model
- Dropped all '_calc' columns.
- Dropped additional columns ['ps_ind_10_bin', 'ps_ind_13_bin', 'ps_ind_18_bin', 'ps_car_10_cat'] due to minimal meaningful contribution in prediction
- Created new binary features using certain '_ind' features
- Created new categorical features using combinations of certain '_cat' and '_ind' features
- One Hot Encoding applied to categorical columns (helped slightly in improving performance)
XGBoost trained using following parameters, obtained through extensive hyperparameter tuning using Optuna:
params = {
"objective": "binary:logistic",
'device':'cuda',
'tree_method':'hist',
'eval_metric':'auc',
'max_depth': 3,
'eta': 0.06443239542535328,
'subsample': 0.7731240330866832,
'colsample_bytree': 0.947824044178731,
'colsample_bylevel': 0.9124205465696081,
'colsample_bynode': 0.7234222779570076,
'reg_alpha': 0.9699926009829554,
'reg_lambda': 0.6172896412559273}
The model recieves input data that has been cleaned and processed by a preprocessing pipeline.
- Logistic Regression
- Random Forest
- AdaBoost
- Gradient Boosting (sklearn)
- XGBoost (final model)
- Model ensembling via bagging (specifically, averaging predictions from multiple XGBoost models).
Chose XGBoost to be the final model, since improvement in performance when using ensemble techniques was very small, and not worth the extra computation and resources.
- Optuna for optimised and automated tuning
- Tuned multiple models and chose best performing model
XGBoost had the highest performance
- Gini co-efficient on holdout set: 0.28632
- Gini co-efficient on Kaggle provided test data: 0.28788
- Engineering new features based on feature importance was very helpful beyond the 0.28 Gini range
- Leaving -1s as is performed much better than imputation of columns
- One Hot Encoding helped, but only slightly
- Ensembling multiple XGBoosters helped performance extremely slightly, hence was not used
src/ # Core pipeline and logic
datasets/ # train and test data
artifacts/ # saved model and preprocessor
notebooks/ # experimentation
reports/ # visualisations
- Get dataset from https://www.kaggle.com/competitions/porto-seguro-safe-driver-prediction/data or through any of the GitHub repos that host the dataset
- Place train.csv and test.csv in datasets/ directory
- Install dependencies:
pip install -r requirements.txt
- Run program:
python main.py
- Options:
- Build and train model
- Evaluate model on test data
- Feed CSV files to obtain predictions
Was pretty fun actually. Had a fun time tuning parameters for XGB, and the parallel coordinate plot is pretty satisfying to look at. Experimenting with different features to get new potential strong features was very fun and anticipatory too. Overall, enjoyed it. 10/10, would recommend! [ps: I've written this way too formally. I enjoy informal language with less jargon more actually. Whatever, maybe I'll use an informal tone for the next project]