Bias और Variance की समस्याओं का निदान

Python में Tree-Based Models के साथ Machine Learning

Elie Kawerk

Data Scientist

Generalization Error का अनुमान

  • हम किसी मॉडल की generalization error का अनुमान कैसे लगाएँ?

  • सीधे नहीं कर सकते क्योंकि:

    • $f$ अज्ञात है,

    • आमतौर पर आपके पास केवल एक डेटासेट होता है,

    • noise अप्रत्याशित है.

Python में Tree-Based Models के साथ Machine Learning

Generalization Error का अनुमान

समाधान:

  • डेटा को training और test सेट में बाँटें,
  • $\hat{f}$ को training सेट पर फिट करें,
  • unseen test सेट पर $\hat{f}$ की error मापें.
  • $\hat{f}$ की generalization error $\approx$ test सेट error.
Python में Tree-Based Models के साथ Machine Learning

Cross-Validation से बेहतर मूल्यांकन

  • जब तक आप $\hat{f}$ के प्रदर्शन पर आश्वस्त न हों, test सेट को न छुएँ.

  • training सेट पर $\hat{f}$ का मूल्यांकन: biased estimate, $\hat{f}$ ने सभी training पॉइंट पहले ही देख लिए हैं.

  • समाधान $\rightarrow$ Cross-Validation (CV):

    • K-Fold CV,

    • Hold-Out CV.

Python में Tree-Based Models के साथ Machine Learning

K-Fold CV

K-Fold CV का आरेख

Python में Tree-Based Models के साथ Machine Learning

K-Fold CV

CV error का प्लॉट

Python में Tree-Based Models के साथ Machine Learning

Variance समस्याओं का निदान

  • अगर $\hat{f}$ में high variance है:

    $\hat{f}$ की CV error > training सेट error.

  • $\hat{f}$ training सेट पर overfit करता है. Overfitting कम करने के तरीके:
    • मॉडल complexity घटाएँ,
    • जैसे: max depth घटाएँ, min samples per leaf बढ़ाएँ, ...
    • ज़्यादा डेटा जुटाएँ, ..
Python में Tree-Based Models के साथ Machine Learning

Bias समस्याओं का निदान

  • अगर $\hat{f}$ में high bias है:

    $\hat{f}$ की CV error $\approx$ training सेट error >> वांछित error.

  • $\hat{f}$ training सेट को underfit करता है. Underfitting कम करने के तरीके:

    • मॉडल complexity बढ़ाएँ
    • जैसे: max depth बढ़ाएँ, min samples per leaf घटाएँ, ...
    • और प्रासंगिक फीचर जुटाएँ
Python में Tree-Based Models के साथ Machine Learning

Auto डेटासेट पर sklearn में K-Fold CV

from sklearn.tree import DecisionTreeRegressor
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error as MSE
from sklearn.model_selection import cross_val_score

# Set seed for reproducibility SEED = 123 # Split data into 70% train and 30% test X_train, X_test, y_train, y_test = train_test_split(X,y, test_size=0.3, random_state=SEED)
# Instantiate decision tree regressor and assign it to 'dt' dt = DecisionTreeRegressor(max_depth=4, min_samples_leaf=0.14, random_state=SEED)
Python में Tree-Based Models के साथ Machine Learning

Auto डेटासेट पर sklearn में K-Fold CV

# Evaluate the list of MSE ontained by 10-fold CV 
# Set n_jobs to -1 in order to exploit all CPU cores in computation
MSE_CV = - cross_val_score(dt, X_train, y_train, cv= 10, 
                           scoring='neg_mean_squared_error',
                           n_jobs = -1)

# Fit 'dt' to the training set dt.fit(X_train, y_train) # Predict the labels of training set y_predict_train = dt.predict(X_train) # Predict the labels of test set y_predict_test = dt.predict(X_test)
Python में Tree-Based Models के साथ Machine Learning
# CV MSE  
print('CV MSE: {:.2f}'.format(MSE_CV.mean()))
CV MSE: 20.51
# Training set MSE
print('Train MSE: {:.2f}'.format(MSE(y_train, y_predict_train)))
Train MSE: 15.30
# Test set MSE
print('Test MSE: {:.2f}'.format(MSE(y_test, y_predict_test)))
Test MSE: 20.92
Python में Tree-Based Models के साथ Machine Learning

अभ्यास करते हैं!

Python में Tree-Based Models के साथ Machine Learning

Preparing Video For Download...