Calculating variability in model coefficients
In this lesson, you'll re-run the cross-validation routine used before, but this time paying attention to the model's stability over time. You'll investigate the coefficients of the model, as well as the uncertainty in its predictions.
Begin by assessing the stability (or uncertainty) of a model's coefficients across multiple CV splits. Remember, the coefficients are a reflection of the pattern that your model has found in the data.
An instance of the Linear regression object (model
) is available in your workpsace. Also, the arrays X
and y
(the data) are available too.
This exercise is part of the course
Machine Learning for Time Series Data in Python
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Iterate through CV splits
n_splits = 100
cv = TimeSeriesSplit(n_splits=____)
# Create empty array to collect coefficients
coefficients = np.____([n_splits, X.shape[1]])
for ii, (tr, tt) in enumerate(cv.split(X, y)):
# Fit the model on training data and collect the coefficients
model.fit(X[tr], y[tr])
coefficients[ii] = ____