CHI*_* YI 5 plot scatter-plot julia
如果我想画一条边界线来分隔两个类,这是我的分类器的结果。怎么画呢?图片是样本,黑线是我要画的边界。绿色点是边界点。我想画一条完美拟合这些点的曲线。但是当我绘制这些曲线时,结果是紫色线,它不是曲线。
这是一个可重现的示例,说明如何执行此操作:
using Plots
x = rand(1000)
y = rand(1000)
color = [3 * (b-0.5)^2 < a - 0.1 ? "red" : "blue" for (a, b) in zip(x, y)]
y_bound = 0:0.01:1
x_bound = @. 3 * (y_bound - 0.5)^2 + 0.1
scatter(x, y, color=color, legend=false)
plot!(x_bound, y_bound, color="green")
Run Code Online (Sandbox Code Playgroud)
这里的关键是使边界点有序(即它们必须在向量中正确排序,以便在绘制线条时连接正确的点)。在我的示例中,我通过改变 y 维度并计算 x 维度来实现它。
在更复杂的情况下,最好使用等高线图,例如:
x = 1:0.1:8
y = 1:0.1:7
f(x, y) = begin
(3x + y ^ 2) * abs(sin(x) + cos(y)) - 40
end
X = repeat(reshape(x, 1, :), length(y), 1)
Y = repeat(y, 1, length(x))
Z = map(f, X, Y)
contour(x, y, Z, levels=[0], color="green", width=3)
x_s = 7 .* rand(1000) .+ 1
y_s = 6 .* rand(1000) .+ 1
color = [f(a, b) > 0 ? "red" : "blue" for (a, b) in zip(x_s, y_s)]
scatter!(x_s, y_s, color=color, legend=false)
Run Code Online (Sandbox Code Playgroud)
但是,正如您所看到的,这次为了获得最佳结果,最好将分数传递给contour并将分类阈值指定为级别。