Modellieren mit kategorialer Variable
In den vorherigen Übungen hast du ein logistisches Regressionsmodell mit color als erklärender Variable zusammen mit width angepasst, wobei du color als quantitative Variable behandelt hast. In dieser Übung behandelst du color als kategoriale Variable. Beim Erstellen der Modellmatrix wird color dann mit einer 0/1-Kodierung in 3 Variablen kodiert.
Denk daran: Die Standardkodierung in dmatrix() verwendet die erste Gruppe als Referenzgruppe. Um die Modellmatrix als DataFrame zu sehen, wird in dmatrix() das zusätzliche Argument return_type auf 'dataframe' gesetzt.
Die Variable color hat die folgende natürliche Reihenfolge:
1: medium light
2: medium
3: medium dark
4: dark
Der Datensatz crab ist im Workspace bereits geladen.
Diese Übung ist Teil des Kurses
Generalisierte lineare Modelle in Python
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# Construct model matrix
model_matrix = ____('C(____, ____(____))' , data = ____,
return_type = 'dataframe')
# Print first 5 rows of model matrix dataframe
print(____.____)
# Fit and print the results of a glm model with the above model matrix configuration
model = ____('____ ~ ____(____, ____(____))', data = ____,
family = ____).____
print(____.____)