Skip to content

petrosbal/machine-learning-coursework

Repository files navigation

Machine Learning

Two projects built for a Machine Learning course: predicting corporate bankruptcy from financial ratios, and modeling diabetes progression with a focus on interpretability. Both were team assignments.

1. Financial Distress Classification

Classifies companies as healthy or bankrupt from a single year of accounting ratios (leverage, liquidity, profitability, activity) taken from Greek company filings. The data is heavily skewed toward healthy firms, and that imbalance drives most of the design choices.

Evaluation is stratified 4-fold cross-validation. Inside each fold the majority class is undersampled to 3:1 on the training split only, while the test split keeps its natural distribution; features are then Min-Max scaled and eight classifiers are compared: LDA, logistic regression, decision tree, random forest, k-NN, naive Bayes, SVM, and XGBoost. Hyperparameters come from a Bayesian search (BayesSearchCV) with nested cross-validation that optimizes F1. Each model is scored on precision, recall, F1, and ROC-AUC, with a confusion matrix per fold.

Results

With bankrupt firms only about 2.3% of the sample, accuracy is misleading and the real story is a precision/recall trade-off. On the held-out folds the models reach useful recall (SVM 0.78, logistic regression 0.77, random forest 0.72) but precision stays low (0.05 to 0.12), because even a handful of false positives dominates such a rare class. Measured as lift over the 2.3% base rate, random forest's ~9% precision is still about 4x better than random guessing, and ROC-AUC was the most stable metric from train to test.

Selection applied two thresholds on the test set, recall > 0.6 and specificity > 0.7, which four models cleared: random forest, logistic regression, XGBoost, and SVM. Ranked by G-Mean (the balance of recall and specificity) they finish close together (RF 0.770, logistic regression 0.765, XGBoost 0.762, SVM 0.758). Random forest is the best all-round choice, pairing the highest ROC-AUC (0.85) with high specificity (0.83) so it flags few healthy firms while still catching most failures. Where missing a bankruptcy is the costlier error, SVM and logistic regression trade specificity for higher recall (0.78 and 0.77).

Data: Dataset2Use_Assignment1.xlsx. Notebook: financial_distress_classification.ipynb

2. Diabetes Progression Regression

Predicts one-year disease progression from ten baseline clinical features (the standard scikit-learn diabetes dataset), comparing four regressors: random forest, gradient boosting, SVR, and a Gaussian process. Models are tuned with randomized search under K-fold cross-validation and scored on RMSE, MAE, and R^2.

The second half is about interpretability. SHAP values (TreeExplainer for the tree models, KernelExplainer for the rest) rank feature contributions and show how each feature moves an individual prediction, so the models are read rather than treated as black boxes.

Results

Errors are averaged over the six folds and reported on the original mg/dL scale. The Gaussian process is the most accurate (R^2 0.46, RMSE 54.8 mg/dL, MAE 44.3), with SVR almost tied (R^2 0.46, RMSE 55.0) and the smallest worst-case error (138 mg/dL), meaning it is the least affected by extreme cases. Random forest and gradient boosting fall behind (R^2 0.42 and 0.41): they predict in discrete steps, which fits the smooth progression of the disease poorly on only 442 patients. For reference, standard linear models in the literature sit near RMSE 54.8, so the Gaussian process matches them.

The Gaussian process is preferred for this clinical setting not only for its accuracy but because it reports how confident it is in each prediction (a confidence interval), which SVR does not, and that matters when a model informs medical decisions. The SHAP plots then show which features drive each prediction (BMI and the blood-serum measures most of all), confirming the models rely on clinically sensible signals.

Notebook: diabetes_regression.ipynb

Running

python -m venv .venv
source .venv/bin/activate      # Windows: .venv\Scripts\activate
pip install -r requirements.txt
jupyter notebook

The notebooks ship with their saved plots and metric tables, so the results are readable without running anything. A full re-run of the classification notebook repeats the Bayesian search on every fold and takes a few minutes. Each project folder also holds the graded report as report.pdf.

License

GNU General Public License v3.0. See LICENSE.

Releases

Packages

Contributors

Languages