Professional Documents
Culture Documents
1 2 3 4 5 6 7 8 9 10 Sepallength Sepalwidth Petallength Petalwidth Species
1 2 3 4 5 6 7 8 9 10 Sepallength Sepalwidth Petallength Petalwidth Species
1 2 3 4 5 6 7 8 9 10 Sepallength Sepalwidth Petallength Petalwidth Species
jl ⚡
⋅ using Pkg
⋅ Pkg.add("Clustering")
⋅ Pkg.add("RDatasets")
more
features =
4×150 Array{Float64,2}:
5.1 4.9 4.7 4.6 5.0 5.4 4.6 5.0 … 5.8 6.8 6.7 6.7 6.3 6.5 6.2 5.9
3.5 3.0 3.2 3.1 3.6 3.9 3.4 3.4 2.7 3.2 3.3 3.0 2.5 3.0 3.4 3.0
1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 5.1 5.9 5.7 5.2 5.0 5.2 5.4 5.1
0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 1.9 2.3 2.5 2.3 1.9 2.0 2.3 1.8
⋅ features = collect(Matrix(iris[:,1:4])')
res =
KmeansResult{Array{Float64,2},Float64,Int64}(4×3 Array{Float64,2}: , Int64[2, 2, 2,
5.90161 5.006 6.85
2.74839 3.428 3.07368
4.39355 1.462 5.74211
1.43387 0.246 2.07105
⋅ res = kmeans(features, 3)
localhost:1234/edit?id=a1590a70-4b0c-11eb-378a-67415e11ed15 1/4
2020/12/31 🎈 KMeans.jl ⚡ Pluto.jl ⚡
X = 5×1000 Array{Float64,2}:
0.425544 0.61718 0.573201 … 0.763786 0.708567 0.948852 0.115165
0.591705 0.987675 0.0810505 0.237321 0.182992 0.710342 0.957146
0.00442796 0.963646 0.656056 0.745468 0.137074 0.682515 0.132817
0.159276 0.0442401 0.736157 0.0188291 0.855469 0.950143 0.755111
0.958077 0.96841 0.53596 0.145513 0.670037 0.812596 0.841391
⋅ X = rand(5, 1000)
R =
KmeansResult{Array{Float64,2},Float64,Int64}(5×15 Array{Float64,2}:
0.776648 0.741381 0.721454 0.19869 …
0.302897 0.690129 0.317147 0.661161
0.672359 0.243211 0.793183 0.589928
0.752583 0.739094 0.321394 0.59443
0.690158 0.723916 0.246351 0.204999
true
⋅ nclusters(R) == 15
M = 5×15 Array{Float64,2}:
0.776648 0.741381 0.721454 0.19869 … 0.212292 0.78157 0.253372 0.274885
0.302897 0.690129 0.317147 0.661161 0.345947 0.249006 0.214296 0.759596
0.672359 0.243211 0.793183 0.589928 0.725917 0.223315 0.226449 0.215397
0.752583 0.739094 0.321394 0.59443 0.223952 0.608264 0.687379 0.192026
0.690158 0.723916 0.246351 0.204999 0.760524 0.237421 0.640363 0.478572
⋅ M = R.centers
1. reduce_empty(::typeof(+),
::Type{SubArray{Float64,1,Array{Float64,2},Tuple{Int64,Base.Slice{Base.OneTo{Int64
2. reduce_empty(::typeof(Base.add_sum),
::Type{SubArray{Float64,1,Array{Float64,2},Tuple{Int64,Base.Slice{Base.OneTo{Int64
3. mapreduce_empty(::typeof(identity), ::Function, ::Type{T} where
T) @ reduce.jl:343
4. reduce_empty(::Base.MappingRF{typeof(identity),typeof(Base.add_sum)},
::Type{SubArray{Float64,1,Array{Float64,2},Tuple{Int64,Base.Slice{Base.OneTo{Int64
5. reduce_empty_iter @ reduce.jl:355 [inlined]
6. mapreduce_empty_iter(::Function, ::Function,
::Array{SubArray{Float64,1,Array{Float64,2},Tuple{Int64,Base.Slice{Base.OneTo{Int6
::Base.HasEltype) @ reduce.jl:351
7. _mapreduce(::typeof(identity), ::typeof(Base.add_sum), ::IndexLinear,
::Array{SubArray{Float64,1,Array{Float64,2},Tuple{Int64,Base.Slice{Base.OneTo{Int6
8. _mapreduce_dim @ reducedim.jl:318 [inlined]
9. #mapreduce#620 @ reducedim.jl:310 [inlined]
10. mapreduce @ reducedim.jl:310 [inlined]
11. _sum @ reducedim.jl:727 [inlined]
12. _sum @ reducedim.jl:726 [inlined]
13. #sum#627 @ reducedim.jl:722 [inlined]
14. sum(::Array{SubArray{Float64,1,Array{Float64,2},Tuple{Int64,Base.Slice{Base.OneTo{
15. #kmeans!#1(::Int64, ::Float64, ::typeof(Main.workspace88.kmeans!),
::Array{Float64,2}, ::Int64) @ Other: 14
16. top-level scope @ Local: 1 [inlined]
localhost:1234/edit?id=a1590a70-4b0c-11eb-378a-67415e11ed15 3/4
2020/12/31 🎈 KMeans.jl ⚡ Pluto.jl ⚡
⋅ result, fin = kmeans!(X, 15; maxiters = 300, tol = 1e-5)
localhost:1234/edit?id=a1590a70-4b0c-11eb-378a-67415e11ed15 4/4