Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

classif.kfold

Functional Classification usign k-fold CV


Description

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, see Details section.

measure

character, type of measure of accuracy used, see cat2meas function.

cost

numeric, see cat2meas function.

models

logical. If TRUE, return a list of the fitted models used, (k-fold -1) X (number of parameters)

verbose

logical. If TRUE, print some internal results.

Details

Parameters for k-fold cross validation:

  1. 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.

  2. Bandwidth parameter. Option used in non-parametric classificiation models such as classif.np and classif.gkam.

Value

Best fitted model computed by the k-fold CV using the method indicated in the classif argument and also returns:

  1. param.min, value of parameter (or parameters) selected by k-fold CV.

  2. params.error, k-fold CV error for each parameter combination.

  3. pred.kfold, predicted response computed by k-fold CV.

  4. model, if TRUE, list of models for each parameter combination.

Author(s)

Manuel Febrero-Bande, Manuel Oviedo de la Fuente manuel.oviedo@usc.es

Examples

## 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)

fda.usc

Functional Data Analysis and Utilities for Statistical Computing

v2.0.2
GPL-2
Authors
Manuel Febrero Bande [aut], Manuel Oviedo de la Fuente [aut, cre], Pedro Galeano [ctb], Alicia Nieto [ctb], Eduardo Garcia-Portugues [ctb]
Initial release
2020-02-17

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.