from pylab import loadtxt, figure, plot, subplot, axis, clf, show

# The last column of the data sets is a label, which is used to distinguish the
# three groups of data in the data sets. This label should be translated to a
# floating point, or a conversion error will occur (since ``dtype=float'').
cnvt_dict = {'Iris-setosa': 0.0, 'Iris-versicolor': 1.0, 'Iris-virginica': 2.0}
data = loadtxt('iris.data', delimiter=',', dtype=float, \
        converters={4: lambda s: not s in cnvt_dict and -1.0 or cnvt_dict[s]})

# Transform the data set into plottable graph data
graph_data = [[[] for i in range(3)] for j in range(16)]
for i in range(4):
    for j in range(4):
        if i != j:
            for d in data:
                graph_data[i + j*4][int(d[4])].append((d[i], d[j]));

# Different colors for different data types (map these colors to cnvt_dict).
colors = ['r', 'g', 'b']
figure(16)
clf()
for i in range(4):
    for j in range(4):
        if i != j:
            subplot(4, 4, (i+1) + j*4)
            axis('equal')
            # Plot the three data sets.
            for c in range(3):
                tmp = zip(*graph_data[i + j*4][c])
                plot(tmp[0], tmp[1], 'x' + colors[c])
# In the following plot, we can see that the colored areas do not overlap in
# the same place in all subplots. Thus, using all plots, we could probably
# classify a given data point to one of the iris classes (except for some points
# in the blue/green areas, these overlap much in a small area).
show()
