Members: Huaqing Li, Jon Kuçi, Tenga Masujima.
Course: CS-433 Machine Learning.
Institution: École Polytechnique Fédérale de Lausanne (EPFL), Switzerland.
This repository contains the full implementation for EPFL CS-433 Project 1 (Fall 2025), focusing on the prediction of coronary heart disease (CHD) using the Behavioral Risk Factor Surveillance System (BRFSS 2015) dataset. The project applies data preprocessing, feature selection, and two core predictive models, regularized logistic regression and a three-layer neural network, to study how data-engineering strategies and model design influence performance under class imbalance.
The run.ipynb notebook orchestrates the complete machine learning pipeline of the best submission of the Neural Network model. Before executing it make sure the raw datasets x_train.csv, y_train.csv and x_test.csv are inside the data folder. The run.ipynb notebook includes:
- Data loading and processing – Cleans the dataset, encodes categorical variables, handles missing values, and standardizes continuous features.
- Feature selection – Applies filtering, mutual information, and mRMR ranking to select the most informative features.
- Model training – Trains a neural network using class-weighted loss with and early stopping.
- Threshold optimization – Determines the optimal classification threshold maximizing the F1-score on validation data.
- Prediction and output – Generates the final
submission.csvfile in the required format for AIcrowd.
Execution:
# Open run.ipynb and execute all cells sequentially
# Note: Data preprocessing of x_train and x_test can take several minutes.
# To skip this step, execute only the loading cell which loads the datasets stored in src/saved_dataset/
# Note: Training the model can take a long time as well
# If you wish to skip this step, execute only the leading cell.
# Final output: submission.csv generated in submission folder.Other key points
- The best run using Neural Network model in
run.ipynbachieved a score ofF1=0.445in AIcrowd. - The logistic regression model run is located in
src/training/run_logistic_regression.ipynb. This model reached a score ofF1=0.433in AICrowd. - Other executed files used for the project report are included in
src/training. - The project report can be found in
report/report.pdf.
project-1-gradient_tri-scent/
│
├── implementations.py # Required ML algorithms (graded)
├── helpers.py # Data I/O and CSV submission
├── run.ipynb # Main file
│
├── src/
│ ├── data_processing/
│ │ ├── data_transformer.py # Cleaning, encoding, standardization
│ │ ├── feature_selection.py # mRMR, mutual information, correlation filtering
│ │ ├── dataset_util.py # Dataset construction & caching
│ │ └── data_clean_BRFSS.py # BRFSS-specific preprocessing
│ │
│ ├── models/
│ │ ├── neural_network.py # 3-layer NN with early stopping
│ │ └── logistic_regression.py # Regularized Logistic regression
│ |
│ ├── utils/
│ │ ├── evaluation_util.py # F1, precision, recall metrics
│ │ ├── path_util.py # Root path detection
│ │ └── data_helpers.py # Helper functions for data manipulation
│ │
│ ├── training/
│ │ ├── run.ipynb # Legacy main training notebook
│ │ ├── run_logistic_regression.ipynb # Logistic regression experiments
│ │ ├── run_Neural_Network_250_features.ipynb # NN with 250 features
│ │ ├── run_Neural_Network_450_features.ipynb # NN with 450 features
│ │ └── run_Neural_network_plot.ipynb # Visualization of NN training
│ │
│ ├── saved_dataset/ # Cached preprocessed data (.npz)
│ └── saved_models/ # Trained model weights (.npz)
│
├── data/ # Raw CSV files
├── report/ # Project report in PDF
└── submission/ # Output predictions
Six required ML algorithms implemented from scratch per project specifications. Each function returns (w, loss) where loss excludes regularization penalties.
mean_squared_error_gd(y, tx, initial_w, max_iters, gamma)– Linear regression using gradient descentmean_squared_error_sgd(y, tx, initial_w, max_iters, gamma)– Linear regression using stochastic gradient descent (mini-batch size = 1)least_squares(y, tx)– Least-squares regression using normal equationsridge_regression(y, tx, lambda_)– Ridge regression using normal equations with L2 regularizationlogistic_regression(y, tx, initial_w, max_iters, gamma)– Logistic regression using gradient descentreg_logistic_regression(y, tx, lambda_, initial_w, max_iters, gamma)– Regularized logistic regression using gradient descent with L2 penalt
Complete preprocessing pipeline handling the BRFSS dataset's complexities.
Data cleaning and selection built around the DataTransformer class. Performs one-hot encoding by creating binary columns for each categorical value, imputes missing values using mean/median strategies while adding _missing indicator flags to preserve missingness signals, maps boolean features (1/2 → 1/0) and extracts special survey codes (7=Refused, 9=Don't Know) into separate columns, standardizes features using training set statistics cached for test alignment, and provides queued operations for batch feature manipulation.
Implements the FeatureSelector class with advanced dimensionality reduction. Removes low-variance features below threshold, eliminates highly correlated features (keeps higher variance), computes mutual information via discretization to measure feature-target relevance, applies mRMR (Maximal Relevance Minimal Redundancy) algorithm for optimal feature subset selection, and generates polynomial features (pairwise interactions, squares, logs, square roots) from seed features for non-linear modeling.
High-level functions specific to the BFSS dataset. create_training_set() runs the full pipeline: BRFSS cleaning → correlation filtering → mRMR selection (350 features) → optional polynomial engineering → standardization → caching. create_testing_set() applies identical transformations using training metadata to ensure feature space alignment and consistent standardization.
Domain-specific cleaning based on BRFSS codebook. Deletes redundant features identified via manual inspection, transforms encoded values (e.g., blood sugar units, exercise frequencies) into numeric scales, applies one-hot encoding to 20+ categorical variables (state, marital status, employment), maps 100+ binary health indicators handling survey codes, cleans range-based features with domain-specific valid ranges (BMI, age, income), and converts special codes (88=None, 77=Don't Know, 99=Refused) into missing indicators.
Custom models optimized for class imbalance.
2-layer feedforward network implementation. Architecture uses He initialization for proper gradient flow with ReLU activations in hidden layers (prevents vanishing gradients), ReLU activation functions in layers 1-2 with sigmoid output for binary classification, weighted binary cross-entropy loss where positive class weight = N_neg/N_pos addresses severe imbalance, L2 regularization on all weight matrices prevents overfitting, mini-batch gradient descent with configurable batch size and shuffling, early stopping monitors validation loss with patience parameter, learning rate decay triggers when validation reaches threshold (default 0.5), and F1-optimized threshold selection sweeps probability thresholds to find optimal classification cutoff.
Extended logistic regression with SGD, momentum optimization using Adam, and L2 regularization for baseline comparison. Includes 10-fold cross validation for finding the best regularizer and threshold.
Supporting infrastructure for the project.
Evaluation metrics for binary classification. Implements compute_f1_score() calculating precision, recall, and F1-score of thhe predictions.
Smart path detection automatically finds project root whether running from notebooks, scripts, or interactive shells by traversing up directories until finding src/ folder, ensuring consistent imports across execution contexts.
Helper functions for data manipulation and preprocessing. Includes utilities for batch processing, data splitting, and common transformations used across the pipeline.
Collection of Jupyter notebooks documenting model training and hyperparameter tuning experiments.
Copy of the root run.ipynb.
The Logistic regression experiments including 10-fold cross-validation for regularization parameter (lambda) tuning, grid search for optimal classification thresholds, comparison between SGD and batch gradient descent, momentum optimization using Adam optimizer, and performance analysis across different feature subset sizes.
Neural network experiments using 250 selected features.
Neural network experiments with 450 selected features.
Visualization notebook for neural network training with different feature numbers.
- NumPy
- Python standard library
- BRFSS Dataset: CDC Behavioral Risk Factor Surveillance System, 2015