mvpa_model | R Documentation |
Create an MVPA model based on a caret-based classification or regression model.
mvpa_model(
model,
dataset,
design,
model_type = c("classification", "regression"),
crossval = NULL,
feature_selector = NULL,
tune_grid = NULL,
tune_reps = 15,
performance = NULL,
class_metrics = TRUE
)
model |
A caret-based classification or regression model. |
dataset |
An 'mvpa_dataset' instance. |
design |
An 'mvpa_design' instance. |
model_type |
A character string indicating the problem type: "classification" or "regression". |
crossval |
An optional 'cross_validation' instance. |
feature_selector |
An optional 'feature_selector' instance. |
tune_grid |
An optional parameter tuning grid as a 'data.frame'. |
tune_reps |
The number of replications used during parameter tuning. Only relevant if 'tune_grid' is supplied. |
performance |
An optional custom function for computing performance metrics. |
class_metrics |
A logical flag indicating whether to compute performance metrics for each class. |
If 'performance' is supplied, it must be a function that takes one argument and returns a named list of scalar values. The argument the function takes is a class deriving from 'classification_result' appropriate for the problem at hand. See example below.
mod <- load_model("sda")
traindat <- neuroim2::NeuroVec(array(rnorm(6*6*6*100), c(6,6,6,100)), neuroim2::NeuroSpace(c(6,6,6,100)))
mask <- neuroim2::LogicalNeuroVol(array(rnorm(6*6*6)>-.2, c(6,6,6)), neuroim2::NeuroSpace(c(6,6,6)))
mvdset <- mvpa_dataset(traindat,mask=mask)
design <- data.frame(fac=rep(letters[1:4], 25), block=rep(1:10, each=10))
cval <- blocked_cross_validation(design$block)
mvdes <- mvpa_design(design, ~ fac, block_var=~block)
custom_perf <- function(result) {
c(accuracy=sum(result$observed == result$predicted)/length(result$observed))
}
mvpmod <- mvpa_model(mod, dataset=mvdset, design=mvdes, crossval=cval, performance=custom_perf)
ret <- run_searchlight(mvpmod)
stopifnot("accuracy" %in% names(ret))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.