np
.
random
.
seed
(
0
)
X
=
[
(
10
,
2
)
+
[
1
,
1
],
(
10
,
2
)]
y
=
[
1
]
*
10
+
[
-
1
]
*
10
sample_weight
=
100
*
np
.
abs
(
(
20
))
sample_weight
[:
10
]
*=
10
xx
,
yy
=
(
(
-
4
,
5
,
500
),
(
-
4
,
5
,
500
))
fig
,
ax
=
()
ax
.
scatter
(
X
[:,
0
],
X
[:,
1
],
c
=
y
,
s
=
sample_weight
,
alpha
=
0.9
,
cmap
=
plt
.
cm
.
bone
,
edgecolor
=
"black"
,
)
clf
=
(
alpha
=
0.01
,
max_iter
=
100
)
clf
.
fit
(
X
,
y
)
Z
=
clf
.
decision_function
(
[
xx
.
ravel
(),
yy
.
ravel
()])
Z
=
Z
.
reshape
(
xx
.
shape
)
no_weights
=
ax
.
contour
(
xx
,
yy
,
Z
,
levels
=
[
0
],
linestyles
=
[
"solid"
])
clf
=
(
alpha
=
0.01
,
max_iter
=
100
)
clf
.
fit
(
X
,
y
,
sample_weight
=
sample_weight
)
Z
=
clf
.
decision_function
(
[
xx
.
ravel
(),
yy
.
ravel
()])
Z
=
Z
.
reshape
(
xx
.
shape
)
samples_weights
=
ax
.
contour
(
xx
,
yy
,
Z
,
levels
=
[
0
],
linestyles
=
[
"dashed"
])
no_weights_handles
,
_
=
no_weights
.
legend_elements
()
weights_handles
,
_
=
samples_weights
.
legend_elements
()
ax
.
legend
(
[
no_weights_handles
[
0
],
weights_handles
[
0
]],
[
"no weights"
,
"with weights"
],
loc
=
"lower left"
,
)
ax
.
set
(
xticks
=
(),
yticks
=
())
()
Total running time of the script: (0 minutes 0.068 seconds)
Related examples