FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
dl_tutorial/examples/iris_classification.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.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
28 lines (24 loc) · 1.05 KB
Breadcrumbs
dl_tutorial
/
examples
/
iris_classification.py
Copy path
File metadata and controls
28 lines (24 loc) · 1.05 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
import
numpy
as
np
import
matplotlib
.
pyplot
as
plt
from
sklearn
import
(
datasets
,
svm
)
from
matplotlib
.
lines
import
Line2D
# For the custom legend
# Load a dataset
iris
=
datasets
.
load_iris
()
# Train a model
model
=
svm
.
SVC
()
# Accuracy: 0.973 (146/150)
model
.
fit
(
iris
.
data
,
iris
.
target
)
# Try 'iris.data[:,0:2]' (Accuracy: 0.820)
# Test the model
predict
=
model
.
predict
(
iris
.
data
)
# Try 'iris.data[:,0:2]' (Accuracy: 0.820)
n_correct
=
sum
(
predict
==
iris
.
target
)
accuracy
=
n_correct
/
len
(
iris
.
data
)
# Visualize testing results
cmap
=
np
.
array
([(
1
,
0
,
0
), (
0
,
1
,
0
), (
0
,
0
,
1
)])
clabel
=
[
Line2D
([
0
], [
0
],
marker
=
'o'
,
lw
=
0
,
label
=
iris
.
target_names
[
i
],
color
=
cmap
[
i
])
for
i
in
range
(
len
(
cmap
))]
for
(
x
,
y
)
in
[(
0
,
1
), (
2
,
3
)]:
plt
.
figure
()
plt
.
title
(
f'svm.SVC (
{
n_correct
}
/
{
len
(
iris
.
data
)
}
=
{
accuracy
:.3f
}
)'
)
plt
.
scatter
(
iris
.
data
[:,
x
],
iris
.
data
[:,
y
],
c
=
cmap
[
iris
.
target
],
edgecolors
=
cmap
[
predict
])
plt
.
xlabel
(
iris
.
feature_names
[
x
])
plt
.
ylabel
(
iris
.
feature_names
[
y
])
plt
.
legend
(
handles
=
clabel
,
framealpha
=
0.5
)
plt
.
show
()
Back
|
FazBrowse Home
|
New Git URL