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

Training data का undersampling

अब बारी है कि आप Pandas की कुछ पंक्तियों से training set का undersampling खुद करें। Undersampling पूरा होने के बाद, आप loan_status के value counts देखकर नतीजों को verify कर सकते हैं.

X_y_train, count_nondefault, और count_default पहले से workspace में लोड हैं। इन्हें निम्न कोड से बनाया गया है:

X_y_train = pd.concat([X_train.reset_index(drop = True),
                       y_train.reset_index(drop = True)], axis = 1)
count_nondefault, count_default = X_y_train['loan_status'].value_counts()

मूल training data के .value_counts() अपने-आप प्रिंट हो जाएँगे।

यह अभ्यास पाठ्यक्रम का हिस्सा है

Python में क्रेडिट रिस्क मॉडलिंग

पाठ्यक्रम देखें

अभ्यास निर्देश

  • non-defaults और defaults के data sets बनाएँ और उन्हें nondefaults और defaults में स्टोर करें।
  • nondefaults को count_default की समान संख्या तक sample करें और उसे nondefaults_under में रखें।
  • .concat() का उपयोग करके nondefaults और defaults को जोड़ें और उसे X_y_train_under में स्टोर करें।
  • नए data set के लिए loan status के .value_counts() को प्रिंट करें।

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

# Create data sets for defaults and non-defaults
____ = ____[____[____] == 0]
____ = ____[____[____] == 1]

# Undersample the non-defaults
____ = nondefaults.sample(____)

# Concatenate the undersampled nondefaults with defaults
____ = pd.____([____.reset_index(drop = True),
                             ____.reset_index(drop = True)], axis = 0)

# Print the value counts for loan status
print(____[____].____())
कोड संपादित करें और चलाएँ