Skip to content

Commit 42e68e1

Browse files
committed
validate: reuse clu_quality_data
1 parent cc6e252 commit 42e68e1

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

docs/source/validate.md

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -191,29 +191,29 @@ provides mean silhouette metric for the datapoints. Higher values indicate bette
191191
### Examples
192192

193193
Exemplary data with 3 real clusters.
194-
```@example
194+
```@example clu_quality
195195
using Plots, Clustering
196-
X = hcat([4., 5.] .+ 0.4 * randn(2, 10),
197-
[9., -5.] .+ 0.4 * randn(2, 5),
198-
[-4., -9.] .+ 1 * randn(2, 5))
199-
196+
X_clusters = [(center = [4., 5.], std = 0.4, n = 10),
197+
(center = [9., -5.], std = 0.4, n = 5),
198+
(center = [-4., -9.], std = 1, n = 5)]
199+
X = mapreduce(hcat, X_clusters) do (center, std, n)
200+
center .+ std .* randn(length(center), n)
201+
end
202+
X_assignments = mapreduce(vcat, enumerate(X_clusters)) do (i, (_, _, n))
203+
fill(i, n)
204+
end
200205
201206
scatter(view(X, 1, :), view(X, 2, :),
202-
label = "data points",
203-
xlabel = "x",
204-
ylabel = "y",
205-
legend = :right,
207+
markercolor = X_assignments,
208+
plot_title = "Data", label = nothing,
209+
xlabel = "x", ylabel = "y",
210+
legend = :outerright
206211
)
207212
```
208213

209214
Hard clustering quality for K-means method with 2 to 5 clusters:
210215

211-
```@example
212-
using Plots, Clustering
213-
X = hcat([4., 5.] .+ 0.4 * randn(2, 10),
214-
[9., -5.] .+ 0.4 * randn(2, 5),
215-
[-4., -9.] .+ 1 * randn(2, 5))
216-
216+
```@example clu_quality
217217
hard_nclusters = 2:5
218218
clusterings = kmeans.(Ref(X), hard_nclusters)
219219
@@ -230,12 +230,7 @@ plot((
230230
```
231231

232232
Fuzzy clustering quality for fuzzy C-means method with 2 to 5 clusters:
233-
```@example
234-
using Plots, Clustering
235-
X = hcat([4., 5.] .+ 0.4 * randn(2, 10),
236-
[9., -5.] .+ 0.4 * randn(2, 5),
237-
[-4., -9.] .+ 1 * randn(2, 5))
238-
233+
```@example clu_quality
239234
fuzziness = 2
240235
fuzzy_nclusters = 2:5
241236
fuzzy_clusterings = fuzzy_cmeans.(Ref(X), fuzzy_nclusters, fuzziness)

0 commit comments

Comments
 (0)