@@ -19,16 +19,15 @@ mutable struct KMeans <: MMI.Unsupervised
1919 max_iters:: Int
2020 copy:: Bool
2121 threads:: Int
22- verbosity:: Int
2322 init
2423end
2524
2625
2726function KMeans (; algo= :Hamerly , k_init= " k-means++" ,
2827 k= 3 , tol= 1e-6 , max_iters= 300 , copy= true ,
29- threads= Threads. nthreads (), verbosity = 0 , init= nothing )
28+ threads= Threads. nthreads (), init= nothing )
3029
31- model = KMeans (algo, k_init, k, tol, max_iters, copy, threads, verbosity, init)
30+ model = KMeans (algo, k_init, k, tol, max_iters, copy, threads, init)
3231 message = MMI. clean! (model)
3332 isempty (message) || @warn message
3433 return model
@@ -68,11 +67,6 @@ function MMI.clean!(m::KMeans)
6867 m. threads = Threads. nthreads ()
6968 end
7069
71- if ! (m. verbosity ∈ (0 , 1 ))
72- push! (warning, " Verbosity must be either 0 (no info) or 1 (info requested). Defaulting to 1." )
73- m. verbosity = 1
74- end
75-
7670 return join (warning, " \n " )
7771end
7872
8579
8680 See also the [package documentation](https://pydatablog.github.io/ParallelKMeans.jl/stable).
8781"""
88- function MMI. fit (m:: KMeans , X)
82+ function MMI. fit (m:: KMeans , verbosity :: Int , X)
8983 # convert tabular input data into the matrix model expects. Column assumed as features so input data is permuted
9084 if ! m. copy
9185 # permutes dimensions of input table without copying and pass to model
@@ -99,16 +93,22 @@ function MMI.fit(m::KMeans, X)
9993 algo = MLJDICT[m. algo] # select algo
10094
10195 # fit model and get results
102- verbose = m . verbosity != 0
96+ verbose = verbosity > 0 # Display fitting operations if verbosity > 0
10397 fitresult = ParallelKMeans. kmeans (algo, DMatrix, m. k;
10498 n_threads = m. threads, k_init= m. k_init,
10599 max_iters= m. max_iters, tol= m. tol, init= m. init,
106100 verbose= verbose)
101+
107102 cache = nothing
108103 report = (cluster_centers= fitresult. centers, iterations= fitresult. iterations,
109104 converged= fitresult. converged, totalcost= fitresult. totalcost,
110105 labels= fitresult. assignments)
111-
106+ """
107+ # TODO: warn users about non convergence
108+ if verbose & (!fitresult.converged)
109+ @warn "Specified model failed to converge."
110+ end
111+ """
112112 return (fitresult, cache, report)
113113end
114114
@@ -144,7 +144,7 @@ function MMI.transform(m::KMeans, fitresult, Xnew)
144144
145145 # Warn users if fitresult is from a `non-converged` fit
146146 if ! fitresult[end ]. converged
147- @warn " Failed to converged . Using last assignments to make transformations."
147+ @warn " Failed to converge . Using last assignments to make transformations."
148148 end
149149
150150 # results from fitted model
@@ -175,7 +175,7 @@ MMI.metadata_pkg.(KMeans,
175175# Metadata for ParaKMeans model interface
176176MMI. metadata_model (KMeans,
177177 input = MMI. Table (MMI. Continuous),
178- output = MMI. Table (MMI. Count ),
178+ output = MMI. Table (MMI. Continuous ),
179179 weights = false ,
180180 descr = ParallelKMeans_Desc,
181181 path = " ParallelKMeans.KMeans" )
0 commit comments