Aan de slagGa gratis aan de slag

Linear model, a special case of GLM

In this exercise you will fit a linear model two ways, one using the ols() function and one using the glm() function. This will show how a linear model is a special case of a generalized linear model (GLM).

You will use the preloaded salary dataset introduced in the video.

Recall that the linear model in Python is defined as:

ols(formula = 'y ~ X', data = my_data).fit()

and the generalized linear model can be trained using

glm(formula = 'y ~ X', data = my_data, family = sm.families.___).fit()

Deze oefening maakt deel uit van de cursus

Generalized Linear Models in Python

Cursus bekijken

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

import ____ as ____
from ____.____.____ import ____, ____

# Fit a linear model
model_lm = ols(formula = '____ ~ ____',
               data = ____).fit()

# View model coefficients
print(model_lm.params)
Code bewerken en uitvoeren