2.1. Exercises

Linear Model Coefficient Questions

Use the following equation to answer the questions below:

predicted(backpack_weight) = 3.02 x #laptops + 0.3 x #pencils + 0.5


True or False: Coefficients

Interpreting Ridge

Instructions:
Running a coding exercise for the first time could take a bit of time for everything to load. Be patient, it could take a few minutes.

When you see ____ in a coding exercise, replace it with what you assume to be the correct code. Run it and see if you obtain the desired output. Submit your code to validate if you were correct.

Make sure you remove the hash (#) symbol in the coding portions of this question. We have commented them so that the line won’t execute and you can test your code after each step.

Using the same Ridge model as we obtained last time, let’s calculate what our model would predict for a player who is 2.05m tall and weighs 93.2 kg.

Tasks:

  • Build and fit a Ridge model with default hyperparameters and name it ridge_bb.
  • What are the coefficients for this model? Save these in an object named bb_coeffs.
  • What is the intercept for this model? Save this in an object named bb_intercept.
  • Using the coefficients and intercept discovered above, calculate the model’s prediction and save the result in player_predict.
  • Check your answer using predict.
Hint 1
  • Are you fitting your model?
  • Are you finding the coefficients using ridge_bb.coef_? print(bb_weights)
  • Are you using ridge_bb.intercept_ to find your model’s intercept?
  • Are you calculating your model’s predictions with bb_intercept + (bb_coeffs*player_stats).sum(axis=1)?
  • You can check your calculation using predict with ridge_bb.predict(player_stats).
Fully worked solution: