0

I am trying to fit multiple observations to a single Gaussian Process.

I try to fit the data of two observations (Y) like this:

import numpy as np
from sklearn.gaussian_process import GaussianProcessRegressor
from sklearn.gaussian_process.kernels import RBF, ConstantKernel as C


# Example data

# Input data X 
X = np.array([[1.0], [2.0], [3.0], [4.0], [5.0]])

# Output data Y 
Y = np.array([[1.5, 2.5], [2.5, 3.5], [3.5, 4.5], [4.5, 5.5], [5.5, 6.5]])
kernel = C(1.0, (1e-4, 1e1)) * RBF(1.0, (1e-4, 1e1))
gp = GaussianProcessRegressor(kernel=kernel, n_restarts_optimizer=10)

# Fitting the model
gp.fit(X, Y)

mean_prediction, cov_prediction = gp.predict(X, return_cov=True)

I am getting two array of mean_prediction and two cov_prediction matrices. But I want a single mean and covariance matrix of same dimension as the observations corresponding to single fitted GP. How can I implement that?

1 Answer 1

0

If you fit them the following way you should get only one posterior mean, I think in theory you should also get two means but they are indentical so the model will give you just once:

# Input data X 
X = np.array([[1.0], [2.0], [3.0], [4.0], [5.0],[1.0], [2.0], [3.0], [4.0], [5.0]])

# Output data Y 
Y = np.array([[1.5], [2.5], [2.5], [3.5], [3.5], [4.5], [4.5], [5.5], [5.5], [6.5]])
kernel = C(1.0, (1e-4, 1e1)) * RBF(1.0, (1e-4, 1e1))
gp = GaussianProcessRegressor(kernel=kernel, n_restarts_optimizer=10)

# Fitting the model
gp.fit(X, Y)

mean_prediction, cov_prediction = gp.predict([[1.0], [2.0], [3.0], [4.0], [5.0]], return_cov=True)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.