Predictions को manually कैलकुलेट करना
Simple linear regression की तरह, आप मॉडल coefficients से predictions को manually भी कैलकुलेट कर सकते हैं। Parallel slopes के मामले में बस एक बदलाव है: categorical explanatory variable की हर category के लिए intercept अलग होता है। इसका मतलब, आपको हर category के होने पर उसे अलग से consider करना होगा।
taiwan_real_estate, mdl_price_vs_both, और explanatory_data उपलब्ध हैं; पिछले अभ्यास से ic_0_15, ic_15_30, ic_30_45, और slope भी लोडेड हैं।
यह अभ्यास पाठ्यक्रम का हिस्सा है
इंटरमीडिएट Regression with statsmodels in Python
अभ्यास निर्देश
- तीन शर्तों के साथ
conditionsनाम की एक सूची परिभाषित करें:house_age_years"0 to 15"है,house_age_years"15 to 30"है, औरhouse_age_years"30 to 45"है। choicesनाम की एक सूची परिभाषित करें, जिसमेंmdl_price_vs_bothसे निकाले गए intercepts हों। ये ऊपर दी गई शर्तों से क्रमवार मेल खाते हों।np.select()का उपयोग करके intercepts की एक array बनाएँ।prediction_dataबनाएँ:explanatory_dataसे शुरू करें,interceptको intercepts की array असाइन करें, औरprice_twd_msqको manually कैलकुलेट किए गए predictions के रूप में असाइन करें।
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Define conditions
conditions = [____]
# Define choices
choices = [____]
# Create array of intercepts for each house_age_year category
intercept = ____(____, ____)
# Create prediction_data with columns intercept and price_twd_msq
prediction_data = ____.____(
____ = ____,
____ = ____ + ____ * ____[____])
print(prediction_data)