View source: R/generate_simulation.R
| simu_n | R Documentation |
Generates synthetic classification data by drawing independent multivariate normal samples for each class. Useful when you want explicit control over each class's mean and covariance structure.
simu_n(
means,
covs,
ns,
class_names = NULL,
seed = NULL,
noise_ratio = 0,
test_ratio = 0
)
means |
A list of numeric vectors, one per class, specifying the class means. Each vector must have length equal to the number of features. |
covs |
A list of covariance matrices, one per class. |
ns |
A numeric vector of sample sizes, one per class. |
class_names |
Optional character vector of class labels (length equal to
|
seed |
Optional integer for reproducibility. The global random seed is restored after the call. |
noise_ratio |
Numeric in [0, 1). Proportion of |
test_ratio |
Numeric in [0, 1). If greater than 0, generates an additional independent test dataset. This is not a split of the training data. |
When test_ratio > 0, an additional independent test dataset is generated by
drawing fresh samples of size round(ns * test_ratio) for each class using the
same means and covs. This is not a split of the training data. The training
set has sum(ns) observations; the test set has sum(round(ns * test_ratio))
independently generated observations.
If test_ratio == 0 (default): a data frame with a Sim class column
and feature columns (X1, X2, ...). If test_ratio > 0: a list with
$train and $test data frames.
simulate_mixsim()
means <- list(c(0, 0), c(3, 3), c(0, 5))
covs <- list(diag(2), diag(2), diag(2))
ns <- c(60, 60, 60)
train_df <- simu_n(means, covs, ns, seed = 1)
head(train_df)
# With independent test data
sim <- simu_n(means, covs, ns, seed = 1, test_ratio = 0.3)
nrow(sim$train) # 180
nrow(sim$test) # 54 (independently generated, not split from train)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.