Confusion matrix की गणना
एक confusion matrix (कभी-कभी confusion table भी कहा जाता है) श्रेणीबद्ध response वाले मॉडलों (जैसे logistic regression) के सभी performance metrics का आधार है. इसमें प्रत्येक actual response–predicted response जोड़ी की गणनाएँ (counts) होती हैं. इस मामले में, जहाँ दो संभावित responses हैं (churn या not churn), कुल मिलाकर चार परिणाम होते हैं.
- True positive: ग्राहक ने churn किया और मॉडल ने भी यही predict किया.
- False positive: ग्राहक ने churn नहीं किया, लेकिन मॉडल ने churn predict किया.
- True negative: ग्राहक ने churn नहीं किया और मॉडल ने भी churn न होने का predict किया.
- False negative: ग्राहक ने churn किया, लेकिन मॉडल ने churn न होने का predict किया.
churn और mdl_churn_vs_relationship उपलब्ध हैं.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में statsmodels के साथ Regression परिचय
अभ्यास निर्देश
- डेटासेट के
has_churnedकॉलम को subset करके actual responses निकालें.actual_responseको असाइन करें. - मॉडल से "सबसे संभावित" predicted responses प्राप्त करें.
predicted_responseको असाइन करें. actual_responseऔरpredicted_responseसे एक DataFrame बनाएँ.outcomesको असाइन करें.outcomesको counts की table के रूप में प्रिंट करें, जो confusion matrix को दर्शाती है. यह आपके लिए कर दिया गया है.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Get the actual responses
actual_response = ____
# Get the predicted responses
predicted_response = ____
# Create outcomes as a DataFrame of both Series
outcomes = pd.DataFrame({____,
____})
# Print the outcomes
print(outcomes.value_counts(sort = False))