1️⃣Linear Regression
Linear regression is a supervised learning algorithm used to predict a continuous outcome variable (also called dependent variable) based on one or more predictor variables (also known as independent variables, features or attributes). Linear regression models the relationship between the data-points by fitting a linear equation to the observed data.

The basic idea behind linear regression is that there is a linear relationship between the input variables (x) and the output variable (y). This relationship is represented by an equation of the form:
where b0, b1, b2, ..., bn are the coefficients of the linear equation and x1, x2, ..., xn are the input variables. The coefficients are estimated from the training data using a method called Ordinary Least Squares (OLS).
Once the coefficients are estimated, the linear regression model can be used to make predictions on new data. For example, given a new input data point (x), the predicted output (y) can be computed by plugging the values of the input variables into the linear equation.
Linear regression is simple, easy to understand and interpret, and it has good interpretability. However, it can only be used when there is a linear relationship between the input and output variables. If the relationship is non-linear, a non-linear regression model would have to be used.
Example
This code imports the necessary libraries and defines the input variable x as an array of integers representing the number of hours studied and the output variable y as an array of integers representing the test scores.
Then, a LinearRegression model is created, and then it's fit to the data using the fit()
method. The coefficients of the linear equation, the intercept and the coefficient of x variable, are then printed using the intercept_
and coef_
attributes of the model.
Finally, the code makes predictions for new data points (x_new) using the predict() method and prints the predictions.
Python Code
Output:
References:
Last updated