duongtruongbinh's picture
Implement MLP regression demo with Gradio interface, including data loading, model training, and visualization features. Add README and requirements documentation, along with necessary package files.
4045778

A newer version of the Gradio SDK is available: 6.1.0

Upgrade
metadata
title: AIO2025M06 DEMO MLP REGRESSION
emoji: 馃
colorFrom: blue
colorTo: purple
sdk: gradio
sdk_version: 5.38.0
app_file: app.py
short_description: Interactive MLP regression visualization and training
pinned: false

MLP (Multi-Layer Perceptron) Regression Interactive Demo

Interactive demonstration of Multi-Layer Perceptron (MLP) for regression. Build, train, and visualize neural networks with customizable architectures, activation functions, optimizers, and regularization techniques. Experience real-time training metrics and predictions.

Features

  • Interactive MLP Architecture: Build custom neural networks with multiple hidden layers
  • Flexible Layer Configuration: Add/remove hidden layers with configurable neuron counts (1-64 neurons per layer)
  • Multiple Activation Functions: Choose from ReLU, Sigmoid, Tanh, LeakyReLU for each hidden layer
  • Advanced Optimizers: Adam, SGD, RMSprop optimizers for efficient training
  • Regularization: L1 and L2 regularization to prevent overfitting
  • Real-time Visualization:
    • Training loss (MSE) and MAE curves
    • Validation loss (MSE) and MAE curves
    • Network architecture visualization
    • Performance metrics (MSE, MAE, R虏)
  • Interactive Data Input: Upload CSV/Excel files or use sample datasets
  • Preset Datasets: California Housing, Synthetic regression datasets for quick experimentation
  • PyTorch Backend: Fast, efficient neural network training

Algorithm Details

Architecture: Multi-Layer Perceptron with configurable hidden layers

  • Input Layer: Variable number of features
  • Hidden Layers: User-configurable (up to 8 layers, 1-64 neurons each)
  • Output Layer: 1 neuron with linear activation for regression

Activation Functions:

  • ReLU: f(x) = max(0, x) - Most common, helps with vanishing gradient
  • Sigmoid: 蟽(x) = 1/(1 + e^(-x)) - Maps to (0,1) range
  • Tanh: tanh(x) = (e^x - e^(-x))/(e^x + e^(-x)) - Maps to (-1,1) range
  • LeakyReLU: f(x) = max(0.01x, x) - Variant of ReLU with small gradient for negative values

Loss Function: Mean Squared Error (MSE) L = (1/n)危(y - 欧)虏

Metrics:

  • MSE (Mean Squared Error): Average squared difference between predicted and actual values
  • MAE (Mean Absolute Error): Average absolute difference between predicted and actual values
  • R虏 (R-squared): Coefficient of determination, measures how well the model explains variance

Optimizers:

  • Adam: Adaptive learning rate, combines momentum and RMSprop benefits
  • SGD: Stochastic Gradient Descent with configurable learning rate
  • RMSprop: Root Mean Square Propagation, adapts learning rate per parameter

Regularization:

  • L1 (Lasso): Adds 位|weights| penalty, encourages sparsity
  • L2 (Ridge): Adds 位(weights虏) penalty, prevents large weights

Interactive Features

  1. Data Input:

    • Upload CSV/Excel files with continuous target values
    • Load preset datasets (California Housing, Synthetic)
    • Select target column for regression
  2. Network Architecture:

    • Configure up to 8 hidden layers
    • Set neurons per layer (1-64)
    • Select activation function for each layer
    • Visualize network structure
  3. Training Configuration:

    • Epochs: Number of training iterations (recommended: 50-500)
    • Learning Rate: Step size for optimization (recommended: 0.001-0.01)
    • Batch Size: Samples per weight update (0 = full batch)
    • Optimizer: Adam, SGD, or RMSprop
    • Regularization: None, L1, or L2 with configurable rate (位)
    • Train/Validation Split: Proportion of data for training vs validation (default: 80/20)
  4. Visualization:

    • Real-time training loss (MSE) and MAE plots
    • Validation loss (MSE) and MAE plots
    • Performance metrics (MSE, MAE, R虏)
    • Network architecture diagram

Sample Datasets

  1. California Housing: Real-world housing price prediction dataset
  2. Synthetic: Generated regression dataset with configurable noise

How to Use

Gradio Interface (app.py)

  1. Select Data: Choose a sample dataset or upload your own CSV/Excel file
  2. Configure Target: Select target column (must be continuous numeric values)
  3. Set Training Parameters:
    • Epochs: Number of training iterations
    • Learning Rate: Step size for optimization
    • Batch Size: Samples per batch
    • Train/Validation Split: Proportion for training (default: 80%)
  4. Configure Architecture: Set number of neurons and activation functions for each hidden layer
  5. Enter Features: Input feature values for prediction
  6. Run Training: Click "Run Training & Prediction" to train and visualize

Key Parameters

Architecture Parameters:

  • Hidden Layers: Number of layers between input and output (recommended: 1-3 for simple problems)
  • Neurons per Layer: Width of each layer (recommended: 8-32 for most problems)
  • Activation Function: ReLU for hidden layers, Linear for output

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. 0 = full batch (most stable)
  • Optimizer: Adam for adaptive learning, SGD for fine control, RMSprop for stability

Regularization Parameters:

  • L1/L2 Rate (位): Penalty strength (0.001-0.01 recommended). Higher = more regularization

Tips for Best Results

  1. Start Simple: Begin with 1-2 hidden layers and 8-16 neurons
  2. Use Adam: Adam optimizer typically works well with default learning rate
  3. Monitor Overfitting: Watch validation metrics; add regularization if needed
  4. Experiment with Architecture: Try different layer configurations for complex problems
  5. Adjust Learning Rate: Lower learning rate (0.001) for more stable training
  6. Normalize Data: Ensure both features and target are properly normalized

Requirements

  • gradio >= 5.38.0
  • pandas >= 1.5.0
  • scikit-learn >= 1.3.0
  • numpy >= 1.24.0
  • plotly >= 5.15.0
  • torch >= 2.0.0
  • openpyxl >= 3.0.0