15 KiB
15 KiB
In [67]:
import numpy as np
n = 100
bootstraps = 1000
predictions = np.random.rand(bootstraps, n) * 10 + 10
targets = np.random.rand(bootstraps, n)
mse = ...
bias = ...
variance = ...In [ ]:
import numpy as np
import matplotlib.pyplot as plt
from sklearn.preprocessing import (
PolynomialFeatures,
) # use the fit_transform method of the created object!
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error
from sklearn.model_selection import train_test_split
from sklearn.utils import resampleIn [ ]:
n = 100
bootstraps = 1000
x = np.linspace(-3, 3, n)
y = np.exp(-(x**2)) + 1.5 * np.exp(-((x - 2) ** 2)) + np.random.normal(0, 0.1)
biases = []
variances = []
mses = []
# for p in range(1, 5):
# predictions = ...
# targets = ...
#
# X = ...
# X_train, X_test, y_train, y_test = ...
# for b in range(bootstraps):
# X_train_re, y_train_re = ...
#
# # fit your model on the sampled data
#
# # make predictions on the test data
# predictions[b, :] =
# targets[b, :] =
#
# biases.append(...)
# variances.append(...)
# mses.append(...)