CommencerCommencer gratuitement

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()

Cet exercice fait partie du cours

Generalized Linear Models in Python

Afficher le cours

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

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

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

# View model coefficients
print(model_lm.params)
Modifier et exécuter le code