शुरू करेंमुफ़्त में शुरू करें

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 - फिट की formula y ~ 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())
कोड संपादित करें और चलाएँ