|
38 | 38 |
|
39 | 39 | function MLJModelInterface.clean!(m::KMeans) |
40 | 40 | warning = "" |
| 41 | + |
41 | 42 | if !(m.algo ∈ keys(MLJDICT)) |
42 | | - warning *= "Unsuppored algorithm supplied. Please check documentation for supported Kmeans algorithms." |
| 43 | + warning *= "Unsuppored algorithm supplied. Defauting to KMeans++ seeding algorithm." |
| 44 | + m.algo = :Lloyd |
| 45 | + |
| 46 | + elseif m.k_init != "k-means++" |
| 47 | + warning *= "Only `k-means++` or random seeding algorithms are supported. Defaulting to random seeding." |
| 48 | + m.k_init = "random" |
| 49 | + |
43 | 50 | elseif m.k < 1 |
44 | | - warning *= "Number of clusters must be greater than 0." |
| 51 | + warning *= "Number of clusters must be greater than 0. Defaulting to 3 clusters." |
| 52 | + m.k = 3 |
| 53 | + |
45 | 54 | elseif !(m.tol < 1.0) |
46 | | - warning *= "Tolerance level must be less than 1." |
| 55 | + warning *= "Tolerance level must be less than 1. Defaulting to tol of 1e-6." |
| 56 | + m.tol = 1e-6 |
| 57 | + |
47 | 58 | elseif !(m.max_iters > 0) |
48 | | - warning *= "Number of permitted iterations must be greater than 0." |
| 59 | + warning *= "Number of permitted iterations must be greater than 0. Defaulting to 300 iterations." |
| 60 | + m.max_iters = 300 |
| 61 | + |
49 | 62 | elseif !(m.threads > 0) |
50 | | - warning *= "Number of threads must be at least 1." |
| 63 | + warning *= "Number of threads must be at least 1. Defaulting to all threads available." |
| 64 | + m.threads = Threads.nthreads() |
| 65 | + |
51 | 66 | elseif !(m.verbosity ∈ (0, 1)) |
52 | | - warning *= "Verbosity must be either 0 (no info) or 1 (info requested)" |
| 67 | + warning *= "Verbosity must be either 0 (no info) or 1 (info requested). Defaulting to 0." |
| 68 | + m.verbosity = 0 |
53 | 69 | end |
54 | 70 | return warning |
55 | 71 | end |
|
61 | 77 | #### |
62 | 78 | """ |
63 | 79 | TODO 3.1: Docs |
| 80 | + # fit the specified struct as a ParaKMeans model |
64 | 81 |
|
65 | 82 | See also the [package documentation](https://pydatablog.github.io/ParallelKMeans.jl/stable). |
66 | 83 | """ |
67 | 84 | function MLJModelInterface.fit(m::KMeans, X) |
68 | | - # fit the specified struct as a ParaKMeans model |
69 | | - |
70 | 85 | # convert tabular input data into the matrix model expects. Column assumed as features so input data is permuted |
71 | 86 | if !m.copy |
72 | 87 | # transpose input table without copying and pass to model |
@@ -152,4 +167,4 @@ metadata_model(KMeans, |
152 | 167 | output = MLJModelInterface.Table(MLJModelInterface.Count), |
153 | 168 | weights = false, |
154 | 169 | descr = ParallelKMeans_Desc, |
155 | | - path = "ParallelKMeans.src.mlj_interface.KMeans") |
| 170 | + path = "ParallelKMeans.KMeans") |
0 commit comments