kfda: Kernel Fisher Discriminant Analysis (KFDA)

Description Usage Arguments Details Value Note Author(s) References See Also Examples

View source: R/kfda.R

Description

Train the trainData using KFDA. Basically, we run KFDA using Gaussian kernel. Returns trained KFDA object.

Usage

1
kfda(trainData = data, kernel.name = "rbfdot", kpar.sigma = 0.001, threshold = 1e-05)

Arguments

trainData

an optional data frame or matrix containing the variables in the model. In particular, the last column of the data frame should contain the target value.

kernel.name

the kernel function used in training and predicting. This parameter is fixed in the rbfdot(Gaussian kernel).

kpar.sigma

hyper-parameter of selected kernel. sigma inverse kernel width for the Gaussian kernel function "rbfdot".

threshold

the value of the eigenvalue under which principal components are ignored (only valid when features = 0). (default : 1e-05).

Details

Train the trainData using KFDA. Basically, we run KFDA using Gaussian kernel. Returns trained KFDA object. Since this function performs KFDA with the appropriate combination of kpca and lda, the following values can show the result of each function.

Value

An object of class kfda.

kpca.train

An object of class "kpca". It has results of kpca function. (seekpca (in package kernlab))

lda.rotation.train

The result of applying LDA, After KPCA is performed on trainData.

LDs

A dataframe of linear discriminants of LDA.

label

A vector of class label of trainData.

Note

This package is an early version and will be updated in the future.

Author(s)

Donghwan Kim
ainsuotain@hanmail.net donhkim9714@korea.ac.kr dhkim2@bistel.com

References

Yang, J., Jin, Z., Yang, J. Y., Zhang, D., and Frangi, A. F. (2004) <DOI:10.1016/j.patcog.2003.10.015>. Essence of kernel Fisher discriminant: KPCA plus LDA. Pattern Recognition, 37(10): 2097-2100.

See Also

kpca (in package kernlab) lda (in package MASS) kfda.predict

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# data input
data(iris)

# data separation
idx <- sample(1:dim(iris)[1], round(dim(iris)[1]*0.7))
trainData <- iris[idx, ]

# training KFDA model
kfda.model <- kfda(trainData = trainData, kernel.name = "rbfdot")

# structure of kfda.model
str(kfda.model)

Example output

