|
1 | | -#' @rdname model_parameters.kmeans |
2 | | -#' @inheritParams cluster_centers |
| 1 | +#' Parameters from Cluster Models (k-means, ...) |
| 2 | +#' |
| 3 | +#' Format cluster models obtained for example by [kmeans()]. |
| 4 | +#' |
| 5 | +#' @param model Cluster model. |
| 6 | +#' @inheritParams model_parameters.default |
| 7 | +#' @param ... Arguments passed to or from other methods. |
| 8 | +#' |
| 9 | +#' @examplesIf require("factoextra", quietly = TRUE) && require("dbscan", quietly = TRUE) && require("cluster", quietly = TRUE) && require("fpc", quietly = TRUE) |
| 10 | +#' \donttest{ |
| 11 | +#' # |
| 12 | +#' # K-means ------------------------------- |
| 13 | +#' model <- kmeans(iris[1:4], centers = 3) |
| 14 | +#' rez <- model_parameters(model) |
| 15 | +#' rez |
| 16 | +#' |
| 17 | +#' # Get clusters |
| 18 | +#' predict(rez) |
| 19 | +#' |
| 20 | +#' # Clusters centers in long form |
| 21 | +#' attributes(rez)$means |
| 22 | +#' |
| 23 | +#' # Between and Total Sum of Squares |
| 24 | +#' attributes(rez)$Sum_Squares_Total |
| 25 | +#' attributes(rez)$Sum_Squares_Between |
3 | 26 | #' |
4 | | -#' @examples |
5 | 27 | #' # |
6 | 28 | #' # Hierarchical clustering (hclust) --------------------------- |
7 | 29 | #' data <- iris[1:4] |
|
20 | 42 | #' # Between and Total Sum of Squares |
21 | 43 | #' attributes(rez)$Total_Sum_Squares |
22 | 44 | #' attributes(rez)$Between_Sum_Squares |
| 45 | +#' |
| 46 | +#' # |
| 47 | +#' # Hierarchical K-means (factoextra::hkclust) ---------------------- |
| 48 | +#' data <- iris[1:4] |
| 49 | +#' model <- factoextra::hkmeans(data, k = 3) |
| 50 | +#' |
| 51 | +#' rez <- model_parameters(model) |
| 52 | +#' rez |
| 53 | +#' |
| 54 | +#' # Get clusters |
| 55 | +#' predict(rez) |
| 56 | +#' |
| 57 | +#' # Clusters centers in long form |
| 58 | +#' attributes(rez)$means |
| 59 | +#' |
| 60 | +#' # Between and Total Sum of Squares |
| 61 | +#' attributes(rez)$Sum_Squares_Total |
| 62 | +#' attributes(rez)$Sum_Squares_Between |
| 63 | +#' |
| 64 | +#' # K-Medoids (PAM and HPAM) ============== |
| 65 | +#' model <- cluster::pam(iris[1:4], k = 3) |
| 66 | +#' model_parameters(model) |
| 67 | +#' |
| 68 | +#' model <- fpc::pamk(iris[1:4], criterion = "ch") |
| 69 | +#' model_parameters(model) |
| 70 | +#' |
| 71 | +#' # DBSCAN --------------------------- |
| 72 | +#' model <- dbscan::dbscan(iris[1:4], eps = 1.45, minPts = 10) |
| 73 | +#' |
| 74 | +#' rez <- model_parameters(model, iris[1:4]) |
| 75 | +#' rez |
| 76 | +#' |
| 77 | +#' # Get clusters |
| 78 | +#' predict(rez) |
| 79 | +#' |
| 80 | +#' # Clusters centers in long form |
| 81 | +#' attributes(rez)$means |
| 82 | +#' |
| 83 | +#' # Between and Total Sum of Squares |
| 84 | +#' attributes(rez)$Sum_Squares_Total |
| 85 | +#' attributes(rez)$Sum_Squares_Between |
| 86 | +#' |
| 87 | +#' # HDBSCAN |
| 88 | +#' model <- dbscan::hdbscan(iris[1:4], minPts = 10) |
| 89 | +#' model_parameters(model, iris[1:4]) |
| 90 | +#' } |
23 | 91 | #' @export |
24 | 92 | model_parameters.hclust <- function(model, data = NULL, clusters = NULL, ...) { |
25 | 93 | if (is.null(data)) { |
@@ -58,34 +126,6 @@ model_parameters.hclust <- function(model, data = NULL, clusters = NULL, ...) { |
58 | 126 |
|
59 | 127 |
|
60 | 128 | #' @inheritParams n_clusters |
61 | | -#' @rdname model_parameters.kmeans |
62 | | -#' @examples |
63 | | -#' \donttest{ |
64 | | -#' # |
65 | | -#' # pvclust (finds "significant" clusters) --------------------------- |
66 | | -#' if (require("pvclust", quietly = TRUE)) { |
67 | | -#' data <- iris[1:4] |
68 | | -#' # NOTE: pvclust works on transposed data |
69 | | -#' model <- pvclust::pvclust(datawizard::data_transpose(data, verbose = FALSE), |
70 | | -#' method.dist = "euclidean", |
71 | | -#' nboot = 50, |
72 | | -#' quiet = TRUE |
73 | | -#' ) |
74 | | -#' |
75 | | -#' rez <- model_parameters(model, data, ci = 0.90) |
76 | | -#' rez |
77 | | -#' |
78 | | -#' # Get clusters |
79 | | -#' predict(rez) |
80 | | -#' |
81 | | -#' # Clusters centers in long form |
82 | | -#' attributes(rez)$means |
83 | | -#' |
84 | | -#' # Between and Total Sum of Squares |
85 | | -#' attributes(rez)$Sum_Squares_Total |
86 | | -#' attributes(rez)$Sum_Squares_Between |
87 | | -#' } |
88 | | -#' } |
89 | 129 | #' @export |
90 | 130 | model_parameters.pvclust <- function(model, data = NULL, clusters = NULL, ci = 0.95, ...) { |
91 | 131 | if (is.null(data)) { |
|
0 commit comments