kernelize: Apply a kernel

View source: R/kernels.R

kernelizeR Documentation

Apply a kernel

Description

Apply a kernel to your data.

Usage

kernelize(
  x,
  kernel,
  standardize = TRUE,
  rows_proportion = 0.8,
  arc_cosine_deep = 1,
  gamma = 1/NCOL(x),
  coef0 = 0,
  degree = 3
)

Arguments

x

(any) The data to apply the kernel to.

kernel

(character(1)) (case no sensitive) The kernel name to apply. The available options are "Linear", "Polynomial", "Exponential", "Sigmoid", "Gaussian" and "Arc_cosine". Also the sparse version of each kernel can be used as "Sparse_KERNEL", where KERNEL is one the kernels.

standardize

(logical(1)) Should the data be standardized before applying the kernel? TRUE by default.

rows_proportion

(numeric(1)) The proportion of rows to be sampled to compute the kernel. It has to be a value > 0 and <= 1. This parameter is only used with "Sparse_" kernels. 0.8 by default.

arc_cosine_deep

(numeric(1)) The deep to use in the "Arc_cosine" and "Sparse_Arc_cosine" kernels. It has to be a integer value >= 1. 1 by default.

gamma

(numeric) Parameter needed for all kernels except "Linear", "Arc_cosine" and their "Sparse_" versions. 1 / NCOL(x) by default.

coef0

(numeric) Parameter needed for "Polynomial", "Sigmoid" kernels and their "Sparse_" versions. 0 by default.

degree

(numeric) Parameter needed for "Polynomial" and "Sparse_Polynomial" kernels. 3 by default.

Details

You have to consider that before applying the kernel, the provided data is converted to matrix with to_matrix() function, see its documentation for more details of how categorical variables are handled.

kernel

The different kernel transformations are described in the following mathematical expressions:

  • Linear:

    K(X, Y) = X^T %*% Y

  • Polynomial:

    K(X, Y) = (gamma * X^T %*% Y + coef0)^degree

  • Radial:

    K(X, Y) = eXp(-gamma * |X - Y|^2)

  • Sigmoid:

    K(X, Y) = tanh(gamma * X^T %*% Y + coef0)

Value

A matrix with the data after apply the kernel.

Examples

## Not run: 
kernelize(iris, kernel = "linear")
kernelize(1:10, kernel = "polynomial")
kernelize(
  matrix(rnorm(12), 3, 4),
  kernel = "Sparse_polynomial",
  rows_proportion = 0.5
)

## End(Not run)


brandon-mosqueda/SKM documentation built on Feb. 8, 2025, 5:24 p.m.