टेस्ट और ट्रेन पर मॉडल का मूल्यांकन
फंक्शन auc_train_test उस मॉडल का AUC निकालता है जो train सेट पर बनाया गया है और test सेट पर इवैल्यूएट किया गया है:
auc_train, auc_test = auc_train_test(variables, target, train, test)
यहाँ variables उस सूची को दर्शाता है जिसमें मॉडल में उपयोग किए गए वैरिएबल्स के नाम होते हैं.
इस अभ्यास में, आप इस फंक्शन को लागू करेंगे और जाँचेंगे कि train और test AUC एक-दूसरे के समान हैं या नहीं.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में प्रिडिक्टिव एनालिटिक्स परिचय
अभ्यास निर्देश
basetableलोड है. basetable को इस तरह विभाजित करें कि train सेट में 70% डेटा हो, और यह सुनिश्चित करें कि train और test सेट में target incidence समान हो.auc_train_testफंक्शन का उपयोग करते हुए"age"और"gender_F"को predictors के रूप में लेकर मॉडल के train और test AUC की गणना करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Load the partitioning module
from sklearn.model_selection import train_test_split
# Create DataFrames with variables and target
X = basetable.drop('target', 1)
y = basetable["target"]
# Carry out 70-30 partititioning with stratification
X_train, X_test, y_train, y_test = ____(X, y, test_size = ____, stratify = ____)
# Create the final train and test basetables
train = pd.concat([X_train, y_train], axis=1)
test = pd.concat([X_test, y_test], axis=1)
# Apply the auc_train_test function
auc_train, auc_test = ____([____, ____], ["target"], ____, ____)
print(round(auc_train,2))
print(round(auc_test,2))