<jupyter_start><jupyter_text>Dimensionality reductionHistorically the major SoTa development seems to follow this timeline- Linear & Random projections    - PCA, SVD etc- [Manifold learning](https://scikit-learn.org/stable/modules/manifold.html)    - autoencoders, e.g. [CVAE](https://github.com/maxfrenzel/CompressionVAE)    - t-SNE    - [UMAP](https://umap-learn.readthedocs.io/en/latest/index.html)    - [trimap](https://github.com/google-research/google-research/tree/master/trimap)<jupyter_code>%matplotlib inline
import numpy as np
from sklearn.datasets import load_digits
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import trimap
import umap

from sklearn.manifold import TSNE

sns.set(style='white', context='notebook', rc={'figure.figsize':(14,10)})
penguins = pd.read_csv("https://github.com/allisonhorst/palmerpenguins/raw/5b5891f01b52ae26ad8cb9755ec93672f49328a8/data/penguins_size.csv")
penguins = penguins.dropna()
penguins.head()
sns.pairplot(penguins, hue='species_short')
reducer = umap.UMAP()
penguin_data = penguins[
    [
        "culmen_length_mm",
        "culmen_depth_mm",
        "flipper_length_mm",
        "body_mass_g",
    ]
].values
scaled_penguin_data = StandardScaler().fit_transform(penguin_data)
scaled_penguin_data.shape
%%time
embedding = reducer.fit_transform(scaled_penguin_data)
embedding.shape
plt.scatter(
    embedding[:, 0],
    embedding[:, 1],
    c=[sns.color_palette()[x] for x in penguins.species_short.map({"Adelie":0, "Chinstrap":1, "Gentoo":2})])
plt.gca().set_aspect('equal', 'datalim')
plt.title('UMAP projection of the Penguin dataset', fontsize=24)
%%time
embedding = TSNE(n_components=2, learning_rate='auto', init='random').fit_transform(scaled_penguin_data)
embedding.shape
plt.scatter(
    embedding[:, 0],
    embedding[:, 1],
    c=[sns.color_palette()[x] for x in penguins.species_short.map({"Adelie":0, "Chinstrap":1, "Gentoo":2})])
plt.gca().set_aspect('equal', 'datalim')
plt.title('T-SNE projection of the Penguin dataset', fontsize=24)
%%time
embedding = trimap.TRIMAP().fit_transform(scaled_penguin_data)
embedding.shape
plt.scatter(
    embedding[:, 0],
    embedding[:, 1],
    c=[sns.color_palette()[x] for x in penguins.species_short.map({"Adelie":0, "Chinstrap":1, "Gentoo":2})])
plt.gca().set_aspect('equal', 'datalim')
plt.title('trimap projection of the Penguin dataset', fontsize=24)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1450653983353151, 'fraction_numerical': 0.02100673801030519, 'mean_word_length': 5.896174863387978, 'pattern_counts': {'":': 9, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 5, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '95206', 'license': 'MIT', 'n_tokens_mistral': 976, 'n_tokens_neox': 923, 'n_words': 161, 'path': 'ml/DimensionalityReduction.ipynb', 'repo_name': 'pgenevski/notebooks', 'size': '2523'}