kernlab (version 0.9-27)

gausspr: Gaussian processes for regression and classification


gausspr is an implementation of Gaussian processes for classification and regression.


# S4 method for formula
gausspr(x, data=NULL, ..., subset, na.action = na.omit, scaled = TRUE)

# S4 method for vector gausspr(x,...)

# S4 method for matrix gausspr(x, y, scaled = TRUE, type= NULL, kernel="rbfdot", kpar="automatic", var=1, variance.model = FALSE, tol=0.0005, cross=0, fit=TRUE, ... , subset, na.action = na.omit)



a symbolic description of the model to be fit or a matrix or vector when a formula interface is not used. When not using a formula x is a matrix or vector containing the variables in the model


an optional data frame containing the variables in the model. By default the variables are taken from the environment which `gausspr' is called from.


a response vector with one label for each row/component of x. Can be either a factor (for classification tasks) or a numeric vector (for regression).


Type of problem. Either "classification" or "regression". Depending on whether y is a factor or not, the default setting for type is classification or regression, respectively, but can be overwritten by setting an explicit value.


A logical vector indicating the variables to be scaled. If scaled is of length 1, the value is recycled as many times as needed and all non-binary variables are scaled. Per default, data are scaled internally (both x and y variables) to zero mean and unit variance. The center and scale values are returned and used for later predictions.


the kernel function used in training and predicting. This parameter can be set to any function, of class kernel, which computes a dot product between two vector arguments. kernlab provides the most popular kernel functions which can be used by setting the kernel parameter to the following strings:

  • rbfdot Radial Basis kernel function "Gaussian"

  • polydot Polynomial kernel function

  • vanilladot Linear kernel function

  • tanhdot Hyperbolic tangent kernel function

  • laplacedot Laplacian kernel function

  • besseldot Bessel kernel function

  • anovadot ANOVA RBF kernel function

  • splinedot Spline kernel

The kernel parameter can also be set to a user defined function of class kernel by passing the function name as an argument.


the list of hyper-parameters (kernel parameters). This is a list which contains the parameters to be used with the kernel function. Valid parameters for existing kernels are :

  • sigma inverse kernel width for the Radial Basis kernel function "rbfdot" and the Laplacian kernel "laplacedot".

  • degree, scale, offset for the Polynomial kernel "polydot"

  • scale, offset for the Hyperbolic tangent kernel function "tanhdot"

  • sigma, order, degree for the Bessel kernel "besseldot".

  • sigma, degree for the ANOVA kernel "anovadot".

Hyper-parameters for user defined kernels can be passed through the kpar parameter as well.


the initial noise variance, (only for regression) (default : 0.001)


build model for variance or standard deviation estimation (only for regression) (default : FALSE)


tolerance of termination criterion (default: 0.001)


indicates whether the fitted values should be computed and included in the model or not (default: 'TRUE')


if a integer value k>0 is specified, a k-fold cross validation on the training data is performed to assess the quality of the model: the Mean Squared Error for regression


An index vector specifying the cases to be used in the training sample. (NOTE: If given, this argument must be named.)


A function to specify the action to be taken if NAs are found. The default action is na.omit, which leads to rejection of cases with missing values on any required variable. An alternative is, which causes an error if NA cases are found. (NOTE: If given, this argument must be named.)

additional parameters


An S4 object of class "gausspr" containing the fitted model along with information. Accessor functions can be used to access the slots of the object which include :


The resulting model parameters


Training error (if fit == TRUE)


A Gaussian process is specified by a mean and a covariance function. The mean is a function of \(x\) (which is often the zero function), and the covariance is a function \(C(x,x')\) which expresses the expected covariance between the value of the function \(y\) at the points \(x\) and \(x'\). The actual function \(y(x)\) in any data modeling problem is assumed to be a single sample from this Gaussian distribution. Laplace approximation is used for the parameter estimation in gaussian processes for classification.

The predict function can return class probabilities for classification problems by setting the type parameter to "probabilities". For the regression setting the type parameter to "variance" or "sdeviation" returns the estimated variance or standard deviation at each predicted point.


C. K. I. Williams and D. Barber Bayesian classification with Gaussian processes. IEEE Transactions on Pattern Analysis and Machine Intelligence, 20(12):1342-1351, 1998

See Also

predict.gausspr, rvm, ksvm, gausspr-class, lssvm


Run this code
# train model
test <- gausspr(Species~.,data=iris,var=2)

# predict on the training set
# class probabilities 
predict(test, iris[,-5], type="probabilities")

# create regression data
x <- seq(-20,20,0.1)
y <- sin(x)/x + rnorm(401,sd=0.03)

# regression with gaussian processes
foo <- gausspr(x, y)

# predict and plot
ytest <- predict(foo, x)
plot(x, y, type ="l")
lines(x, ytest, col="red")

#predict and variance
x = c(-4, -3, -2, -1,  0, 0.5, 1, 2)
y = c(-2,  0,  -0.5,1,  2, 1, 0, -1)
foo2 <- gausspr(x, y, variance.model = TRUE)
xtest <- seq(-4,2,0.2)
lines(xtest, predict(foo2, xtest))
      predict(foo2, xtest)+2*predict(foo2,xtest, type="sdeviation"),
      predict(foo2, xtest)-2*predict(foo2,xtest, type="sdeviation"),

# }

Run the code above in your browser using DataCamp Workspace