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

Regularization

Regularization वह प्रक्रिया है जिसमें overfitting रोकने के लिए किसी मॉडल में अतिरिक्त जानकारी जोड़ी जाती है. यह इस अध्याय में पहले देखे गए evaluation metrics को बेहतर बनाने के लिए महत्वपूर्ण है. इस अभ्यास में, आप decision tree के max depth पैरामीटर को बदलकर देखेंगे कि classification के नतीजे कैसे प्रभावित होते हैं.

X_train, y_train, X_test, y_test आपके workspace में उपलब्ध हैं. pandas as pd, numpy as np, और sklearn भी आपके workspace में उपलब्ध हैं. साथ ही, sklearn.metrics से confusion_matrix(), precision_score(), और recall_score() उपलब्ध हैं.

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

Python में Machine Learning के साथ CTR प्रेडिक्शन

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

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

  • हर tree की अधिकतम गहराई (maximum depth) बदलकर अलग-अलग decision trees बनाइए.
  • प्रत्येक tree के लिए, मॉडल fit कीजिए और testing data पर predictions निकालिए.
  • प्रत्येक tree के लिए confusion matrix, precision, और recall का मूल्यांकन कीजिए.

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

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

# Iterate over different levels of max depth
for max_depth_val in [2, 3, 5, 10, 15, 20]:
  # Create and fit model
  clf = ____(____ = max_depth_val)
  print("Evaluating tree with max_depth = %s" %(max_depth_val))
  y_pred = clf.fit(____, ____).predict(____) 
  
  # Evaluate confusion matrix, precision, recall
  print("Confusion matrix: ")
  print(____(y_test, y_pred))
  prec = ____(____, ____, average = 'weighted')
  recall = ____(____, ____, average = 'weighted')
  print("Precision: %s, Recall: %s" %(prec, recall))
कोड संपादित करें और चलाएँ