Linear Regression Implementation
Linear regression in scikit-learn is simple: from sklearn.linear_model import LinearRegression; model = LinearRegression(); model.fit(X, y).
The model learns coefficients (model.coef_) and intercept (model.intercept_). Predictions: model.predict(X_new).
Multiple Linear Regression
Multiple regression works the same way with multiple features. X should have shape (n_samples, n_features). Coefficients show each feature's contribution.
Regularization
Ridge regression adds L2 penalty: Ridge(alpha=1.0). Lasso adds L1 penalty: Lasso(alpha=1.0). ElasticNet combines both.
Regularization strength (alpha) is tuned via cross-validation. Higher alpha means more shrinkage.
Key Takeaways
- Linear regression is simple to implement in scikit-learn
- Multiple features work seamlessly
- Regularization prevents overfitting in high dimensions