View source: R/parsnip_simca.R
| simca | R Documentation |
simca() defines a soft independent modeling of class analogy (SIMCA)
classification model for tidymodels: a principal component model of each
class, and the assignment of each observation to the closest class. Its
engine "rsimca" (the default) is the robust SIMCA of rsimca(), whose
class models resist outlying spectra of the training data.
simca(
mode = "classification",
num_comp = NULL,
gamma = NULL,
squared = NULL,
engine = "rsimca"
)
## S3 method for class 'simca'
update(
object,
parameters = NULL,
num_comp = NULL,
gamma = NULL,
squared = NULL,
fresh = FALSE,
...
)
mode |
The type of model: |
num_comp |
The number of components of the PCA model of each class,
or |
gamma |
The weight of the orthogonal distances in the classification
rule, between 0 and 1, or |
squared |
A logical: combine the squared scaled distances ( |
engine |
The computational engine: |
object |
A |
parameters |
A one-row tibble or named list of main parameters to
update, such as those returned by |
fresh |
If |
... |
Not used. |
simca() is a parsnip model specification: it is fitted with
parsnip::fit() or in a workflow, and can be tuned and resampled like any
parsnip model. It needs the parsnip package, and the "rsimca" engine is
available once parsnip and specProc are both loaded.
A model specification of classes simca and model_spec.
num_comp is the number of components of the robust PCA of each class
(ncomp of rsimca()), the same for all the classes. With NULL (the
default), each class gets the number chosen by robpca() from the
proportion of variance explained.
gamma is the weight of the orthogonal distances, against the score
distances, in the classification rule (gamma of rsimca()). With
NULL (the default), it is 0.5.
squared chooses the classification rule (squared of rsimca()):
the squared scaled distances (TRUE, rule R2 of the paper) or the
scaled distances (FALSE, rule R1). With NULL (the default), it is
TRUE.
All three can be tuned with tune::tune(), using dials::num_comp(),
simca_gamma() and simca_squared().
The other arguments of rsimca() are set with parsnip::set_engine():
ncomp_max, alpha, var_explained, prior, ndir and nsamp.
predict() gives the classes
(type = "class"), or with type = "raw" the combined distances to the
classes and whether each observation is outlying for all of them
(predict.specproc_rsimca()). SIMCA does not give class probabilities:
when tuning, use metrics of the predicted classes, such as
yardstick::metric_set(yardstick::accuracy, yardstick::kap).
The fitted rsimca() model is returned by
parsnip::extract_fit_engine(). rsimca() uses random directions and
subsets, so use set.seed() before fitting for reproducible results.
Christian L. Goueguel
rsimca(), predict.specproc_rsimca(), simca_gamma(),
simca_squared()
library(parsnip)
spec <- simca(num_comp = 2, gamma = 0.5) |>
set_engine("rsimca", alpha = 0.75)
spec
# iris: train on 100 flowers, predict the 50 others
set.seed(1)
train <- sample(nrow(iris), 100)
fit <- fit(spec, Species ~ ., data = iris[train, ])
table(predict(fit, iris[-train, ])$.pred_class, iris$Species[-train])
head(predict(fit, iris[-train, ], type = "raw"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.