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

Exercise

Variable transformation

Continuing with the wells you will practice applying variable transformation directly in the formula and model matrix setting without the need to add the transformed data to the data frame first. You will also revisit the computation of model error or deviance to see if the transformation improved the model fit.

Recall the structure of dmatrix() function is the right hand side of the glm() formula argument in addition to the data argument.

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

The dataset wells and the model model_ars with arsenic (original variable) have been preloaded in the workspace.

Instructions 1/3

undefined XP
    1
    2
    3
  • Import numpy as np, and dmatrix from patsy.
  • Construct a model matrix by applying the logarithm transformation on arsenic using numpy log() function.