RidgeとLassoの正則化
ペナルティで過学習を抑える
「RidgeとLassoの正則化」はCoddyKit上の無料Data Science Academyレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはData Science Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Data Science Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
When a Line Overfits
Plain linear regression can chase noise, growing huge coefficients that fit training data yet fail on new data. That trap is called overfitting. 😬
Add a Penalty
Regularization fixes this by adding a penalty for large coefficients. The model now balances fitting the data against keeping weights small.
Ridge Shrinks Weights
Ridge penalizes the squared size of the coefficients. It pulls every weight toward zero but rarely makes any exactly zero.
from sklearn.linear_model import Ridge
model = Ridge(alpha=1.0).fit(X, y)Lasso Can Zero Them Out
Lasso penalizes the absolute size instead. This can drive weak coefficients all the way to zero, dropping those features entirely.
from sklearn.linear_model import Lasso
model = Lasso(alpha=0.1).fit(X, y)Lasso Selects Features
Because Lasso zeroes weak weights, it doubles as feature selection. The surviving non-zero coefficients are the ones it found useful.
Alpha Sets the Strength
The alpha knob controls how hard the penalty pushes. Bigger alpha means stronger shrinkage and a simpler, smoother model.
Too Much Alpha Underfits
Crank alpha too high and coefficients shrink so far the model ignores real signal. That opposite mistake is called underfitting.
Scale Before You Penalize
Penalties compare coefficients directly, so features must share a scale first. Standardize your data or the penalty hits big-unit features unfairly.
from sklearn.preprocessing import StandardScalerRidge or Lasso?
Use Ridge when most features help a little, and Lasso when you suspect many are useless and want a sparse, lean model.
ElasticNet Blends Both
Can't decide? ElasticNet mixes the Ridge and Lasso penalties, giving you shrinkage and some feature dropping at the same time.
from sklearn.linear_model import ElasticNetTune With Cross-Validation
Never guess alpha by hand. Try a range and pick the value that scores best on held-out folds with cross-validation.
from sklearn.linear_model import RidgeCVQuick Check
One key difference sets these two apart in practice.
Recap
Regularization tames overfitting: Ridge shrinks weights, Lasso can zero them, and alpha sets the strength. Scale first, then tune. 🎯
よくある質問
「RidgeとLassoの正則化」レッスンは無料ですか?
はい。「RidgeとLassoの正則化」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Data Science Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Data Science Academyコースには全4レッスンが含まれています。
「RidgeとLassoの正則化」で何を学びますか?
ペナルティで過学習を抑える ブラウザで直接実行するハンズオンコードでData Science Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Data Science Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのData Science Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。
「RidgeとLassoの正則化」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このData Science Academyレッスンでコードを書いて実行できますか?
はい。すべてのData Science Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- 線形回帰を再確認する
- RidgeとLassoの正則化
- 決定木回帰
- 回帰に使うランダムフォレスト