Nearest Centroid Classification
from
matplotlib.colors
import
from
sklearn
import
datasets
from
sklearn.inspection
import
DecisionBoundaryDisplay
from
sklearn.neighbors
import
iris
=
()
X
=
iris
.
data
[:,
:
2
]
y
=
iris
.
target
for
shrinkage
in
[
None
,
0.2
]:
clf
=
(
shrink_threshold
=
shrinkage
)
clf
.
fit
(
X
,
y
)
y_pred
=
clf
.
predict
(
X
)
acc
=
(
y
==
y_pred
)
_
,
ax
=
()
disp
=
(
clf
,
X
,
ax
=
ax
,
response_method
=
"predict"
,
alpha
=
0.5
)
cmap
=
(
disp
.
multiclass_colors_
)
(
X
[:,
0
],
X
[:,
1
],
c
=
y
,
cmap
=
cmap
,
edgecolor
=
"k"
,
s
=
20
)
(
f
"3-Class classification (shrink_threshold=
{
shrinkage
}
)
\n
Accuracy:
{
acc
:
.2f
}
"
)
(
"tight"
)
()
Total running time of the script: (0 minutes 0.161 seconds)
Related examples