You can view the notebook with all outputs and results on Kaggle:
https://www.kaggle.com/code/evangelosgakias/t-sne-mnist-dataset
- Live Results
- Table of Contents
- Overview
- Project Structure
- Features
- Quickstart
- Usage
- Results
- Limitations and Future Work
- Contributing
- License
- Contact
This project demonstrates the application of t-Distributed Stochastic Neighbor Embedding (t-SNE) for visualizing high-dimensional data, using the MNIST handwritten digits dataset. The notebook covers the full data science workflow: data loading, preprocessing, dimensionality reduction, visualization, and interpretation of results.
Goal:
Project high-dimensional MNIST data into 2D space to reveal clusters and patterns, and to compare t-SNE with other dimensionality reduction techniques.
t-Distributed Stochastic Neighbor Embedding/
├── t_sne_project.ipynb # Jupyter notebook with the complete implementation
├── requirements.txt # Python dependencies
├── README.md # Project documentation (this file)
├── figures/ # Result images and plots
│ ├── sample_digits.png
│ ├── class_distribution.png
│ ├── tsne_embedding.png
│ ├── tsne_perplexity_5.png
│ └── tsne_different_perplexities.png
- Dataset Loading: Uses the MNIST dataset (70,000 samples, 784 features).
- Exploratory Data Analysis (EDA): Sample digit visualization, class distribution.
- Preprocessing: Standard scaling, subsetting for computational efficiency.
- t-SNE: 2D embedding of MNIST data, parameter tuning (perplexity).
- Visualization: Scatter plots of t-SNE embeddings, color-coded by digit label.
- Parameter Exploration: Visual comparison of t-SNE results for different perplexity values.
- Cluster Analysis: Discussion of cluster structure, separation, and intra-class variation.
- Comparison: Theoretical discussion of t-SNE vs. PCA.
- Kaggle (Recommended for Reproducibility):
- Local:
- Clone the repo and run
t_sne_project.ipynbin Jupyter after installing requirements.
- Clone the repo and run
- 📥 Clone the repository:
git clone https://github.com/EvanGks/t-sne-mnist-visualization.git cd t-sne-mnist-visualization - 🔒 Create and activate a virtual environment:
- Windows:
python -m venv .venv .venv\Scripts\activate
- macOS/Linux:
python3 -m venv .venv source .venv/bin/activate
- Windows:
- 📦 Install dependencies:
pip install -r requirements.txt
- 🚀 Launch Jupyter Notebook:
jupyter notebook t_sne_project.ipynb
▶️ Run all cells to reproduce the analysis and results.
🛠️ Troubleshooting:
- If you encounter missing package errors, ensure your Python environment is activated and up to date.
- For best reproducibility, use the provided Kaggle link.
- Sample Digits:

- Class Distribution:

- t-SNE Embedding (Perplexity=30):

- t-SNE with Different Perplexities:

- t-SNE reveals clear clusters corresponding to digit classes in the MNIST dataset.
- The choice of perplexity significantly affects the visualization; values between 30 and 50 often yield the best separation for MNIST.
- Some digits (e.g., 4 and 9, 3 and 8) may have overlapping clusters due to visual similarity.
- t-SNE excels at local structure but does not always preserve global distances.
For full details, metrics, and plots, see the notebook.
- Computational Cost: t-SNE is slow for large datasets; subsetting is used for efficiency.
- Parameter Sensitivity: Results depend on perplexity and other parameters.
- Global Structure: t-SNE is best for local structure; global distances may be misleading.
- Potential Improvements:
- Compare with UMAP and PCA visually and quantitatively.
- Automate parameter selection.
- Apply to other high-dimensional datasets.
Contributions are welcome! Please feel free to submit a Pull Request or open an Issue for suggestions and improvements.
This project is licensed under the MIT License. See the LICENSE file for details.
For questions or feedback, please reach out via:
- GitHub: EvanGks
- X (Twitter): @Evan6471133782
- LinkedIn: Evangelos Gakias
- Kaggle: evangelosgakias
- Email: evangks88@gmail.com
Happy Visualizing!