Loading required package: kernlab
Loading required package: MASS
List of 4
 $ kpca.train        :Formal class 'kpca' [package "kernlab"] with 9 slots
  .. ..@ rotated : num [1:105, 1:5] 1.183 -1.205 -1.083 1.237 0.334 ...
  .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. ..$ : chr [1:105] "15" "126" "105" "4" ...
  .. .. .. ..$ : NULL
  .. ..@ pcv     : num [1:105, 1:5] 1.316 -1.341 -1.205 1.377 0.371 ...
  .. ..@ eig     : Named num [1:5] 8.56e-03 4.81e-04 1.28e-04 4.88e-05 2.37e-05
  .. .. ..- attr(*, "names")= chr [1:5] "Comp.1" "Comp.2" "Comp.3" "Comp.4" ...
  .. ..@ kernelf :Formal class 'rbfkernel' [package "kernlab"] with 2 slots
  .. .. .. ..@ .Data:function (x, y = NULL)  
  .. .. .. ..@ kpar :List of 1
  .. .. .. .. ..$ sigma: num 0.001
  .. ..@ kpar    : list()
  .. ..@ xmatrix : num [1:105, 1:4] 5.8 7.2 6.5 4.6 4.9 5.5 6.4 6.5 5.2 5.5 ...
  .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. ..$ : chr [1:105] "15" "126" "105" "4" ...
  .. .. .. ..$ : chr [1:4] "Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width"
  .. .. ..- attr(*, "assign")= int [1:4] 1 2 3 4
  .. ..@ kcall   : language kpca(x = x, data = ..1, kernel = ..2, kpar = ..3, th = ..4)
  .. ..@ terms   :Classes 'terms', 'formula'  language ~Sepal.Length + Sepal.Width + Petal.Length + Petal.Width
  .. .. .. ..- attr(*, "variables")= language list(Sepal.Length, Sepal.Width, Petal.Length, Petal.Width)
  .. .. .. ..- attr(*, "factors")= int [1:4, 1:4] 1 0 0 0 0 1 0 0 0 0 ...
  .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. ..$ : chr [1:4] "Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width"
  .. .. .. .. .. ..$ : chr [1:4] "Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width"
  .. .. .. ..- attr(*, "term.labels")= chr [1:4] "Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width"
  .. .. .. ..- attr(*, "order")= int [1:4] 1 1 1 1
  .. .. .. ..- attr(*, "intercept")= num 0
  .. .. .. ..- attr(*, "response")= int 0
  .. .. .. ..- attr(*, ".Environment")=<environment: 0x5589d7180f00> 
  .. .. .. ..- attr(*, "predvars")= language list(Sepal.Length, Sepal.Width, Petal.Length, Petal.Width)
  .. .. .. ..- attr(*, "dataClasses")= Named chr [1:4] "numeric" "numeric" "numeric" "numeric"
  .. .. .. .. ..- attr(*, "names")= chr [1:4] "Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width"
  .. ..@ n.action: NULL
 $ lda.rotation.train:List of 10
  ..$ prior  : Named num [1:3] 0.343 0.324 0.333
  .. ..- attr(*, "names")= chr [1:3] "setosa" "versicolor" "virginica"
  ..$ counts : Named int [1:3] 36 34 35
  .. ..- attr(*, "names")= chr [1:3] "setosa" "versicolor" "virginica"
  ..$ means  : num [1:3, 1:5] 1.2012 -0.2625 -0.9804 0.0847 -0.1217 ...
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:3] "setosa" "versicolor" "virginica"
  .. .. ..$ : chr [1:5] "V1" "V2" "V3" "V4" ...
  ..$ scaling: num [1:5, 1:2] -7.418 -7.565 -0.678 3.26 -23.879 ...
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:5] "V1" "V2" "V3" "V4" ...
  .. .. ..$ : chr [1:2] "LD1" "LD2"
  ..$ lev    : chr [1:3] "setosa" "versicolor" "virginica"
  ..$ svd    : num [1:2] 52.68 8.35
  ..$ N      : int 105
  ..$ call   : language lda(formula = kpca.rotation.train$Y ~ ., data = kpca.rotation.train)
  ..$ terms  :Classes 'terms', 'formula'  language kpca.rotation.train$Y ~ V1 + V2 + V3 + V4 + V5
  .. .. ..- attr(*, "variables")= language list(kpca.rotation.train$Y, V1, V2, V3, V4, V5)
  .. .. ..- attr(*, "factors")= int [1:6, 1:5] 0 1 0 0 0 0 0 0 1 0 ...
  .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. ..$ : chr [1:6] "kpca.rotation.train$Y" "V1" "V2" "V3" ...
  .. .. .. .. ..$ : chr [1:5] "V1" "V2" "V3" "V4" ...
  .. .. ..- attr(*, "term.labels")= chr [1:5] "V1" "V2" "V3" "V4" ...
  .. .. ..- attr(*, "order")= int [1:5] 1 1 1 1 1
  .. .. ..- attr(*, "intercept")= int 1
  .. .. ..- attr(*, "response")= int 1
  .. .. ..- attr(*, ".Environment")=<environment: 0x5589d7180f00> 
  .. .. ..- attr(*, "predvars")= language list(kpca.rotation.train$Y, V1, V2, V3, V4, V5)
  .. .. ..- attr(*, "dataClasses")= Named chr [1:6] "factor" "numeric" "numeric" "numeric" ...
  .. .. .. ..- attr(*, "names")= chr [1:6] "kpca.rotation.train$Y" "V1" "V2" "V3" ...
  ..$ xlevels: Named list()
  ..- attr(*, "class")= chr "lda"
 $ LDs               : num [1:105, 1:2] -11.48 6.01 7.36 -9.64 1 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:105] "15" "126" "105" "4" ...
  .. ..$ : chr [1:2] "LD1" "LD2"
 $ label             : Factor w/ 3 levels "setosa","versicolor",..: 1 3 3 1 2 2 3 2 1 2 ...
 - attr(*, "class")= chr "Kernel Fisher Discriminant Analysis"

kfda documentation built on May 2, 2019, 2:47 p.m.

Related to kfda in kfda...