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

