回帰:正則化

Pythonで学ぶMachine Learning面接対策

Lisa Stuart

Data Scientist

正則化アルゴリズム

  • Ridge 回帰
  • Lasso 回帰
  • ElasticNet 回帰
Pythonで学ぶMachine Learning面接対策

最小二乗法(OLS)

OLS のプロット

OLS の式

1 https://en.wikipedia.org/wiki/Linear_regression#Simple_and_multiple_linear_regression
Pythonで学ぶMachine Learning面接対策

Ridge の損失関数

リッジ回帰のプロット

リッジ回帰の式

1 https://gerardnico.com/data_mining/ridge_regression#tuning_parameter_math_lambdamath
Pythonで学ぶMachine Learning面接対策

Lasso の損失関数

ラッソ回帰のプロット

ラッソ回帰の式

1 https://stats.stackexchange.com/questions/155192/why-discrepancy-between-lasso-and-randomforest
Pythonで学ぶMachine Learning面接対策

Ridge と Lasso の比較

正則化 L1(Lasso) L2(Ridge)
罰則 係数の絶対値の和 係数の二乗和
解 スパース 非スパース
解の数 複数 一意
特徴選択 あり なし
外れ値に頑健? はい いいえ
複雑なパターン? いいえ はい
Pythonで学ぶMachine Learning面接対策

ElasticNet

ElasticNet の式

Pythonで学ぶMachine Learning面接対策

Boston 住宅データでの正則化

特徴量 CHAS NOX RM
係数推定値 2.7 -17.8 3.8
正則化後の係数推定値 0 0 0.95
Pythonで学ぶMachine Learning面接対策

正則化の関数

# Lasso estimator 
sklearn.linear_model.Lasso

# Lasso estimator with cross-validation
sklearn.linear_model.LassoCV

# Ridge estimator
sklearn.linear_model.Ridge

# Ridge estimator with cross-validation
sklearn.linear_model.RidgeCV

# ElasticNet estimator
sklearn.linear_model.ElasticNet
# ElasticNet estimator with cross-validation
sklearn.linear_model.ElasticNetCV

# Train/test split
sklearn.model_selection.train_test_split

# Mean squared error
sklearn.metrics.mean_squared_error(y_test, 
                           predict(X_test))
# Best regularization parameter
mod_cv.alpha_

# Array of log values
alphas=np.logspace(-6, 6, 13)
Pythonで学ぶMachine Learning面接対策

Ayo berlatih!

Pythonで学ぶMachine Learning面接対策

Preparing Video For Download...