View source: R/classif.kfold.R
classif.kfold | R Documentation |
Computes Functional Classification using k-fold cross-validation
classif.kfold( formula, data, classif = "classif.glm", par.classif, kfold = 10, param.kfold = NULL, measure = "accuracy", cost, models = FALSE, verbose = FALSE )
formula |
an object of class |
data |
|
classif |
character, name of classification method to be used in fitting the model, see |
par.classif |
|
kfold |
|
param.kfold |
|
measure |
|
cost |
|
models |
|
verbose |
|
Parameters for k-fold cross validation:
Number of basis elements:
Data-driven basis such as Functional Principal Componetns (PC). No implemented for PLS basis yet.
Fixed basis (bspline, fourier, etc.).
Option used in some classifiers such as classif.glm
, classif.gsam
, classif.svm
, etc.
Bandwidth parameter. Option used in non-parametric classificiation models such as classif.np
and classif.gkam
.
Best fitted model computed by the k-fold CV using the method indicated
in the classif
argument and also returns:
param.min
, value of parameter (or parameters) selected by k-fold CV.
params.error
, k-fold CV error for each parameter combination.
pred.kfold
, predicted response computed by k-fold CV.
model
, if TRUE
, list of models for each parameter combination.
Manuel Febrero-Bande, Manuel Oviedo de la Fuente manuel.oviedo@udc.es
## Not run: data(tecator) cutpoint <- 18 tecator$y$class <- factor(ifelse(tecator$y$Fat<cutpoint,0,1)) table(tecator$y$class ) x <- tecator[[1]] x2 <- fdata.deriv(tecator[[1]],2) data <- list("df"=tecator$y,x=x,x2=x2) formula <- formula(class~x+x2) # ex: default excution of classifier (no k-fold CV) classif="classif.glm" out.default <- classif.kfold(formula, data, classif = classif) out.default out.default$param.min out.default$params.error summary(out.default) # ex: Number of PC basis elements selected by 10-fold CV # Logistic classifier kfold = 10 param.kfold <- list("x"=list("pc"=c(1:8)),"x2"=list("pc"=c(1:8))) out.kfold1 <- classif.kfold(formula, data, classif = classif, kfold = kfold,param.kfold = param.kfold) out.kfold1$param.min min(out.kfold1$params.error) summary(out.kfold1) # ex: Number of PC basis elements selected by 10-fold CV # Logistic classifier with inverse weighting out.kfold2 <- classif.kfold(formula, data, classif = classif, par.classif=list("weights"="inverse"), kfold = kfold,param.kfold = param.kfold) out.kfold2$param.min min(out.kfold2$params.error) summary(out.kfold2) # ex: Number of fourier basis elements selected by 10-fold CV # Logistic classifier ibase = seq(5,15,by=2) param.kfold <- list("x"=list("fourier"=ibase), "x2"=list("fourier"=ibase)) out.kfold3 <- classif.kfold(formula, data, classif = classif, kfold = kfold,param.kfold = param.kfold) out.kfold3$param.min min(out.kfold3$params.error) summary(out.kfold3) # ex: Number of k-nearest neighbors selected by 10-fold CV # non-parametric classifier (only for a functional covariate) output <- classif.kfold( class ~ x, data, classif = "classif.knn", param.kfold= list("x"=list("knn"=c(3,5,9,13)))) output$param.min output$params.error output <- classif.kfold( class ~ x2, data, classif = "classif.knn", param.kfold= list("x2"=list("knn"=c(3,5,9,13)))) output$param.min output$params.error ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.