timsainb / ParametricUMAP_paper

Parametric UMAP embeddings for representation and semisupervised learning. From the paper "Parametric UMAP: learning embeddings with deep neural networks for representation and semi-supervised learning" (Sainburg, McInnes, Gentner, 2020).
MIT License
149 stars 15 forks source link

The example code cannot be reproduced #8

Open Tim690813 opened 3 months ago

Tim690813 commented 3 months ago

Hello, Tim Sainburg, When I ran the example code you provided, I encountered the following issues. I hope you can help me resolve them. The example code as follow from umap.parametric_umap import ParametricUMAP import tensorflow as tf from tensorflow.keras.datasets import mnist import matplotlib.pyplot as plt import pandas as pd

(train_images, Y_train), (test_images, Y_test) = mnist.load_data() train_images = train_images.reshape((train_images.shape[0], -1))/255 test_images = test_images.reshape((test_images.shape[0], -1))/255

dims = (28, 28, 1) n_components = 2 encoder = tf.keras.Sequential([ tf.keras.layers.InputLayer(input_shape=dims), tf.keras.layers.Conv2D( filters=32, kernel_size=3, strides=(2, 2), activation="relu", padding="same" ), tf.keras.layers.Conv2D( filters=64, kernel_size=3, strides=(2, 2), activation="relu", padding="same" ), tf.keras.layers.Flatten(), tf.keras.layers.Dense(units=256, activation="relu"), tf.keras.layers.Dense(units=256, activation="relu"), tf.keras.layers.Dense(units=n_components), ])

embedder = ParametricUMAP(encoder=encoder, dims=dims, n_epochs=50, verbose=True) embedding = embedder.fit_transform(train_images) print(embedder._history)

This is my output ParametricUMAP(dims=(28, 28, 1), encoder=<tensorflow.python.keras.engine.sequential.Sequential object at 0x0000000012CE5588>, optimizer=<tensorflow.python.keras.optimizer_v2.adam.Adam object at 0x0000000012C8AA08>) Construct fuzzy simplicial set Mon Jun 24 16:28:23 2024 Finding Nearest Neighbors Mon Jun 24 16:28:23 2024 Building RP forest with 17 trees Mon Jun 24 16:28:25 2024 NN descent for 16 iterations 1 / 16 2 / 16 3 / 16 4 / 16 5 / 16 Stopping threshold met -- exiting after 5 iterations Mon Jun 24 16:28:46 2024 Finished Nearest Neighbor Search Mon Jun 24 16:28:50 2024 Construct embedding completed 0 / 50 epochs completed 5 / 50 epochs completed 10 / 50 epochs completed 15 / 50 epochs completed 20 / 50 epochs completed 25 / 50 epochs completed 30 / 50 epochs completed 35 / 50 epochs completed 40 / 50 epochs completed 45 / 50 epochs Mon Jun 24 16:29:03 2024 Finished embedding Traceback (most recent call last): print(embedder._history) AttributeError: 'ParametricUMAP' object has no attribute '_history'

timsainb commented 3 months ago

I believe _history has been moved in a recent update to tensorflow / keras, try inspecting the ParametricUMAP object or downgrading keras to the version from around 2020.

Alternatively you can the version of parametric umap that we are actively maintaining: https://github.com/lmcinnes/umap

Tim690813 commented 3 months ago

Thanks,Can the current version of UMAP rank feature importance?

timsainb commented 3 months ago

I suppose it could if you wanted it to