Python में Generalized Linear Models
Ita Cirovic Donev
Data Science Consultant
मॉडल फिट मिलने के बाद

मॉडल फिट मिलने के बाद
मूल $x$ मानों के लिए fitted values
नए $x$ मानों के लिए predicted values

हॉर्सशू क्रैब मॉडल y ~ weight
$$
\mu = \frac{\exp(-3.6947+1.8151 \times weight)}{1+\exp(-3.6947+1.8151 \times weight)}
$$
नया मापन: weight = 2.85
$$ \mu = \frac{\exp(-3.6947+1.8151 \times \color{blue}{2.85})}{1+\exp(-3.6947+1.8151 \times \color{blue}{2.85})} = 0.814 $$
new_data के लिए मॉडल प्रेडिक्शंस निकालें# Compute model predictions
model_GLM.predict(exog = new_data)

# मॉडल से fitted probabilities निकालें
crab['fitted'] = model.fittedvalues.values
# कट-ऑफ मान तय करें
cut_off = 0.4
# क्लास प्रेडिक्शंस निकालें
crab['pred_class'] = np.where(crab['fitted'] > cut_off, 1, 0)
# हर क्लास के occurrences गिनें
crab['pred_class'].value_counts()
1 151
0 22
| कट-ऑफ | $\hat y=1$ | $\hat y=0$ |
|---|---|---|
| $\mu = 0.4$ | 151 | 22 |
| $\mu = 0.5$ | 126 | 47 |





print(pd.crosstab(y_actual, y_predicted,
rownames=['Actual'], colnames=['Predicted'],
margins = True))
Predicted 0 1 All
Actual
0 15 47 62
1 7 104 111
All 22 151 173
Python में Generalized Linear Models