@@ -191,29 +191,29 @@ provides mean silhouette metric for the datapoints. Higher values indicate bette
191
191
### Examples
192
192
193
193
Exemplary data with 3 real clusters.
194
- ``` @example
194
+ ``` @example clu_quality
195
195
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
200
205
201
206
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
206
211
)
207
212
```
208
213
209
214
Hard clustering quality for K-means method with 2 to 5 clusters:
210
215
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
217
217
hard_nclusters = 2:5
218
218
clusterings = kmeans.(Ref(X), hard_nclusters)
219
219
@@ -230,12 +230,7 @@ plot((
230
230
```
231
231
232
232
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
239
234
fuzziness = 2
240
235
fuzzy_nclusters = 2:5
241
236
fuzzy_clusterings = fuzzy_cmeans.(Ref(X), fuzzy_nclusters, fuzziness)
0 commit comments