4.1. Exercises

Is it Overfitting or Underfitting?

Overfitting and Underfitting True or False

Overfitting/Underfitting in Action!

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.

Letโ€™s examine our validation scores and training scores a bit more carefully and assess if our model is underfitting or overfitting.

This time we are looking at a new data set that contains the basketball players in the NBA. We are only going to use the players with a position of Guard (G) or Forward (F). We will be using features height, weight and salary to try to predict the playerโ€™s position, Guard or Forward.

Letโ€™s take a quick look at it before diving in.

Tasks:

  • Cross-validate using cross_validate() on the objects X_train and y_train making sure to specify 10 folds and return_train_score=True.
  • Convert the scores into a dataframe and save it in an object named scores_df.
  • Calculate the mean value of each column and save this in an object named mean_scores.
  • Answer the question below.
Hint 1
  • Are you cross-validating using cross_validate(model, X_train, y_train, cv=10, return_train_score=True) on your model?
  • Are you saving your dataframe using pd.DataFrame(scores)?
  • Are you using .mean() to calculate the mean of each column in scores_df?
Fully worked solution: