Get startedGet started for free

t-SNE visualization of grain dataset

In the video, you saw t-SNE applied to the iris dataset. In this exercise, you'll apply t-SNE to the grain samples data and inspect the resulting t-SNE features using a scatter plot. You are given an array samples of grain samples and a list variety_numbers giving the variety number of each grain sample.

This exercise is part of the course

Unsupervised Learning in Python

View Course

Exercise instructions

  • Import TSNE from sklearn.manifold.
  • Create a TSNE instance called model with learning_rate=200.
  • Apply the .fit_transform() method of model to samples. Assign the result to tsne_features.
  • Select the column 0 of tsne_features. Assign the result to xs.
  • Select the column 1 of tsne_features. Assign the result to ys.
  • Make a scatter plot of the t-SNE features xs and ys. To color the points by the grain variety, specify the additional keyword argument c=variety_numbers.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Import TSNE
____

# Create a TSNE instance: model
model = ____

# Apply fit_transform to samples: tsne_features
tsne_features = ____

# Select the 0th feature: xs
xs = tsne_features[:,0]

# Select the 1st feature: ys
ys = tsne_features[:,1]

# Scatter plot, coloring by variety_numbers
____
plt.show()
Edit and Run Code