I am rewriting a code in MATLAB in Python. The code performs Gaussian Process regression using fitrgp. In Python, I am using scikit-learn and its GaussianProcessRegressor. In both cases, the GP learns the mapping betwen input and output. The core of my MATLAB and Python codes are as follows:
-MATLAB
prediction_train=[];
%% z-score of input
[normalized_input_train,mu_train,std_train]=zscore(input_data);
parfor j=1:1:size(output_data,2)
j %prints time component
z1=squeeze(output_data(:,j));
beta1=fitrgp(normalized_input_train,z1,'BasisFunction','linear','KernelFunction','ardmatern32');
beta1=compact(beta1);
prediction_tmp=predict(beta1,normalized_input_train);
prediction_train=[prediction_train, prediction_tmp];
end
which trains the GP on some training input_data, and learns the prediction for the same input_data, to be later compared with output_data. This script implements a linear basis with ard Matern 3/2 kernel function.
-Python
# Instantiate a Gaussian Process model
kernel = 1.0 * Matern(nu=1.5)
gp = GaussianProcessRegressor(kernel=kernel)
# z-score of input
scale = StandardScaler()
normalized_input_train = scale.fit_transform(input_data)
prediction_train = np.zeros((np.shape(output_data)))
for i in range(np.shape(output_data)[1]):
print("time component", i)
gp.fit(normalized_input_train, output_data[:,i])
prediction_tmp, sigma = gp.predict(normalized_input_train, return_std=True)
prediction_train[:,i] = prediction_tmp
This should do exactly the same as my MATLAB code. However, I am not sure how to implement the linear basis option that is implemented in the MATLAB script.