VLAI-AIVN/AIO2025M06_DEMO_LOGISTIC_REGRESSION
0
Logistic Regression Demo
Interactive demonstration of Logistic Regression implemented from scratch using NumPy and gradient descent. Learn binary classification with sigmoid activation, binary cross-entropy loss, and adjustable prediction threshold.
Features
- Binary Classification: Implements binary classification (2 classes: 0 and 1)
- NumPy Implementation: Efficient matrix operations for fast computation
- Sigmoid Activation: Maps predictions to probabilities (0-1 range)
- Binary Cross-Entropy Loss: Optimized loss function for binary classification
- Adjustable Threshold: Experiment with different probability thresholds to balance precision/recall
- Mini-batch Gradient Descent: Supports configurable batch sizes (powers of 2) or full batch
- Feature Normalization: Automatic standardization (zero mean, unit variance) for stable training
- Training Visualization: Track loss and accuracy over epochs for training and validation sets
Algorithm Details
Activation Function: Sigmoid σ(z) = 1/(1 + e^(-z)) Loss Function: Binary Cross-Entropy L = -[y·log(ŷ) + (1-y)·log(1-ŷ)] Classification: Predict class 1 if probability ≥ threshold, else class 0 Normalization: Features standardized (zero mean, unit variance) for numerical stability
Sample Datasets
- Breast Cancer: Wisconsin Breast Cancer dataset (binary classification)
- Wine (Binary): Wine dataset converted to binary (class 0 vs others)
- Synthetic: Artificially generated binary classification dataset
How to Use
- Select Data: Choose a sample dataset or upload your own CSV/Excel file
- Configure Target: Select target column (must have exactly 2 unique values)
- Set Training Parameters:
- Epochs: Number of training iterations (recommended: 50-500)
- Learning Rate: Step size for gradient descent (recommended: 0.001-0.01)
- Batch Size: Samples per batch (powers of 2, or Full Batch)
- Train/Validation Split: Proportion for training (default: 80%)
- Adjust Threshold: Set probability threshold for classification (default: 0.5)
- Enter Features: Input feature values for prediction
- Run Training: Click "Run Training & Prediction" to train and visualize
Key Parameters
Training Parameters:
- Epochs: Complete passes through data. More epochs = better learning but risk of overfitting
- Learning Rate: Step size (0.001-0.01 recommended). Too high causes instability, too low is slow
- Batch Size: Samples processed before update. Smaller = faster but noisier, larger = more stable
- Train/Validation Split: Data split ratio (default 80/20)
Threshold Parameter (Key Feature):
- Default: 0.5 (balanced classification)
- Lower threshold (e.g., 0.3): More class 1 predictions → higher recall, lower precision
- Higher threshold (e.g., 0.7): Fewer class 1 predictions → higher precision, lower recall
- Experiment: Adjust threshold to see how predictions and accuracy change in real-time
- Use Case: Balance precision vs recall based on your classification goals
Requirements
- gradio >= 5.38.0
- pandas >= 1.5.0
- scikit-learn >= 1.3.0
- numpy >= 1.24.0
- plotly >= 5.15.0
