Cross-validation on gaussian process

I need to complete k-fold cross-validation on my Gaussian process. My Gaussian process code is below. I have read about cross_val_score and cross_validate functions, however I cannot seem to get them to work as the estimator input is not from .fit. I don’t know if I’m using them wrong or if they are incompatible with my model. Any input on how to adapt my model or another way of doing k-fold cross validation would be helpful! I am aware pymc3 as a leave one out function but ideally I don’t want to use this as my report argues to use k-fold.

data = pandas.read_csv('exported_stress')
data = data[data['load']==0]
x = data['x'].to_numpy()
x = x[:,None]
y = data['s11'].to_numpy()
actual_data = pandas.read_csv('exported_stress_fsw_311.csv')
actual_data = actual_data[actual_data['load']==0]
actual_data = actual_data[actual_data['y']==0]
X_acc = actual_data['x'].to_numpy()
X_acc = X_acc[:,None]
with pm.Model() as model:
    l = pm.InverseGamma("l", alpha=2, beta=4)
    n = pm.HalfNormal("n",2)
    cov = n ** 2 * pm.gp.cov.Matern52(1,l)
    gp = pm.gp.Marginal(cov_func=cov)
    s = pm.HalfNormal("s",1)
    y_ = gp.marginal_likelihood("y",X=x,y=y, noise=s)
    trace = pm.sample()
    mp = pm.find_MAP()
    f_pred = gp.conditional("f_pred",X_acc)
    pred_samples = pm.sample_posterior_predictive([mp], var_names= ['f_pred'],samples=2000)
1 Like

See if the answer in this thread helps.