-
-
Notifications
You must be signed in to change notification settings - Fork 155
Added t-Distributed Stochastic Neighbor Embedding in Machine Learning #3700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
141 changes: 141 additions & 0 deletions
141
docs/Machine Learning/t-Distributed Stochastic Neighbor Embedding.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
--- | ||
id: t-Distributed Stochastic Neighbor Embedding | ||
title: t-Distributed Stochastic Neighbor Embedding | ||
sidebar_label: Introduction to t-Distributed Stochastic Neighbor Embedding | ||
sidebar_position: 2 | ||
tags: [t-Distributed Stochastic Neighbor Embedding, t-SNE, dimensionality reduction, data visualization, machine learning, data science, non-linear dimensionality reduction, feature reduction] | ||
description: In this tutorial, you will learn about t-Distributed Stochastic Neighbor Embedding (t-SNE), its significance, what t-SNE is, why learn t-SNE, how to use t-SNE, steps to start using t-SNE, and more. | ||
--- | ||
|
||
### Introduction to t-Distributed Stochastic Neighbor Embedding | ||
t-Distributed Stochastic Neighbor Embedding (t-SNE) is a popular dimensionality reduction technique used to visualize high-dimensional data in a lower-dimensional space, typically 2D or 3D. It is particularly effective in preserving the local structure of the data, making it an invaluable tool for exploring and understanding complex datasets. | ||
|
||
### What is t-Distributed Stochastic Neighbor Embedding? | ||
t-SNE works by converting high-dimensional data into a probability distribution that captures pairwise similarities between data points. It then maps these points to a lower-dimensional space while preserving these similarities. | ||
|
||
- **High-Dimensional Data**: Data is represented in a high-dimensional space with complex structures. | ||
- **Probability Distribution**: t-SNE calculates the similarity between data points using conditional probabilities. | ||
- **Low-Dimensional Mapping**: The algorithm minimizes the divergence between the high-dimensional and low-dimensional probability distributions, resulting in a 2D or 3D representation. | ||
|
||
**Similarity Measurement**: Uses Gaussian distribution to measure similarity in high-dimensional space and Student’s t-distribution for low-dimensional space. | ||
|
||
### Example: | ||
Consider using t-SNE to visualize clusters in a dataset of handwritten digits. By reducing the data to 2D, you can observe how different digits group together, revealing underlying patterns and clusters. | ||
|
||
### Advantages of t-Distributed Stochastic Neighbor Embedding | ||
t-SNE offers several advantages: | ||
|
||
- **Preserves Local Structure**: Maintains the local relationships between data points, making clusters and patterns more apparent. | ||
- **Non-Linear Mapping**: Capable of capturing complex, non-linear structures in the data. | ||
- **Intuitive Visualization**: Produces intuitive and interpretable visualizations of high-dimensional data. | ||
|
||
### Example: | ||
In bioinformatics, t-SNE can be used to visualize gene expression profiles, revealing patterns and relationships between different genes or samples. | ||
|
||
### Disadvantages of t-Distributed Stochastic Neighbor Embedding | ||
Despite its strengths, t-SNE has limitations: | ||
|
||
- **Computational Complexity**: Can be computationally intensive, especially with large datasets. | ||
- **Parameter Sensitivity**: Results can be sensitive to hyperparameters, such as perplexity and learning rate. | ||
- **Global Structure**: May not preserve global structures or distances well, focusing more on local relationships. | ||
|
||
### Example: | ||
In large-scale image datasets, t-SNE might struggle to maintain meaningful global relationships between images, potentially making it less effective for certain types of analysis. | ||
|
||
### Practical Tips for Using t-Distributed Stochastic Neighbor Embedding | ||
To get the most out of t-SNE: | ||
|
||
- **Choose Perplexity Wisely**: Perplexity is a key parameter that controls the balance between local and global aspects of the data. Experiment with different values to find the best representation. | ||
- **Normalize Data**: Preprocess and normalize data to ensure that t-SNE operates on well-conditioned inputs. | ||
- **Use Dimensionality Reduction Preprocessing**: Apply initial dimensionality reduction (e.g., PCA) to reduce the computational burden and improve the performance of t-SNE. | ||
|
||
### Example: | ||
In a text analysis project, you can preprocess word embeddings using t-SNE to visualize and cluster similar words or documents based on their semantic content. | ||
|
||
### Real-World Examples | ||
|
||
#### Image Analysis | ||
t-SNE is often used in computer vision to visualize the clusters of similar images in a dataset, helping to understand and evaluate image classification algorithms. | ||
|
||
#### Customer Segmentation | ||
In marketing analytics, t-SNE can visualize customer segments based on purchasing behavior, aiding in the development of targeted marketing strategies. | ||
|
||
### Difference Between t-SNE and PCA | ||
| Feature | t-Distributed Stochastic Neighbor Embedding (t-SNE) | Principal Component Analysis (PCA) | | ||
|---------------------------------|------------------------------------------------------|-----------------------------------| | ||
| Linear vs Non-Linear | Non-linear dimensionality reduction. | Linear dimensionality reduction. | | ||
| Preserved Structure | Preserves local structure; may distort global structure. | Preserves global structure; may not capture local nuances. | | ||
| Computational Cost | Computationally intensive with large datasets. | Generally faster and more scalable. | | ||
|
||
### Implementation | ||
To implement and visualize data using t-SNE, you can use libraries such as scikit-learn in Python. Below are the steps to install the necessary library and apply t-SNE. | ||
|
||
#### Libraries to Download | ||
- scikit-learn: Provides the implementation of t-SNE. | ||
- matplotlib: Useful for data visualization. | ||
- pandas: Useful for data manipulation and analysis. | ||
- numpy: Essential for numerical operations. | ||
|
||
You can install these libraries using pip: | ||
|
||
```bash | ||
pip install scikit-learn matplotlib pandas numpy | ||
``` | ||
|
||
#### Applying t-Distributed Stochastic Neighbor Embedding | ||
Here’s a step-by-step guide to applying t-SNE: | ||
|
||
**Import Libraries:** | ||
|
||
```python | ||
import pandas as pd | ||
import numpy as np | ||
from sklearn.manifold import TSNE | ||
import matplotlib.pyplot as plt | ||
``` | ||
|
||
**Load and Prepare Data:** | ||
Assuming you have a dataset in a CSV file: | ||
|
||
```python | ||
# Load the dataset | ||
data = pd.read_csv('your_dataset.csv') | ||
|
||
# Prepare features (X) | ||
X = data.drop('target_column', axis=1) # Replace 'target_column' with any non-feature columns | ||
``` | ||
|
||
**Apply t-SNE:** | ||
|
||
```python | ||
# Initialize t-SNE | ||
tsne = TSNE(n_components=2, random_state=42) | ||
|
||
# Fit and transform the data | ||
X_tsne = tsne.fit_transform(X) | ||
``` | ||
|
||
**Visualize the Results:** | ||
|
||
```python | ||
# Plot t-SNE results | ||
plt.figure(figsize=(10, 8)) | ||
plt.scatter(X_tsne[:, 0], X_tsne[:, 1], c=data['target_column'], cmap='viridis', alpha=0.7) | ||
plt.colorbar() | ||
plt.title('t-SNE Visualization') | ||
plt.xlabel('Component 1') | ||
plt.ylabel('Component 2') | ||
plt.show() | ||
``` | ||
|
||
### Performance Considerations | ||
|
||
#### Computational Efficiency | ||
- **Dataset Size**: t-SNE can be slow for very large datasets. Consider using a subset of the data or combining it with other dimensionality reduction techniques (e.g., PCA) to speed up the process. | ||
- **Hyperparameters**: Proper tuning of hyperparameters, such as perplexity, can affect both the quality of the results and the computational cost. | ||
|
||
### Example: | ||
In a large-scale text dataset, combining t-SNE with PCA for initial dimensionality reduction can make the visualization process more manageable and faster. | ||
|
||
### Conclusion | ||
t-Distributed Stochastic Neighbor Embedding is a powerful technique for visualizing and understanding high-dimensional data. By grasping its strengths, limitations, and implementation, practitioners can effectively leverage t-SNE to gain insights and make sense of complex datasets in various data science and machine learning projects. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.