how to make a scatter plot matrix iris flower dataset

Solutions on MaxInterview for how to make a scatter plot matrix iris flower dataset by the best coders in the world

showing results for - "how to make a scatter plot matrix iris flower dataset"
Martina
23 Jan 2016
1import matplotlib.pyplot as plt
2from sklearn.datasets import load_iris
3import numpy as np
4
5 #setting the shape of the figure in one line as opposed to creating 12 variables
6fig, subs = plt.subplots(4,3) 
7
8#code given in Hyperion notes
9iris = load_iris()
10data = np.array(iris['data'])
11targets = np.array(iris['target'])
12
13cd = {0:'r',1:'b',2:"g"}
14cols = np.array([cd[target] for target in targets])
15#ROW 1
16subs[0][0].scatter(data[:,0], data[:,1], c=cols)
17subs[0][1].scatter(data[:,0], data[:,2], c=cols)
18subs[0][2].scatter(data[:,0], data[:,3], c=cols)
19#ROW 2
20subs[1][0].scatter(data[:,1], data[:,0], c=cols)
21subs[1][1].scatter(data[:,1], data[:,2], c=cols)
22subs[1][2].scatter(data[:,1], data[:,3], c=cols)
23#ROW 3
24subs[2][0].scatter(data[:,2], data[:,0], c=cols)
25subs[2][1].scatter(data[:,2], data[:,1], c=cols)
26subs[2][2].scatter(data[:,2], data[:,3], c=cols)
27#ROW 4
28subs[3][0].scatter(data[:,3], data[:,0], c=cols)
29subs[3][1].scatter(data[:,3], data[:,1], c=cols)
30subs[3][2].scatter(data[:,3], data[:,2], c=cols)
31#show data plot
32plt.show()