chapter four

4 Optimizing the training process: Underfitting, overfitting, testing, and regularization

 

This mini-chapter covers

  • What is underfitting and overfitting?
  • Underfitting and overfitting in regression models.
  • A solution for avoiding overfitting: Testing the model.
  • Using a model complexity graph to make decisions on our model.
  • Another solution to avoid overfitting: Regularization.
  • Calculating the complexity of the model using the L1 and L2 norms.
  • Picking the best model in terms of performance and complexity.

This chapter is different from the majority of the chapters in this book, as it doesn’t contain a particular machine learning algorithm. Instead, it contains some potential problems that machine learning models may face, and effective practical ways to solve them.

Imagine that you have learned some great machine learning algorithms, and you are ready to apply them. You go to work as a data scientist and your first task is to build a machine learning model for a dataset of customers. You build it and put it in production. However, everything goes wrong and the model doesn’t do a good job making predictions. What happened?

4.1    An example of underfitting and overfitting using polynomial regression

4.2    How do we get the computer to pick the right model? By testing

4.2.1    How do we pick the testing set and how big should it be?

4.2.2    Can we use our testing data for training the model? No.

4.3    Where did we break the golden rule, and how do we fix it? The validation set

4.4    A numerical way to decide how complex our model should be - The model complexity graph

4.5    Another alternative to avoiding overfitting - Regularization

4.5.1    Another example of overfitting - Movie recommendations

4.5.2    Measuring how complex a model is - L1 and L2 norm

4.5.3    Modifying the error function to solve our problem - Lasso regression and ridge regression

4.5.4    Regulating the amount of performance and complexity in our model - The regularization parameter

4.5.5    Effects of L1 and L2 regularization in the coefficients of the model

4.5.6    An intuitive way to see regularization

4.6    Polynomial regression, testing, and regularization with Turi Create

4.7    Summary

4.8    Exercises

4.8.1    Exercise 4.1

4.8.2    Exercise 4.2