File tree Expand file tree Collapse file tree 3 files changed +18
-8
lines changed Expand file tree Collapse file tree 3 files changed +18
-8
lines changed Original file line number Diff line number Diff line change 55#
66# It is made available under the MIT License
77
8- from sklearn .datasets import load_iris
98from matplotlib import pyplot as plt
109
10+ # We load the data with load_iris from sklearn
11+ from sklearn .datasets import load_iris
12+
13+ # load_iris returns an object with several fields
1114data = load_iris ()
1215features = data .data
1316feature_names = data .feature_names
Original file line number Diff line number Diff line change 1010from matplotlib import pyplot as plt
1111from sklearn .datasets import load_iris
1212data = load_iris ()
13- features = data ['data' ]
14- feature_names = data ['feature_names' ]
15- species = data ['target_names' ][data ['target' ]]
13+ features = data .data
14+ feature_names = data .feature_names
15+ target = data .target
16+ target_names = data .target_names
1617
17- is_setosa = (species == 'setosa' )
18+ # We use NumPy fancy indexing to get an array of strings:
19+ labels = target_names [target ]
20+
21+ is_setosa = (labels == 'setosa' )
1822features = features [~ is_setosa ]
19- species = species [~ is_setosa ]
20- is_virginica = (species == 'virginica' )
23+ labels = labels [~ is_setosa ]
24+ is_virginica = (labels == 'virginica' )
2125
2226# Hand fixed threshold:
2327t = 1.75
Original file line number Diff line number Diff line change 1212target = data ['target' ]
1313target_names = data ['target_names' ]
1414labels = target_names [target ]
15-
1615plength = features [:, 2 ]
16+
17+ # To use numpy operations to get setosa features,
18+ # we build a boolean array
1719is_setosa = (labels == 'setosa' )
20+
1821max_setosa = plength [is_setosa ].max ()
1922min_non_setosa = plength [~ is_setosa ].min ()
2023
You can’t perform that action at this time.
0 commit comments