การถดถอย: การ Regularization

ฝึกตอบคำถามสัมภาษณ์ Machine Learning ด้วย Python

Lisa Stuart

Data Scientist

อัลกอริทึม Regularization

  • Ridge regression
  • Lasso regression
  • ElasticNet regression
ฝึกตอบคำถามสัมภาษณ์ Machine Learning ด้วย Python

Ordinary least squares

กราฟ OLS

สูตร OLS

1 https://en.wikipedia.org/wiki/Linear_regression#Simple_and_multiple_linear_regression
ฝึกตอบคำถามสัมภาษณ์ Machine Learning ด้วย Python

ฟังก์ชัน Loss ของ Ridge

กราฟ Ridge regression

สูตร Ridge regression

1 https://gerardnico.com/data_mining/ridge_regression#tuning_parameter_math_lambdamath
ฝึกตอบคำถามสัมภาษณ์ Machine Learning ด้วย Python

ฟังก์ชัน Loss ของ Lasso

กราฟ Lasso regression

สูตร Lasso regression

1 https://stats.stackexchange.com/questions/155192/why-discrepancy-between-lasso-and-randomforest
ฝึกตอบคำถามสัมภาษณ์ Machine Learning ด้วย Python

Ridge vs Lasso

Regularization L1 (Lasso) L2 (Ridge)
ลงโทษ ผลรวมค่าสัมบูรณ์ของสัมประสิทธิ์ ผลรวมกำลังสองของสัมประสิทธิ์
คำตอบ sparse non-sparse
จำนวนคำตอบ หลายคำตอบ หนึ่งคำตอบ
การเลือกฟีเจอร์ ใช่ ไม่ใช่
ทนต่อ outlier? ใช่ ไม่ใช่
รูปแบบซับซ้อน? ไม่ใช่ ใช่
ฝึกตอบคำถามสัมภาษณ์ Machine Learning ด้วย Python

ElasticNet

สูตร ElasticNet

ฝึกตอบคำถามสัมภาษณ์ Machine Learning ด้วย Python

Regularization กับข้อมูลบ้านในบอสตัน

ฟีเจอร์ CHAS NOX RM
ค่าประมาณสัมประสิทธิ์ 2.7 -17.8 3.8
ค่าประมาณสัมประสิทธิ์หลัง Regularization 0 0 0.95
ฝึกตอบคำถามสัมภาษณ์ Machine Learning ด้วย Python

ฟังก์ชัน Regularization

# 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)
ฝึกตอบคำถามสัมภาษณ์ Machine Learning ด้วย Python

มาฝึกกันเถอะ!

ฝึกตอบคำถามสัมภาษณ์ Machine Learning ด้วย Python

Preparing Video For Download...