Quantcast
Channel: Active questions tagged kernel - Stack Overflow
Viewing all articles
Browse latest Browse all 6501

How to save and load Gaussian process for production

$
0
0

How can I save and load Gaussian process models created using the GPy package?

Here's how I define the model and optimize for its parameters:

# define kernel
ker =   GPy.kern.Matern52(rescaled_x_train.shape[1],ARD=True) + GPy.kern.White(rescaled_x_train.shape[1]) + \
        GPy.kern.Linear(rescaled_x_train.shape[1]) 

y_gp = y_train.values.reshape(y_train.shape[0],1)        
x_gp = rescaled_x_train
# create a GP model
m = GPy.models.GPRegression(x_gp, y_gp , ker) 

m.optimize(messages=True,max_f_eval = 3000)

But I don't know how I can save m in such a way that I can load it to be used for prediction.

I tried the following:

# Save the model parameters
np.save('gp_params.npy',m.param_array)
np.save('gp_y.npy',y_gp)
np.save('gp_X.npy',x_gp)

# Load model
y_load = np.load('gp_y.npy')
X_load = np.load('gp_X.npy')
gp_load = GPy.models.GPRegression(X_load, y_load, kernel= ker,
                                   initialize=True)  

However, this loads a model that is different than the one I created originally. Can any one help please?


Viewing all articles
Browse latest Browse all 6501

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>