1. Learn
  2. /
  3. Courses
  4. /
  5. Helsinki Open Data Science

Connected

Exercise

Binary predictions (1)

When you have a linear model, you can make predictions. A very basic question is, of course, how well does our model actually predict the target variable. Let's take a look!

The predict() function can be used to make predictions with a model object. If predict() is not given any new data, it will use the data used for finding (fitting, leaning, training) the model to make predictions.

In the case of a binary response variable, the 'type' argument of predict() can be used to get the predictions as probabilities (instead of log of odds, the default).

Instructions

100 XP
  • Fit the logistic regression model with glm().
  • Create object probabilities by using predict() on the model object.
  • Mutate the alc data: add a column 'probability' with the predicted probabilities.
  • Mutate the data again: add a column 'prediction' which is true if the value of 'probability' is greater than 0.5.
  • Look at the first ten observations of the data, along with the predictions.
  • Use table() to create a cross table of the columns 'high_use' versus 'prediction' in alc. This is sometimes called a 'confusion matrix`.