擷取參數估計值
在迴歸模型中,係數估計通常是主要關注的重點。上一個練習你已經學會如何檢視模型擬合結果,進而看到係數數值與其對應的統計量。這個練習中,你會學到如何從模型物件中擷取係數。
屬性 .params 會包含已擬合模型的係數,並以截距(intercept)開始。若要計算係數的 95% 信賴區間,可以使用已擬合模型 wells_fit 的方法 .conf_int()。
回想你所擬合的模型已儲存為 wells_fit,並且已載入到你的工作環境中。
本練習屬於課程
Generalized Linear Models in Python
練習說明
- 使用
.params屬性將係數分別儲存為intercept和slope。 - 列印剛儲存的 intercept 與 slope。
- 使用
.conf_int()擷取並列印係數的 95% 信賴區間。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Extract coefficients from the fitted model wells_fit
intercept, slope = wells_fit.____
# Print coefficients
print('Intercept =', ____)
print('Slope =', ____)
# Extract and print confidence intervals
____(____.____)