Skip to content

Instantly share code, notes, and snippets.

@ggauravr
Last active December 27, 2015 03:48
Show Gist options
  • Save ggauravr/7261723 to your computer and use it in GitHub Desktop.
Save ggauravr/7261723 to your computer and use it in GitHub Desktop.
this code demonstrates and describes basic visualization(2 out of four features) of the Iris Dataset, provided in the sklearn package.
from matplotlib import pyplot as plt
from sklearn.datasets import load_iris
import numpy as np
# load the dataset to be used
iris = load_iris()
# get the 150*4 features into varibale features
features = iris.data
# optional : useful to give labels to the axes
feature_names = iris.feature_names
# holds an array of nSamples(150 in this case), with class labels(Iris Setose=0, Iris Versicolor=1, Iris Virginica=2)
target = iris.target
print feature_names # prints ['sepal length (cm)', 'sepal width (cm)', 'petal length (cm)', 'petal width (cm)']
# zip function returns tuples, in i-th iteration, gives tuples containing i-th element of each argument passes
for t, marker, c in zip(xrange(3), ">oo", "rgb"):
plt.scatter(features[target == t, 1],
features[target == t, 2],
marker = marker,
c=c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment