Memuat
Memuat
Ridge and Lasso Regression for Psychology
0 views
Estimate depression score with Ridge and Lasso regression on screen time and social support score and compare coefficient shrinkage. Ridge and Lasso are linear regressions with L2 and L1 penalties that control overfitting and collinearity. They are used when predictors are many or correlated, and Lasso also selects variables.

Estimate depression score with Ridge and Lasso regression on screen time and social support score and compare coefficient shrinkage.
| Role | Variable | Unit |
|---|---|---|
| Main | Depression score | skor |
| Supporting 1 | Screen time | jam/hari |
| Supporting 2 | Social support score | skor |
Lasso retains 6 of 6 predictors for Depression score at alpha 0.001 (test R2 0.878), while Ridge reaches R2 0.878.
Computed from illustrative synthetic data, not from a real study.
Ridge and Lasso are linear regressions with L2 and L1 penalties that control overfitting and collinearity. They are used when predictors are many or correlated, and Lasso also selects variables.
Report the chosen alpha, test metrics, and the coefficients that shrink or become zero. Explain that coefficients are biased in exchange for lower variance, so they are not read like OLS.
A short starting script with this project's variable names. The delivered version is adapted to your data and fully commented.
import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import RidgeCV, LassoCV, LinearRegression
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import make_pipeline
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error
rng = np.random.default_rng(1)
n, p = 150, 10
X = rng.normal(size=(n, p))
X[:, 1] = X[:, 0] + rng.normal(0, 0.1, n) # collinear pair
screen_time = X[:, 0]
social_support_score = X[:, 1]
depression_score = 3 * screen_time + 2 * X[:, 2] + rng.normal(0, 1, n)
X_tr, X_te, y_tr, y_te = train_test_split(X, depression_score, test_size=0.25, random_state=1)
models = {
"OLS": make_pipeline(StandardScaler(), LinearRegression()),
"Ridge": make_pipeline(StandardScaler(), RidgeCV(alphas=np.logspace(-3, 3, 30))),
"Lasso": make_pipeline(StandardScaler(), LassoCV(cv=5, random_state=1)),
}
coefs = {}
for name, m in models.items():
m.fit(X_tr, y_tr)
rmse = mean_squared_error(y_te, m.predict(X_te)) ** 0.5
coefs[name] = m[-1].coef_
print(name, "RMSE:", round(rmse, 3))
print("Ridge alpha:", models["Ridge"][-1].alpha_)
print("Lasso alpha:", round(models["Lasso"][-1].alpha_, 4))
print("Lasso zero coefs:", int((coefs["Lasso"] == 0).sum()))
idx = np.arange(p)
for k, (name, c) in enumerate(coefs.items()):
plt.bar(idx + 0.27 * k, c, width=0.27, label=name)
plt.xlabel("Feature"); plt.ylabel("Coefficient"); plt.legend()
plt.show()Choose how much help you need. Each higher package includes everything in the lower ones. Prices exclude 11% VAT.
Package 1
US$22
excl. 11% VAT
Duration: 5 working days
Output: Python files + result figures
Deliverables
Package 2 · most chosen
US$63
excl. 11% VAT
Duration: 9 working days
Output: Code + analysis + interpretation notes
Includes all of Package 1, plus
Package 3
US$141
excl. 11% VAT
Duration: 14-17 working days
Output: Code + analysis + guidance until ready to present
Includes all of Packages 1 & 2, plus
Yes. Ridge and Lasso Regression is commonly used at this level in Psychology. We adapt the analysis to your research question, your own data and your supervisor's requirements.
No. The sheet is computed from illustrative synthetic data so you can see the kind of output Python gives. For your order we run the same method on your own data.
That is the point of the packages. Every script is commented, and Package 3 includes two coaching sessions plus practice questions so you can explain the method and the results at your seminar and defence.
Each project has three packages: Package 1 (code and explanation) US$22, Package 2 (your data analysis and interpretation) US$63 and Package 3 (full guidance) US$141, excluding 11% VAT. Larger datasets, extra methods or tight deadlines adjust the quote after a short consultation.
The result sheet uses illustrative synthetic data. Python is a trademark of the Python Software Foundation.
Back to Python portfolio