Logistic regression coefficients को एक्सप्लोर करें
अब आप logistic regression के coefficients को एक्सप्लोर करेंगे ताकि समझ सकें कि churn किन कारणों से ऊपर या नीचे जाता है. इस अभ्यास में, आप अपने fitted मॉडल से logistic regression coefficients निकालेंगे, और उन्हें ज़्यादा interpretable बनाने के लिए उनका exponent निकालेंगे.
Fitted logistic regression इंस्टेंस logreg के रूप में लोड है और scaled फीचर्स train_X नाम की pandas DataFrame में लोड हैं. numpy और pandas लाइब्रेरी क्रमशः np और pd के रूप में लोड हैं.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में मार्केटिंग के लिए मशीन लर्निंग
अभ्यास निर्देश
- फीचर नाम और coefficients को मिलाकर एक
pandasDataFrame बनाएँ. - Logistic regression coefficients का exponent निकालें.
- जिन coefficients का मान शून्य है, उन्हें हटा दें और बाकी को exponent coefficient के अनुसार sort करके प्रिंट करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Combine feature names and coefficients into pandas DataFrame
feature_names = pd.DataFrame(___.columns, columns = ['Feature'])
log_coef = pd.DataFrame(np.transpose(logreg.coef_), columns = ['Coefficient'])
coefficients = pd.concat([feature_names, ___], axis = 1)
# Calculate exponent of the logistic regression coefficients
coefficients['Exp_Coefficient'] = np.___(coefficients['Coefficient'])
# Remove coefficients that are equal to zero
coefficients = coefficients[coefficients['Coefficient']!=___]
# Print the values sorted by the exponent coefficient
print(coefficients.sort_values(by=['___']))