1. Learn
  2. /
  3. Courses
  4. /
  5. Generalized Linear Models in Python

Exercise

Model matrix for continuous variables

In the video you learned about the model formula, the under-the-hood workings of the dmatrix() to obtain the model matrix and how it relates to the glm() function. As you have learned the input to dmatrix() is the right hand side of the glm() formula argument. In case the variables are part of the dataframe, then you should also specify the data source via the data argument.

dmatrix('y ~ x1 + x2', 
        data = my_data)

In this exercise you will analyze and confirm the structure of your model before model fit.

The dataset wells has been preloaded in the workspace.

Instructions 1/2

undefined XP
  • 1

    Import dmatrix from patsy, use it to construct the model_matrix with 'arsenic', and print the first 5 rows.

  • 2

    Import dmatrix from patsy, construct the model_matrix with 'arsenic' and 'distance100', and print the first 5 rows.