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
Exercise instructions
- Import
TSNEfromsklearn.manifold. - Create a TSNE instance called
modelwithlearning_rate=200. - Apply the
.fit_transform()method ofmodeltosamples. Assign the result totsne_features. - Select the column
0oftsne_features. Assign the result toxs. - Select the column
1oftsne_features. Assign the result toys. - Make a scatter plot of the t-SNE features
xsandys. To color the points by the grain variety, specify the additional keyword argumentc=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()