PythonDataScienceHandbook icon indicating copy to clipboard operation
PythonDataScienceHandbook copied to clipboard

05.10-Manifold-Learning causes ValueError when plotting MNIST digits data

Open afettouhi opened this issue 7 years ago • 1 comments

I am trying to reproduce the last cell in the Manifold Learning section of Chapter 5 e.g. this cell here

`from sklearn.manifold import Isomap

    # Choose 1/4 of the "1" digits to project
    data = mnist.data[mnist.target == 1][::4]

    fig, ax = plt.subplots(figsize=(10, 10))
    model = Isomap(n_neighbors=5, n_components=2, eigen_solver='dense')
    plot_components(data, model, images=data.reshape((-1, 28, 28)),
                    ax=ax, thumb_frac=0.05, cmap='gray_r')`

but I get a ValueError because it claims that the data array is empty. Which I don't understand because the data imported and loaded and I have been able to run the previous cells just fine.

afettouhi avatar Aug 09 '19 12:08 afettouhi

The problem is in the new set MNIST_784, digit labels are characters not integers. If you modify the line that selects digit number 1 as below it works.

data = mnist.data[mnist.target == '1'][::4]

lsantapau avatar Dec 11 '20 00:12 lsantapau