forked from justmarkham/DAT4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path13_bayes_iris.py
More file actions
30 lines (22 loc) · 758 Bytes
/
13_bayes_iris.py
File metadata and controls
30 lines (22 loc) · 758 Bytes
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
'''
CLASS: Applying Bayes' theorem to iris classification
'''
# load the iris data
from sklearn.datasets import load_iris
iris = load_iris()
# round up the measurements
import numpy as np
X = np.ceil(iris.data)
# clean up column names
features = [name[:-5].replace(' ', '_') for name in iris.feature_names]
# read into pandas
import pandas as pd
df = pd.DataFrame(X, columns=features)
# create a list of species using iris.target and iris.target_names
species = [iris.target_names[num] for num in iris.target]
# add the species list as a new DataFrame column
df['species'] = species
# print the DataFrame
df
# show all observations with features: 7, 3, 5, 2
df[(df.sepal_length==7) & (df.sepal_width==3) & (df.petal_length==5) & (df.petal_width==2)]