This function allows to calibrate the kmeans algorithm. It is possible to obtain
the best k
value and the best embedded algorithm in kmeans.
calkmeans( img, k = NULL, iter.max = 10, algo = c("Hartigan-Wong", "Lloyd", "Forgy", "MacQueen"), iter = 30, verbose = FALSE, ... )
img | RasterStack or RasterBrick. |
---|---|
k | This argument is |
iter.max | The maximum number of iterations allowed. See kmeans. |
algo | It can be "Hartigan-Wong", "Lloyd", "Forgy" or "MacQueen". See kmeans. |
iter | Iterations number to obtain the best k value. |
verbose | This parameter is Logical. It Prints progress messages during execution. |
... | Options to be passed to the function. See 'Details'. |
If the idea is to find the optimal value of k
(clusters or classes),
k = NULL
as an argument of the function must be put, because the function find k for
which the intra-class inertia is stabilized. If the k
value is known and the idea
is to find the best algorithm embedded in kmeans (that maximizes inter-class distances),
k = n
, which n
is a specific class number, must be put.
If warnings such as "Quick-TRANSfer stage steps exceeded maximum" or
"did not converge in 10 iterations" are obtained, it will be necessary to increase the
iterations in 20 or 30 (i.e., inter.max = 20
or iter.max = 30
). This issue is usually
obtained with "Hartigan-Wong". See details of kmeans.
Tarazona, Y., Maria, Miyasiro-Lopez. (2020). Monitoring tropical forest degradation using remote sensing. Challenges and opportunities in the Madre de Dios region, Peru. Remote Sensing Applications: Society and Environment, 19, 100337.
Gareth James, Daniela Witten, Trevor Hastie, Robert Tibshirani. (2013). An introduction to statistical learning : with applications in R. New York: Springer.
library(ForesToolboxRS) # Load the dataset data(img_l8) # Select the best k value best_k <- calkmeans( img = img_l8[[1:2]], k = NULL, iter.max = 10, algo = c("Hartigan-Wong", "Lloyd", "Forgy", "MacQueen"), iter = 30 ) # Jambu Elbow plot(best_k) # Select the best embedded algorithm in kmeans best_algo <- calkmeans( img = img_l8[[1:2]], k = 4, iter.max = 10, algo = c("Hartigan-Wong", "Lloyd", "Forgy", "MacQueen"), iter = 30 ) # Choose the algorithm with the highest value best_algo