In [1]:
# == Basic import == #
# plot within the notebook
%matplotlib inline
# No annoying warnings
import warnings
warnings.filterwarnings('ignore')
In [2]:
import numpy as np
In [3]:
datafile = open("data/iris.csv").read().splitlines()
In [4]:
entires = np.asarray(datafile[0].split(","))
In [5]:
entires
Out[5]:
In [6]:
sepal_length, sepal_width, petal_length, petal_width,species = [],[],[],[],[] # DON'T do [[]]*5
In [7]:
sepal_length
Out[7]:
In [8]:
for dd in datafile[1:]:
sepal_length_, sepal_width_, petal_length_, petal_width_,species_ = dd.split(",")
sepal_length.append(sepal_length_)
sepal_width.append(sepal_width_)
petal_length.append(petal_length_)
petal_width.append(petal_width_)
species.append(species_)
sepal_length = np.asarray(sepal_length)
sepal_width = np.asarray(sepal_width)
petal_length = np.asarray(petal_length)
petal_width = np.asarray(petal_width)
species = np.asarray(species)
In [9]:
species_unique = np.unique(species)
In [13]:
sepal_length, sepal_width, petal_length, petal_width,species = np.asarray([dd.split(",") for dd in datafile[1:]]).T
In [31]:
sepal_length[species=="setosa"]
Out[31]:
In [33]:
sepal_length[species=="versicolor"]
Out[33]:
In [34]:
import matplotlib.pyplot as mpl
In [45]:
mpl.scatter(sepal_length[species=="versicolor"], petal_length[species=="versicolor"],
s=150, facecolors=mpl.cm.Blues(0.6,0.4), label="versicolor")
mpl.scatter(sepal_length[species=="setosa"], petal_length[species=="setosa"],
s=150, facecolors=mpl.cm.Reds(0.6,0.4), label="setosa")
mpl.scatter(sepal_length[species=="virginica"], petal_length[species=="virginica"],
s=150, facecolors=mpl.cm.Greens(0.6,0.4), label="virginica")
mpl.xlabel("Sepal Length", fontsize = "xx-large")
mpl.ylabel("Petal Length", fontsize = "xx-large")
mpl.legend(loc="upper left", frameon=False)
Out[45]: