It is well known that an estimator's MSE can be decomposed into the sum of the variance and the squared bias. I'd like to actually perform this decomposition. Here is some code to set up and train a small model.
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error
from sklearn.kernel_ridge import KernelRidge
x = np.linspace(0,10,1001).reshape(-1,1)
X = np.random.uniform(low = 0, high =10, size = 2000).reshape(-1,1)
y = 3*np.sin(X) + 2.5*np.random.normal(size = X.shape)
X_train, X_test, y_train, y_test = train_test_split(X,y,train_size = 0.6)
reg = KernelRidge(kernel='rbf', gamma = 1).fit(X,y)
mse = mean_squared_error(y_test, reg.predict(X_test))
print(mse)
How can I go about computing the squared bias and the variance for this estimator?