---
title: ML Loss Function Playground
emoji: ๐ง
colorFrom: purple
colorTo: blue
sdk: docker
app_port: 7860
pinned: false
---
๐ง ML Loss Function Playground
[](https://www.python.org/)
[](https://flask.palletsprojects.com/)
[](https://pytorch.org/)
[](https://plotly.com/python/)
[](https://www.docker.com/)
[](#)
[](https://huggingface.co/spaces/mnoorchenar/loss-function-playground)
[](https://github.com/mnoorchenar/loss-function-playground)
**๐ง ML Loss Function Playground** โ An interactive web application for exploring and comparing loss functions in regression and classification tasks using **PyTorch**.
---
## Table of Contents
- [Features](#-features)
- [Technical Overview](#-technical-overview)
- [Getting Started](#-getting-started)
- [Docker Deployment](#-docker-deployment)
- [How It Works](#๏ธ-how-it-works)
- [Project Structure](#-project-structure)
- [Author](#-author)
- [Disclaimer](#๏ธ-disclaimer)
- [License](#-license)
---
## โจ Features
- Compare multiple loss functions side by side:
- MSE, MAE, Huber (for regression)
- BCE, Cross Entropy, Sparse Categorical Cross Entropy (for classification)
- Switch between:
- Regression
- Binary classification
- Multi-class classification
- Generate synthetic datasets with adjustable:
- Noise level
- Outlier percentage and magnitude
- Number of samples and features
- Visualize:
- Training vs validation loss curves
- Total training time per loss function
- Metric tables (Accuracy, F1, Rยฒ, etc.)
- View convergence epochs and speed comparisons
---
## ๐งฐ Technical Overview
- **Framework**: Flask + PyTorch
- **Frontend**: HTML + Plotly.js
- **Dataset Generation**: `scikit-learn` synthetic datasets
- **Metrics**:
- Regression: MSE, MAE, Rยฒ
- Classification: Accuracy, Precision, Recall, F1
---
## ๐ Getting Started
### Prerequisites
- Python 3.10+
- Git
- Docker (optional)
### Local Installation
```bash
# 1. Clone the repository
git clone https://github.com/mnoorchenar/loss-function-playground.git
cd loss-function-playground
# 2. Create a virtual environment
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
# 3. Install dependencies
pip install -r requirements.txt
# 4. Run the application
python app.py
```
Open your browser at `http://localhost:7860` ๐
---
## ๐ณ Docker Deployment
```bash
docker build -t loss-function-playground .
docker run -p 7860:7860 loss-function-playground
```
---
## ๐๏ธ How It Works
1. The app generates a synthetic dataset for the chosen task.
2. For each selected loss function:
- It builds a simple fully connected PyTorch network.
- Trains it for the specified number of epochs.
- Tracks loss, convergence, and timing.
3. The results are visualized interactively in the browser.
---
## ๐ Project Structure
```
loss-function-playground/
โ
โโโ ๐ Dockerfile # Container definition (port 7860)
โโโ ๐ app.py # Application entry point
โโโ ๐ requirements.txt # Python dependencies
```
---
## ๐จโ๐ป Author

[](https://github.com/mnoorchenar/loss-function-playground/stargazers)
[](https://github.com/mnoorchenar/loss-function-playground/fork)
The name "ML Loss Function Playground" is used purely for academic and research purposes. Any similarity to existing product names or trademarks is entirely coincidental. This project has no affiliation with any commercial entity.