# Gaussian process mean function in scikit-learn

Scikit learn allows us to fit Gaussian processes $$GP(0,K(.,.))$$ such that $$K:T\times T \to \mathbb{R}$$ is a covariance function (kernel), however it doesn't let us specify a mean function $$m: T\times \mathbb{R}$$. I'm trying to work solely with scikit-learn, so working with only the tools it provides. Is it a reasonable approach to fit a mean function using another method such as the multiple linear regression and then fit a Gaussian process to the residuals?

Should I do something like Iterated Weighted Least Squares (IWLS) where you alternate between fitting the fixed effects under the current estimate of the covariance matrix and then reestimate the covariance function parameters using the current residuals?

• I'm not very familiar with scikit-learn, but if you can specify the covariance function as the sum of a linear covariance function and any other (e.g. matern, sq exp), this is equivalent to adding in a mean function Apr 6, 2023 at 11:04
• @jcken sklearn does have a dot-product linear kernel. That sounds exactly like what I want. Could you elaborate a little bit on the equivalence of the linear covariance and the mean function? I know that the sum of p.d. kernels are also p.d., but I don't see how the equivalence works out. Apr 6, 2023 at 19:33
• Thanks, I had the same question. Chris Fonnesbeck wrote an article about Scikit-Learn's GPR module in 2017, in which he states "The GaussianProcessRegressor does not allow for the specification of the mean function, always assuming it to be the zero function, highlighting the diminished role of the mean function in calculating the posterior." So unless something has changed since then it looks like the answer is 'no'.
– Bill
Sep 2, 2023 at 18:42
• @Bill I guessed so. Thanks for the additional info. Looking at the theory, the universal kriging predictor (BLUP under a GP) is just the ordinary kriging predictor over the residuals of fitting said linear model. So fitting, for example, a parametric or non-parametric (splines, etc) linear model then using the residuals to fit and predict seems fine. Sep 4, 2023 at 16:02