FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
dl_tutorial/examples/iris_classification_more.py at master · mint-lab/dl_tutorial · GitHub
mint-lab
/
dl_tutorial
Public
Notifications
You must be signed in to change notification settings
Fork
4
Star
17
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
dl_tutorial
/
examples
/
iris_classification_more.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
67 lines (56 loc) · 3.4 KB
Breadcrumbs
dl_tutorial
/
examples
/
iris_classification_more.py
Copy path
File metadata and controls
67 lines (56 loc) · 3.4 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import
numpy
as
np
import
matplotlib
.
pyplot
as
plt
from
sklearn
import
(
datasets
,
linear_model
,
naive_bayes
,
neural_network
,
neighbors
,
svm
,
tree
,
ensemble
,
metrics
)
from
matplotlib
.
colors
import
ListedColormap
# Load a dataset partially
iris
=
datasets
.
load_iris
()
iris
.
data
=
iris
.
data
[:,
0
:
2
]
iris
.
feature_names
=
iris
.
feature_names
[
0
:
2
]
iris
.
color
=
np
.
array
([(
1
,
0
,
0
), (
0
,
1
,
0
), (
0
,
0
,
1
)])
# Instantiate classification models
models
=
[
{
'name'
:
'linear_model.SGD'
,
'obj'
:
linear_model
.
SGDClassifier
()},
{
'name'
:
'naive_bayes.Gaussian'
,
'obj'
:
naive_bayes
.
GaussianNB
()},
{
'name'
:
'neural_network.MLP'
,
'obj'
:
neural_network
.
MLPClassifier
()},
{
'name'
:
'neighbors.KNN'
,
'obj'
:
neighbors
.
KNeighborsClassifier
()},
{
'name'
:
'svm.LinearSVC'
,
'obj'
:
svm
.
LinearSVC
()},
{
'name'
:
'svm.SVC(linear)'
,
'obj'
:
svm
.
SVC
(
kernel
=
'linear'
)},
{
'name'
:
'svm.SVC(poly,2)'
,
'obj'
:
svm
.
SVC
(
kernel
=
'poly'
,
degree
=
2
)},
{
'name'
:
'svm.SVC(poly,3)'
,
'obj'
:
svm
.
SVC
(
kernel
=
'poly'
)},
{
'name'
:
'svm.SVC(poly,4)'
,
'obj'
:
svm
.
SVC
(
kernel
=
'poly'
,
degree
=
4
)},
{
'name'
:
'svm.SVC(rbf)'
,
'obj'
:
svm
.
SVC
(
kernel
=
'rbf'
)},
{
'name'
:
'svm.SVC(rbf,$\gamma$=1)'
,
'obj'
:
svm
.
SVC
(
kernel
=
'rbf'
,
gamma
=
1
)},
{
'name'
:
'svm.SVC(rbf,$\gamma$=4)'
,
'obj'
:
svm
.
SVC
(
kernel
=
'rbf'
,
gamma
=
4
)},
{
'name'
:
'svm.SVC(rbf,$\gamma$=16)'
,
'obj'
:
svm
.
SVC
(
kernel
=
'rbf'
,
gamma
=
16
)},
{
'name'
:
'svm.SVC(rbf,$\gamma$=64)'
,
'obj'
:
svm
.
SVC
(
kernel
=
'rbf'
,
gamma
=
64
)},
{
'name'
:
'svm.SVC(sigmoid)'
,
'obj'
:
svm
.
SVC
(
kernel
=
'sigmoid'
)},
{
'name'
:
'tree.DecisionTree(2)'
,
'obj'
:
tree
.
DecisionTreeClassifier
(
max_depth
=
2
)},
{
'name'
:
'tree.DecisionTree(4)'
,
'obj'
:
tree
.
DecisionTreeClassifier
(
max_depth
=
4
)},
{
'name'
:
'tree.DecisionTree(N)'
,
'obj'
:
tree
.
DecisionTreeClassifier
()},
{
'name'
:
'tree.ExtraTree'
,
'obj'
:
tree
.
ExtraTreeClassifier
()},
{
'name'
:
'ensemble.RandomForest(10)'
,
'obj'
:
ensemble
.
RandomForestClassifier
(
n_estimators
=
10
)},
{
'name'
:
'ensemble.RandomForest(100)'
,
'obj'
:
ensemble
.
RandomForestClassifier
()},
{
'name'
:
'ensemble.ExtraTrees(10)'
,
'obj'
:
ensemble
.
ExtraTreesClassifier
(
n_estimators
=
10
)},
{
'name'
:
'ensemble.ExtraTrees(100)'
,
'obj'
:
ensemble
.
ExtraTreesClassifier
()},
{
'name'
:
'ensemble.AdaBoost(DTree)'
,
'obj'
:
ensemble
.
AdaBoostClassifier
(
tree
.
DecisionTreeClassifier
())},
]
x_min
,
x_max
=
iris
.
data
[:,
0
].
min
()
-
1
,
iris
.
data
[:,
0
].
max
()
+
1
y_min
,
y_max
=
iris
.
data
[:,
1
].
min
()
-
1
,
iris
.
data
[:,
1
].
max
()
+
1
xx
,
yy
=
np
.
meshgrid
(
np
.
arange
(
x_min
,
x_max
,
0.01
),
np
.
arange
(
y_min
,
y_max
,
0.01
))
xy
=
np
.
vstack
((
xx
.
flatten
(),
yy
.
flatten
())).
T
for
model
in
models
:
# Train a model
model
[
'obj'
].
fit
(
iris
.
data
,
iris
.
target
)
# Test the model
predict
=
model
[
'obj'
].
predict
(
iris
.
data
)
model
[
'acc'
]
=
metrics
.
balanced_accuracy_score
(
iris
.
target
,
predict
)
# Visualize training results (decision boundaries)
zz
=
model
[
'obj'
].
predict
(
xy
)
plt
.
figure
()
plt
.
contourf
(
xx
,
yy
,
zz
.
reshape
(
xx
.
shape
),
cmap
=
ListedColormap
(
iris
.
color
),
alpha
=
0.2
)
# Visualize testing results
plt
.
title
(
model
[
'name'
]
+
f' (
{
model
[
"acc"
]:.3f
}
)'
)
plt
.
scatter
(
iris
.
data
[:,
0
],
iris
.
data
[:,
1
],
c
=
iris
.
color
[
iris
.
target
],
edgecolors
=
iris
.
color
[
predict
])
plt
.
xlabel
(
iris
.
feature_names
[
0
])
plt
.
ylabel
(
iris
.
feature_names
[
1
])
plt
.
show
()
Back
|
FazBrowse Home
|
New Git URL