-1

The mlegp package explains how to do Gaussian Process fitting but the R code mentioned in the mlegp package only demonstrates the use of the predict method to reconstruct the original functional output. Can someone help me understand how to predict using GPR on a test set?

Maurits Evers
  • 49,617
  • 4
  • 47
  • 68

1 Answers1

0

The function predict.gp (which gets called when you use predict on an mlpeg object) takes a newData argument, see ?predict.gp:

Usage:

     ## S3 method for class 'gp'
     predict(object, newData = object$X, se.fit = FALSE, ...)

Arguments:

  object: an object of class ‘gp’

 newData: an optional data frame or matrix with rows corresponding to
          inputs for which to predict.  If omitted, the design matrix
          ‘X’ of ‘object’ is used.
  ...

Consider the simple model

library(mlepg)
x = -5:5
y = sin(x) + rnorm(length(x),sd = 0.1)
fit = mlegp(x, y)

Then

predict(fit)

and

predict(fit, newData = fit$X)

gives the same result. You can then change newData according to your test data.

Maurits Evers
  • 49,617
  • 4
  • 47
  • 68
  • The predict function throws the error-no applicable method for 'predict' applied to an object of class "gp.list" – aanchal sharma Nov 12 '19 at 11:49
  • @aanchalsharma Please edit your main post to include representative & minimal sample data. It is very difficult (impossible) to help without knowing anything about (1) the data you're working with, and (2) the actual code you've been executing. To make your question reproducible, we should be able to copy&paste code from your post and reproduce the exact error you're seeing. Otherwise this is a guessing game. You should also take a look at how to provide a [minimal reproducible example/attempt](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Maurits Evers Nov 13 '19 at 09:37