1.1. Exercises

Linear Regression Questions

True or False: Ridge

Using 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 our well know basketball dataset, we are going to build a model using the height feature and assess if it can help predict a player’sweight.

Tasks:

  • Create a MAPE scorer from the mape function that we provided. Make sure you specify in the scorer that lower numbers are better for MAPE.
  • Build a Ridge model called ridge_bb.
  • Use GridSearchCV to hyperparameter tune alpha. Fill the blanks so it uses ridge_bb as an estimator and the values from param_dist.
  • Fit your grid search on the training data.
  • What is the best value for alpha? Save it in an object named best_alpha.
  • What is the best MAPE score? Save it in an object named best_mape.
Hint 1
  • Are you making the MAPE scorer with make_scorer(mape, greater_is_better=False)?
  • Are you filling in the blank for GridSearchCV as grid_search = GridSearchCV(ridge_bb, param_dist,cv=5, n_jobs=1, random_state=123, scoring=neg_mape_scorer)?
  • Are you fitting with grid_search.fit(X_train, y_train)?
  • Are you finding the best alpha as grid_search.best_params_?
  • Are you finding the best score with grid_search.best_score_?
Fully worked solution: