Memuat
Memuat
Ridge and Lasso Regression for Civil Engineering and Transportation
0 views
Model soil settlement from soil water content and embankment load using Ridge and Lasso Regression and evaluate the model performance. 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.

Model soil settlement from soil water content and embankment load using Ridge and Lasso Regression and evaluate the model performance.
| Role | Variable | Unit |
|---|---|---|
| Main | Soil settlement | cm |
| Supporting 1 | Soil water content | % |
| Supporting 2 | Embankment load | kPa |
Lasso retains 4 of 6 predictors for Soil settlement at alpha 0.006 (test R2 0.942), while Ridge reaches R2 0.941.
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
soil_water_content = X[:, 0]
embankment_load = X[:, 1]
soil_settlement = 3 * soil_water_content + 2 * X[:, 2] + rng.normal(0, 1, n)
X_tr, X_te, y_tr, y_te = train_test_split(X, soil_settlement, 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$66
excl. 11% VAT
Duration: 9 working days
Output: Code + analysis + interpretation notes
Includes all of Package 1, plus
Package 3
US$144
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 Civil Engineering and Transportation. 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$66 and Package 3 (full guidance) US$144, 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