正則化強度を調整する
現在のLassoモデルの \(R^2\) スコアは84.7%です。正則化が強すぎるとバイアスが大きくなり、予測性能が下がることがあります。
alpha パラメータを調整して、予測力とモデルのシンプルさのバランスを改善しましょう。
この演習はコースの一部です
Pythonで学ぶ次元削減
演習の手順
- 次の選択肢
1、0.5、0.1、0.01の中から、\(R^2\) が98%を超える条件でのalphaの「最大」値を見つけてください。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# 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.")