Course Wiki
Linear regression — Machine Learning Zoomcamp Module 2
Model for solving regression tasks, in which the objective is to adjust a line for the data and make predictions on new values. The input of this model is the feature matrix X and a y vector of predictions is obtained, trying to be as...
Related Pages
Machine Learning Zoomcamp › Module 2: Machine Learning for Regression › Linear regression
Notes
Model for solving regression tasks, in which the objective is to adjust a line for the data and make predictions on new values. The input of this model is the feature matrix X and a y vector of predictions is obtained, trying to be as close as possible to the actual y values. The linear regression formula is the sum of the bias term ( $w_0$ ), which refers to the predictions if there is no information, and each of the feature values times their corresponding weights as ( $x_{i1} \cdot w_1 + x_{i2} \cdot w_2 + … + x_{in} \cdot w_n$ ).
So the simple linear regression formula looks like:
$g(x_i) = w_0 + x_{i1} \cdot w_1 + x_{i2} \cdot w_2 + … + x_{in} \cdot w_n$.
And that can be further simplified as:
$g(x_i) = w_0 + \displaystyle\sum_{j=1}^{n} w_j \cdot x_{ij}$
Here is a simple implementation of Linear Regression in python:
w0 = 7.1
def linear_regression(xi):
n = len(xi)
pred = w0
w = [0.01, 0.04, 0.002]
for j in range(n):
pred = pred + w[j] * xi[j]
return pred
If we look at the $\displaystyle\sum_{j=1}^{n} w_j \cdot x_{ij}$ part in the above equation, we know that this is nothing else but a vector-vector multiplication. Hence, we can rewrite the equation as $g(x_i) = w_0 + x_i^T \cdot w$
We need to assure that the result is shown on the untransformed scale by using the inverse function exp().
The entire code of this project is available in this jupyter notebook.
| ⚠️ |
The notes are written by the community. If you see an error here, please create a PR with a fix. |
Key concepts
Related notes
- mlz-m01-introduction-to-numpy
- mlz-m01-introduction-to-pandas
- mlz-m01-linear-algebra-refresher
- mlz-m01-setting-up-the-environment
- mlz-m02-baseline-model-for-car-price-prediction-project
- mlz-m02-car-price-prediction-project
- mlz-m02-car-price-prediction-project-summary
- mlz-m02-categorical-variables
- mlz-m02-computing-rmse-on-validation-data
- mlz-m02-data-preparation
- mlz-m02-exploratory-data-analysis
- mlz-m02-explore-more
- mlz-m02-feature-engineering
- mlz-m02-linear-regression-vector-form
- mlz-m02-regularization
- mlz-m02-root-mean-squared-error-rmse
- mlz-m02-setting-up-the-validation-framework
- mlz-m02-training-linear-regression-normal-equation
- mlz-m02-tuning-the-model
- mlz-m02-using-the-model
- mlz-m03-data-preparation
- mlz-m03-eda
- mlz-m03-explore-more
- mlz-m03-feature-importance-churn-rate-and-risk-ratio
- mlz-m03-feature-importance-correlation
- mlz-m03-feature-importance-mutual-information
- mlz-m03-logistic-regression
- mlz-m03-model-interpretation
- mlz-m03-one-hot-encoding
- mlz-m03-setting-up-the-validation-framework
- mlz-m03-training-logistic-regression-with-scikit-learn
- mlz-m04-accuracy-and-dummy-model
- mlz-m04-confusion-table
- mlz-m04-cross-validation
- mlz-m04-roc-auc
- mlz-m04-roc-curves
- mlz-m04-summary
- mlz-m06-gradient-boosting-and-xgboost
- mlz-m06-xgboost-parameter-tuning
- mlz-m08-installation-of-tensorflow
- mlz-m10-creating-a-pre-processing-service