forked from justmarkham/DAT3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
08_iris_class.py
51 lines (31 loc) · 1.17 KB
/
08_iris_class.py
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
46
47
48
49
50
51
'''
CLASS: "Human Learning" with iris data
'''
from sklearn.datasets import load_iris
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# load the famous iris data
iris = load_iris()
# what do you think these attributes represent?
iris.data
iris.data.shape
iris.feature_names
iris.target
iris.target_names
# intro to numpy
type(iris.data)
## PART 1: Read data into pandas and explore
# read iris.data into a pandas DataFrame (df), including column names
# clean up column names
# read into pandas again, with better column names
# create a list of species (150 elements) using iris.target and iris.target_names
# add the species list as a new DataFrame column
# explore data numerically, looking for differences between species
# explore data by sorting, looking for differences between species
# explore data visually, looking for differences between species
## PART 2: Write a function to predict the species for each observation
# create a dictionary so we can reference columns by name
# define function that takes in a row of data and returns a predicted species
# make predictions and store as numpy array
# calculate the accuracy of the predictions