View source: R/cluster_centroids_impl.R
| cluster_centroids | R Documentation |
Under-samples the majority classes by replacing them with cluster representatives found with k-means.
cluster_centroids(df, var, under_ratio = 1, voting = "soft")
df |
data.frame or tibble. Must have 1 factor variable and remaining numeric variables. |
var |
Character, name of variable containing factor variable. |
under_ratio |
A numeric value for the ratio of the majority-to-minority frequencies. The default value (1) means that all other levels are sampled down to have the same frequency as the least occurring level. A value of 2 would mean that the majority levels will have (at most) (approximately) twice as many rows than the minority level. A named numeric vector can be used instead to give different levels
different targets, for example |
voting |
A character string. Either |
Each class larger than the target count is summarized by running k-means on the observations of that class, using as many clusters as the target count. The class is then replaced by one representative per cluster:
voting = "soft"the cluster centroids themselves are used, so the returned observations are synthetic points that need not appear in the input.
voting = "hard"the observation closest to each centroid is used, so all returned observations are real rows. The representative is always picked from the class being under-sampled.
This makes it the one prototype generation under-sampler in this package. The other under-sampling methods perform prototype selection, keeping a subset of the original rows.
Because two clusters can share the same closest observation, voting = "hard" can return slightly fewer observations than the target count.
All columns used in this function must be numeric with no missing data.
A data.frame or tibble, depending on type of df.
step_cluster_centroids() for step function of this method
Other Direct Implementations:
adasyn(),
bsmote(),
cnn(),
enn(),
instance_hardness(),
kmeans_smote(),
ncl(),
nearmiss(),
oss(),
rose(),
smogn(),
smote(),
smoten(),
smotenc(),
svmsmote(),
tomek()
circle_numeric <- circle_example[, c("x", "y", "class")]
res <- cluster_centroids(circle_numeric, var = "class")
res <- cluster_centroids(circle_numeric, var = "class", voting = "hard")
res <- cluster_centroids(circle_numeric, var = "class", under_ratio = 1.5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.