View source: R/instance_hardness_impl.R
| instance_hardness | R Documentation |
Under-samples the majority classes by removing the points that are hardest to classify.
instance_hardness(df, var, k = 5, under_ratio = 1, distance = "euclidean")
df |
data.frame or tibble. Must have 1 factor variable and remaining numeric variables. |
var |
Character, name of variable containing factor variable. |
k |
An integer. Number of nearest neighbors used to estimate the instance hardness of each observation. |
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 |
distance |
A character string specifying the distance metric used for
nearest neighbor calculations, defaulting to
The probability divergences are meaningful for compositional predictors such as proportions or counts normalized per observation, and are generally not appropriate for standardized predictors. |
The instance hardness of each observation is estimated using the
k-Disagreeing Neighbors measure: the proportion of the nearest neighbors
that belong to a different class. Observations that are surrounded by points
of a different class are considered hard to classify. For each majority
class, the hardest observations are removed until the desired under_ratio
is reached.
All columns used in this function must be numeric with no missing data.
A data.frame or tibble, depending on type of df.
Smith, M. R., Martinez, T., & Giraud-Carrier, C. (2014). An instance level analysis of data complexity. Machine learning, 95(2), 225-256.
step_instance_hardness() for step function of this method
Other Direct Implementations:
adasyn(),
bsmote(),
cluster_centroids(),
cnn(),
enn(),
kmeans_smote(),
ncl(),
nearmiss(),
oss(),
rose(),
smogn(),
smote(),
smoten(),
smotenc(),
svmsmote(),
tomek()
circle_numeric <- circle_example[, c("x", "y", "class")]
res <- instance_hardness(circle_numeric, var = "class")
res <- instance_hardness(circle_numeric, var = "class", k = 10)
res <- instance_hardness(circle_numeric, var = "class", under_ratio = 1.5)
res <- instance_hardness(circle_numeric, var = "class", distance = "manhattan")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.