Computes Functional Classification using k-fold cross-validation
Usage
classif.kfold(
formula,
data,
classif = "classif.glm",
par.classif,
kfold = 10,
param.kfold = NULL,
measure = "accuracy",
cost,
models = FALSE,
verbose = FALSE
)
Arguments
- formula
an object of class
formula
(or one that can be coerced to that class): a symbolic description of the model to be fitted. The procedure only considers functional covariates (not implemented for non-functional covariates).- data
list
, it contains the variables in the model.- classif
character, name of classification method to be used in fitting the model, see
Details
section.- par.classif
list
of arguments used in the classification method.- kfold
integer
, number of k-fold.- param.kfold
list
, arguments related to number of k-folds for each covariate, seeDetails
section.- measure
character
, type of measure of accuracy used, seecat2meas
function.- cost
numeric
, seecat2meas
function.- models
logical
. IfTRUE
, return a list of the fitted models used, (k-fold -1) X (number of parameters)- verbose
logical
. IfTRUE
, print some internal results.
Value
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
, ifTRUE
, list of models for each parameter combination.
Details
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
andclassif.gkam
.
Author
Manuel Febrero-Bande, Manuel Oviedo de la Fuente manuel.oviedo@udc.es
Examples
if (FALSE) { # \dontrun{
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
} # }