forked from probml/pyprobml
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiris_plot.py
More file actions
46 lines (33 loc) · 1.08 KB
/
iris_plot.py
File metadata and controls
46 lines (33 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import numpy as np
import matplotlib.pyplot as plt
import os
import seaborn as sns;
sns.set(style="ticks", color_codes=True)
import pandas as pd
pd.set_option('precision', 2) # 2 decimal places
pd.set_option('display.max_rows', 20)
pd.set_option('display.max_columns', 30)
pd.set_option('display.width', 100) # wide windows
figdir = "../figures"
def save_fig(fname):
if figdir:
plt.savefig(os.path.join(figdir, fname))
import sklearn
from sklearn.datasets import load_iris
iris = load_iris()
# Extract numpy arrays
X = iris.data
y = iris.target
# Convert to pandas dataframe
df = pd.DataFrame(data=X, columns=['sl', 'sw', 'pl', 'pw'])
# create column for labels
df['label'] = pd.Series(iris.target_names[y], dtype='category')
# 2d scatterplot
#https://seaborn.pydata.org/generated/seaborn.pairplot.html
# Make a dataframe with nicer labels for printing
#iris_df = sns.load_dataset("iris")
iris_df = df.copy()
iris_df.columns = iris['feature_names'] + ['label']
g = sns.pairplot(iris_df, vars = iris_df.columns[0:3] , hue="label")
save_fig("iris-scatterplot.pdf")
plt.show()