A neural network built from scratch using NumPy for binary diabetes classification, developed for the Computational Intelligence and Neural Networks (CSEN1121) course at the German University in Cairo (GUC).
The project covers the full machine learning workflow: data preprocessing, visual exploration, model implementation, training, and evaluation — all without high-level ML frameworks. TensorFlow, Keras, and PyTorch's model.Sequential() / .fit() are strictly prohibited per course requirements.
The project uses the CDC Diabetes Health Indicators dataset (data/diabetes_binary.csv), a balanced binary classification dataset derived from CDC survey data.
| Label | Meaning |
|---|---|
0 |
No Diabetes |
1 |
Diabetes |
Key features include BMI, Age, GenHlth, MentHlth, PhysHlth, HighBP, HighChol, and 14 additional health indicators (21 total).
CINN-Project/
├── main.py # Entry point — runs the full pipeline
├── data/
│ └── diabetes_binary.csv # CDC Diabetes Health Indicators dataset
├── plots/ # Auto-generated visualizations
│ ├── target_distribution.png
│ ├── feature_histograms.png
│ ├── correlation_heatmap.png
│ ├── scatter_plots.png
│ └── training_history.png
└── src/
├── __init__.py
├── neural_network.py # NeuralNetwork class + standalone test function
├── activations.py # Sigmoid, ReLU, Softmax (and their derivatives)
├── metrics.py # Binary cross-entropy loss and accuracy
├── preprocessing.py # Data loading, balancing, cleaning, summaries
└── visualizations.py # All matplotlib/seaborn plot functions
Input Layer → Hidden Layer (ReLU) → Output Layer (Sigmoid)
[21 features] [10 neurons] [1 neuron]
- Weights are initialised with He initialisation for the ReLU hidden layer
- Training uses mini-batch gradient descent with manual backpropagation
- Loss function is Binary Cross-Entropy
- Load & inspect the dataset and print a feature summary
- Balance classes if needed (dataset is pre-balanced 50/50 by default)
- Handle missing values via median imputation
- Visualise — target distribution, feature histograms, correlation heatmap, scatter plots
- Split into train / validation / test sets (70 / 20 / 10)
- Scale features with
StandardScaler - Train the network, logging loss and accuracy each epoch
- Evaluate on the held-out test set and report final loss and accuracy
pip install numpy pandas scikit-learn matplotlib seabornpython main.pyPlots are saved to the plots/ directory. Epoch-by-epoch metrics print to stdout.
| Parameter | Default |
|---|---|
| Learning Rate | 0.001 |
| Epochs | 300 |
| Batch Size | 100 |
| Hidden Neurons | 10 |
| Random Seed | 42 |
All are defined at the top of main.py and easy to modify.
NeuralNetwork— initialises weights, forward pass, backward pass, parameter update, and the full training loop with validation trackingtest_TestSet_Random1— standalone function that evaluates a saved weight dictionary on the test split
relu/relu_derivativesigmoid/sigmoid_derivativesoftmax— implemented for potential multi-class extensions
error_Random1— Binary Cross-Entropy, returns per-sample error vector and aggregated scalarcalculate_accuracy— threshold-based accuracy (threshold = 0.5)one_hot_encode— utility for multi-class targets
load_diabetes_data— reads the CSV and enforces integer target encodinghandle_missing_values— median imputation per column with loggingbalance_data— under/over-samples classes to a specified target countget_feature_summary— dtype, unique value count, and null count per featureget_numerical_statistics— extendeddescribe()augmented with variance and range
plot_target_distribution— bar chart of class countsplot_feature_histograms— KDE histograms for selected featuresplot_correlation_heatmap— Pearson correlation heatmap across all featuresplot_scatter_plots— scatter plots coloured by diabetes labelplot_training_history— side-by-side loss and accuracy curves over epochs