--- title: AIO2025M06 DEMO Softmax REGRESSION emoji: 📊 colorFrom: red colorTo: blue sdk: gradio sdk_version: 5.38.0 app_file: app.py short_description: Run Softmax Regression on datasets to predict outcomes pinned: false --- # Softmax 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 - **Multi-class Classification**: Implements classification for 3 or more classes (e.g., 0, 1, 2, ...) - **NumPy Implementation**: Efficient matrix operations for fast computation - **Softmax Activation**: Maps raw scores (logits) to a probability distribution over multiple classes (summing to 1) - **Categorical Entropy Loss**: Optimized loss function for multi-class 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**: Softmax σ(z) = e^(z_k) / Σ_j e^(z_j) **Loss Function**: Categorical Cross-Entropy L = -Σ(k=0 to K-1) y_k · log(ŷ_k) **Classification**: Predict the class with the highest probability ŷ_k if its probability ≥ threshold, otherwise classify as "Undecided" or the highest probability class regardless of threshold. **Normalization**: Features standardized (zero mean, unit variance) for numerical stability ## Sample Datasets 1. **Iris**: Classic multi-class dataset (3 classes of iris flowers) 2. **Wine**: Wine dataset (3 distinct classes) 3. **Synthetic**: Artificially generated multi-class classification dataset ## How to Use 1. **Select Data**: Choose a sample dataset or upload your own CSV/Excel file 2. **Configure Target**: Select target column (must have exactly 2 unique values) 3. **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%) 4. **Adjust Threshold**: Set probability threshold for classification (default: 0.5) 5. **Enter Features**: Input feature values for prediction 6. **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