Skip to content

Instantly share code, notes, and snippets.

Last active September 13, 2016 11:46
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
import matplotlib.pyplot as plt
from sklearn import datasets
from sklearn.decomposition import TruncatedSVD
# Enable saving plot to png file without UI
iris = datasets.load_iris()
X =
y =
# Visualize result using SVD
svd = TruncatedSVD(n_components=2)
X_reduced = svd.fit_transform(X)
# Get min and max sizes for coordinate axis
x_min, x_max = X_reduced[:, 0].min() - .5, X_reduced[:, 0].max() + .5
y_min, y_max = X_reduced[:, 1].min() - .5, X_reduced[:, 1].max() + .5
# Initialize scatter plot with x and y axis values
plt.scatter(X_reduced[:, 0], X_reduced[:, 1], c=y, s=25)
plt.axis([float(x_min), float(x_max), float(y_min), float(y_max)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment