TODO 12 Complete the TODO by getting our data, training the OrdinaryLeastSquares class and making predictions for our training and validation data. Call the data_prep() function to get our cleaned and transformed data. Store the output into data. Make sure to pass forestfire_df and the arguments corresponding to the following descriptions: Return all data as NumPy arrays. Drop the features 'day', 'ISI', 'DC', 'RH', and 'FFMC' from the data using the drop_features keyword argument. Create an instance of the OrdinaryLeastSquares and pass the ?=10 to the model using the lamb keyword argument. Store the output into ols. # TODO 12.1 data = X_trn, y_trn, X_vld, y_vld, _, _, feature_names = data # TODO 12.2 ols = ols.fit(X_trn, y_trn) y_hat_trn = ols.predict(X_trn) _, trn_sse, trn_mse, trn_rmse = analyze( y=y_trn, y_hat=y_hat_trn, title="Training Predictions Log Transform", dataset="Training", xlabel="Data Sample Index", ylabel="Predicted Log Area" ) todo_check([ (isinstance(X_trn, np.ndarray), 'X_trn is not of type np.ndarray'), (np.isclose(trn_rmse, 1.34096, rtol=.01), "trn_rmse value is possibly incorrect!"), (np.all(np.isclose(ols.w[:3].flatten(), [ 1.1418, -0.03522, -0.0148 ], rtol=0.01)), 'ols.w weights possibly contain incorrect values!') ])
TODO 12
Complete the TODO by getting our data, training the OrdinaryLeastSquares class and making predictions for our training and validation data.
- Call the data_prep() function to get our cleaned and transformed data. Store the output into data. Make sure to pass forestfire_df and the arguments corresponding to the following descriptions:
- Return all data as NumPy arrays.
- Drop the features 'day', 'ISI', 'DC', 'RH', and 'FFMC' from the data using the drop_features keyword argument.
- Create an instance of the OrdinaryLeastSquares and pass the ?=10 to the model using the lamb keyword argument. Store the output into ols.
# TODO 12.1
data =
X_trn, y_trn, X_vld, y_vld, _, _, feature_names = data
# TODO 12.2
ols =
ols.fit(X_trn, y_trn)
y_hat_trn = ols.predict(X_trn)
_, trn_sse, trn_mse, trn_rmse = analyze(
y=y_trn,
y_hat=y_hat_trn,
title="Training Predictions Log Transform",
dataset="Training",
xlabel="Data Sample Index",
ylabel="Predicted Log Area"
)
todo_check([
(isinstance(X_trn, np.ndarray), 'X_trn is not of type np.ndarray'),
(np.isclose(trn_rmse, 1.34096, rtol=.01), "trn_rmse value is possibly incorrect!"),
(np.all(np.isclose(ols.w[:3].flatten(), [ 1.1418, -0.03522, -0.0148 ], rtol=0.01)), 'ols.w weights possibly contain incorrect values!')
])
Trending now
This is a popular solution!
Step by step
Solved in 3 steps