Predictions निकालें
अक्सर व्यावहारिक रूप से, हम fitted logistic regression का उपयोग probabilities का अनुमान लगाने और उनके लिए confidence intervals बनाने में करते हैं। wells डेटासेट और मॉडल 'switch ~ arsenic' के साथ मान लीजिए कि आपके पास नई observations wells_test हैं जो training sample का हिस्सा नहीं थीं, और आप नज़दीकी सुरक्षित कुएँ पर स्विच करने की probability को predict करना चाहते हैं.
आप यह .predict() मेथड की मदद से करेंगे.
ध्यान दें कि .predict() कई arguments लेता है:
exog- नई observations (test डेटासेट)transform = True- फिट की formulay ~ xको डेटा पर लागू करता है.
यदि exog परिभाषित नहीं है तो probabilities training डेटासेट के लिए compute की जाती हैं.
मॉडल wells_fit और डेटासेट wells तथा wells_test workspace में पहले से लोड हैं.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में Generalized Linear Models
अभ्यास निर्देश
- Fitted मॉडल
wells_fitका उपयोग करके test डेटाwells_testपर prediction निकालें और उसेpredictionके रूप में सेव करें. - मौजूदा data frame
wells_testमेंpredictionजोड़ें और कॉलम का नामpredictionरखें. print()का उपयोग करकेwells_testकी पहली 5 पंक्तियाँ दिखाएँ, जिनमें कॉलमswitch,arsenicऔरpredictionहों। केवल पहली 5 पंक्तियाँ देखने के लिए pandas फंक्शनhead()का उपयोग करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Compute predictions for the test sample wells_test and save as prediction
prediction = ____.predict(exog = ____)
# Add prediction to the existing data frame wells_test and assign column name prediction
____[____] = ____
# Examine the first 5 computed predictions
print(____[[____, ____, ____]].head())