連續變數的模型矩陣
在影片中你學到模型公式、dmatrix() 在背後如何運作以取得模型矩陣,以及它與 glm() 函式之間的關係。你已經知道,dmatrix() 的輸入是 glm() 公式參數的右手邊部分。若變數來自資料框,則也要透過 data 參數指定資料來源。
dmatrix('y ~ x1 + x2',
data = my_data)
在這個練習中,你會在模型擬合之前先分析並確認模型的結構。
資料集 wells 已預先載入到工作區中。
本練習屬於課程
Generalized Linear Models in Python
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import function dmatrix()
from ____ import ____
# Construct model matrix with arsenic
model_matrix = ____('____', data = ____, return_type = 'dataframe')
print(model_matrix.____())