from IPython.core.display import Image, display display(Image(filename='images/iris_setosa.jpg')) print "Iris Setosa\n" display(Image(filename='images/iris_versicolor.jpg')) print "Iris Versicolor\n" display(Image(filename='images/iris_virginica.jpg')) print "Iris Virginica" from sklearn.datasets import load_iris iris = load_iris() iris.keys() n_samples, n_features = iris.data.shape print (n_samples, n_features) print iris.data[0] print iris.data.shape print iris.target.shape print iris.target print iris.target_names %matplotlib inline import numpy as np import matplotlib.pyplot as plt def plot_iris_projection(x_index, y_index): # this formatter will label the colorbar with the correct target names formatter = plt.FuncFormatter(lambda i, *args: iris.target_names[int(i)]) plt.scatter(iris.data[:, x_index], iris.data[:, y_index], c=iris.target) plt.colorbar(ticks=[0, 1, 2], format=formatter) plt.xlabel(iris.feature_names[x_index]) plt.ylabel(iris.feature_names[y_index]) plot_iris_projection(2, 3) from sklearn import datasets from sklearn.datasets import get_data_home get_data_home() !ls $HOME/scikit_learn_data/ from sklearn.datasets import load_digits digits = load_digits() digits.keys() n_samples, n_features = digits.data.shape print (n_samples, n_features) print digits.data[0] print digits.target print digits.data.shape print digits.images.shape print np.all(digits.images.reshape((1797, 64)) == digits.data) print digits.data.__array_interface__['data'] print digits.images.__array_interface__['data'] # set up the figure fig = plt.figure(figsize=(6, 6)) # figure size in inches fig.subplots_adjust(left=0, right=1, bottom=0, top=1, hspace=0.05, wspace=0.05) # plot the digits: each image is 8x8 pixels for i in range(64): ax = fig.add_subplot(8, 8, i + 1, xticks=[], yticks=[]) ax.imshow(digits.images[i], cmap=plt.cm.binary, interpolation='nearest') # label the image with the target value ax.text(0, 7, str(digits.target[i])) from sklearn.datasets import make_s_curve data, colors = make_s_curve(n_samples=1000) print(data.shape) print(colors.shape) from mpl_toolkits.mplot3d import Axes3D ax = plt.axes(projection='3d') ax.scatter(data[:, 0], data[:, 1], data[:, 2], c=colors) ax.view_init(10, -60) from sklearn.datasets import fetch_olivetti_faces # fetch the faces data # Use a script like above to plot the faces image data. # hint: plt.cm.bone is a good colormap for this data # Uncomment the following to load the solution to this exercise # %load solutions/02_faces.py