Regularization स्ट्रेंथ समायोजित करना
आपके मौजूदा Lasso मॉडल का \(R^2\) स्कोर 84.7% है। जब किसी मॉडल में बहुत अधिक शक्तिशाली regularization लगाया जाता है, तो उसमें उच्च bias आ सकता है, जिससे इसकी predictive क्षमता कमज़ोर पड़ती है।
आइए alpha पैरामीटर को बदलकर predictive power और मॉडल की सादगी के बीच बेहतर संतुलन बनाते हैं।
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में Dimensionality Reduction
अभ्यास निर्देश
- विकल्पों
1,0.5,0.1, और0.01में से ऐसा सबसे बड़ाalphaमान चुनें, जो \(R^2\) को 98% से ऊपर रखे।
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Find the highest alpha value with R-squared above 98%
la = Lasso(____, random_state=0)
# Fits the model and calculates performance stats
la.fit(X_train_std, y_train)
r_squared = la.score(X_test_std, y_test)
n_ignored_features = sum(la.coef_ == 0)
# Print peformance stats
print(f"The model can predict {r_squared:.1%} of the variance in the test set.")
print(f"{n_ignored_features} out of {len(la.coef_)} features were ignored.")