Repository navigation
[Improvement] Improvements to n_clusters() - #1295
Open
DominiqueMakowski wants to merge 5 commits into
Open
DominiqueMakowski wants to merge 5 commits into
DominiqueMakowski wants to merge 5 commits into
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The new hkmeans class assignment drops kmeans inheritance, breaking prediction because the package defines predict.kmeans() but no predict.hkmeans() method.
4 open issues
2 files not reviewed
man/cluster_analysis.Rd: Generated fileman/n_clusters.Rd: Generated file
What changed in this PR
This PR improves cluster-count selection and removes the factoextra dependency from the package’s clustering tools.
Changes:
- Computes clustering diagnostics and hierarchical k-means directly using base R and
cluster. - Corrects voting, argument handling, and random-seed preservation in
n_clusters(), and enables the M3C branch. - Adds regression tests and updates documentation, examples, and release notes.
| File | Description |
|---|---|
vignettes/clustering.Rmd |
Removes factoextra setup requirements. |
tests/testthat/test-n_clusters.R |
Adds coverage for voting, seed preservation, and diagnostic calculations. |
tests/testthat/test-cluster_analysis.R |
Tests hierarchical k-means initialization and stored predictions. |
R/n_clusters.R |
Updates method voting, backend handling, and BIC metadata. |
R/n_clusters_easystats.R |
Replaces factoextra calls with direct diagnostic calculations. |
R/cluster_analysis.R |
Implements hierarchical k-means locally. |
NEWS.md |
Documents clustering improvements and fixes. |
man/n_clusters.Rd |
Updates scaling guidance and example dependencies. |
man/cluster_analysis.Rd |
Updates hierarchical k-means documentation and scaling guidance. |
DESCRIPTION |
Removes factoextra from suggested dependencies. |
Review effort: Balanced
| iter.max = iterations, | ||
| algorithm = kmeans_method | ||
| ) | ||
| class(model) <- "hkmeans" |
Comment on lines
+14
to
+18
| * *factoextra* is no longer needed. `n_clusters_elbow()`, | ||
| `n_clusters_silhouette()`, `n_clusters_gap()` and `n_clusters()` now compute | ||
| the within-cluster sum of squares, the silhouette width and the gap statistic | ||
| directly (with *cluster*). `cluster_analysis(method = "hkmeans")` runs the | ||
| hierarchical k-means itself. The results are the same as before. The |
| iter.max = iterations, hc.method = hclust_method, ... | ||
| # Hierarchical k-means, as in factoextra::hkmeans(): the centers of the | ||
| # clusters from a hierarchical clustering are the initial centers of k-means | ||
| hc <- stats::hclust(stats::dist(cluster_data), method = hclust_method) |
|
|
||
| if ("M3C" %in% tolower(package)) { | ||
| if ("m3c" %in% tolower(package)) { | ||
| out <- rbind(out, .n_clusters_M3C(x, n_max = n_max, fast = fast)) |
- Apply the air formatting suggestions. - hkmeans: honour `hc.metric` (as factoextra::hkmeans() did), and keep the "kmeans" class so that predict() with newdata works. - Restore the user's random seed after M3C::M3C(), which calls set.seed(), with a helper shared with the NbClust methods. - Bump the development version to 0.30.0.17. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
predict() for cluster_meta() gets a `method` argument passed to hclust(), with "average" as the default (instead of "complete"), the usual choice for consensus matrices (Monti et al., 2003). With few solutions, the matrix has many ties, and complete linkage cut the tree arbitrarily. The tree is returned in the "tree" attribute. predict() is now documented on the cluster_meta() page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
See copilot comments. Seem reasonable to me. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


see NEWS