Train and evaluate multiple regression and classification algorithms on a bank loan dataset, run hyperparameter tuning via GridSearchCV, and compare model metrics.
Domain / Environment
Retail Banking / Conda VM
Difficulty
Intermediate (3/5)
Course Module
Supervised Machine Learning
Deliverables
Evaluation Model logs & Comparison metrics report
1. System Architecture & Process Workflow
The diagram below displays the supervised learning workflow. The bank loan dataset is split into training and testing sets. Numerical columns are scaled and categorical features encoded. Data is passed to a classification pipeline (Logistic Regression, Random Forest, SVC, and KNN) and a regression pipeline, with grid search tuning active.
2. Part 1: Step-by-Step Action Items & Key Execution Steps
STEP 1
Activate Python Virtual Environment
Point the terminal execution environment to the course conda sandbox environment.
$ conda activate ds_ai_ml
This action maps the terminal binary packages to the isolated conda environment paths.
STEP 2
Create Project Folders inside Linux VM
Create a dedicated folder for the project files inside your guest VM home folder directory.
$ mkdir -p ~/Projects/model_comparison && cd ~/Projects/model_comparison
This compiles project files in one isolated directory structure.
STEP 3
Save Credit Risk Loan Dataset
Create a CSV dataset containing bank credit records, customer age, income, debt, and credit scores.
$ nano loan_records.csv
This opens nano editor. Paste the CSV data template from Part 2, press **Ctrl + O** and **Enter** to save, and **Ctrl + X** to exit.
STEP 4
Install Machine Learning Packages via Pip
Install Scikit-Learn libraries inside the active conda session.
$ pip install scikit-learn pandas numpy
This command downloads scikit-learn frameworks, loading linear regression models, decision trees, ensemble frameworks, and hyperparameter tuning grid-search modules.
STEP 5
Create classifier script file in VS Code
Launch VS Code and create a new script file inside the project workspace folder.
Launch VS Code via terminal "code ." -> Right-click in explorer tree -> click New File -> Type: model_comparison.py -> Press Enter
This registers an empty file `model_comparison.py` inside the active directory editor workspace.
STEP 6
Load Python modeling comparison logic
Paste the training, tuning, and evaluation code into the newly created python script file.
Click model_comparison.py -> Paste python code from Part 2 below -> Save file via Ctrl + S
This writes modeling and metrics calculations to the script file.
STEP 7
Execute model comparison script
Run the validation script using the python engine to train and compare the models.
$ python model_comparison.py
This trains 4 classifiers and 2 regressors, runs GridSearchCV to tune hyperparameters, and prints comparative evaluation metrics to the console.
3. Operational Pipeline Architecture
The flowchart below outlines the supervised modeling pipeline. It details dataset loading, splitting, running classification and regression pipelines, tuning parameters via GridSearchCV, and outputting benchmark reports.
4. Part 2: Complete Deliverable Assets & Production Templates
To run the model comparison, we need the raw loan CSV dataset and the Python script. Below is a line-by-line explanation of the code, followed by the combined template files.
Step-by-Step Code Construction
Lines 1 - 7
Import Modeling Packages
Include system OS, Pandas/NumPy, classifier models, and metrics functions in the script.
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split, GridSearchCV
from sklearn.linear_model import LogisticRegression, LinearRegression
from sklearn.ensemble import RandomForestClassifier, RandomForestRegressor
from sklearn.metrics import accuracy_score, f1_score, r2_score, mean_squared_error
These imports pull scikit-learn models, validation grids, and performance metric evaluators.
Lines 8 - 18
Load and Split Datasets
Read the CSV file and partition records into feature matrices and target vectors.