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

उत्तम tree depth पहचाने

अब आप decision tree के max_depth पैरामीटर को tune करेंगे ताकि over-fitting कम हो और मॉडल के performance metrics अच्छे बने रहें. आप एक for लूप कई max_depth मानों पर चलाएँगे, हर मान के लिए decision tree फिट करेंगे, और फिर performance metrics निकालेंगे.

depth_list नाम की list, जिसमें पैरामीटर के candidate हैं, आपके लिए लोड कर दी गई है. depth_tuning नाम का array आपके लिए 2 कॉलम के साथ तैयार है: पहले कॉलम में depth candidates भरे हुए हैं, और अगले कॉलम में recall score के लिए placeholder है. इसके अलावा, features और target वैरिएबल्स training डेटा के लिए train_X, train_Y और test डेटा के लिए test_X, test_Y नाम से लोड हैं. numpy और pandas लाइब्रेरी क्रमशः np और pd के रूप में उपलब्ध हैं.

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

Python में मार्केटिंग के लिए मशीन लर्निंग

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

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

  • List depth_list की length तक 0 से range लेकर एक for लूप चलाएँ.
  • हर depth candidate के लिए decision tree classifier initialize और fit करें और test डेटा पर churn predict करें.
  • हर depth candidate के लिए recall_score() फंक्शन से recall score निकालें और उसे depth_tunning के दूसरे कॉलम में स्टोर करें.
  • depth_tuning से उपयुक्त कॉलम नामों के साथ एक pandas DataFrame बनाएँ.

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

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

# Run a for loop over the range of depth list length
for index in ___(0, len(depth_list)):
  # Initialize and fit decision tree with the `max_depth` candidate
  mytree = DecisionTreeClassifier(___=depth_list[index])
  mytree.fit(___, train_Y)
  # Predict churn on the testing data
  pred_test_Y = mytree.predict(___)
  # Calculate the recall score 
  depth_tuning[index,1] = ___(test_Y, ___)

# Name the columns and print the array as pandas DataFrame
col_names = ['Max_Depth','Recall']
print(pd.DataFrame(depth_tuning, columns=___))
कोड संपादित करें और चलाएँ