liveBook · Manning

T-SNE

As explained in Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI

t-SNE is a nonlinear dimensionality-reduction technique that maps high-dimensional data to a low-dimensional space while emphasizing local neighborhood structure.

t-SNE is a nonlinear dimensionality-reduction technique for projecting complex, multivariate data into a few dimensions. The resulting chart helps reveal patterns, clusters, and potentially anomalous points that are difficult to see across many original features. section 2.4.3

Use t-SNE with these practical cautions:

  • Treat the plot as an exploratory aid rather than definitive evidence: changing hyperparameters can produce substantially different projections. section 2.4.3
  • Compare it with PCA, SVD, or UMAP when linear structure, alternative projections, or additional interpretation matter. section 2.4.3
Listing 2.9 Plotting a t-SNE low-dimensional projection of a dataset
from sklearn.manifold import TSNE                           #1
import matplotlib.pyplot as plt                             #2
 
tsne = TSNE(n_components=2, 
            perplexity=30., 
            init="random", 
            learning_rate="auto",
            random_state=42)                                #3
 
X = data[numeric_feats + ordinal_feats].fillna(
            data[numeric_feats + ordinal_feats].mean())     #4
projection_2D = tsne.fit_transform(X)                       #5
 
plt.figure(figsize=(15, 15))
plt.scatter(projection_2D[:, 0], projection_2D[:, 1],
            edgecolor='none', 
            alpha=0.80, 
            s=10) 
plt.show()                                                  #6

A runnable scikit-learn workflow creates a two-dimensional t-SNE projection and plots its points with matplotlib. section 2.4.3

How Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI covers it

How deep it goes
Reduces numeric multivariate data to plotted dimensions, but stops short of stable interpretation because hyperparameters alter projections.
Examples
Uses numeric and ordinal dataset features, mean imputation, scikit-learn TSNE, and a two-dimensional scatter plot.
What it assumes
Requires numeric input features and basic preparation of missing values before projection.
What you can do after
Apply it via scikit-learn's TSNE to create and plot a two-dimensional data projection.
How it connects
Connects dimensionality reduction with exploratory data analysis, PCA, SVD, and UMAP.

Also explained in

Compare how 2 books explain t-SNE →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI. The section links point to the parts of the book it draws on.