Linear regression algorithm predicts continous values (like price, temperature).
This is another article in the machine learning algorithms for beginners series.
It is a supervised learning algorithm, you need to collect training data for it to work.
Related course: Machine Learning Intro for Python Developers
Classification output can only be discrete values. There can be ,, etcetera.
What if you want to output prices or other continous values?
Then you use a regression algorithm.
Lets say you want to predict the housing price based on features. Collecting data is the
first step. Features could be number of rooms, area in m^2, neighborhood quality and others.
Write down the feature: #area_m2.
For our example in code that looks like this.
from sklearn.linear_model import LinearRegression
Then you can create a plot based on that data (if you want to).
You see there is a correlation between the area and the price.
This is a linear relationship.
You can predict the price, with a linear regression algorithm.
First you import the linear regression algorithm from like it learn then you defined a training data X and the Y where axis the area and y is the price.
model = LinearRegression()
Linear regression algorithm because there is a linear relationship then we train the algorithm using the training data.
Now that the algorithm is trained you can make predictions using the area.
A new example, can predict the price for you.
rooms = 11
This algorithm LinearRegression only works if there is a linear relation in your data set.
If there isn’t, you need a polynomial algorithm.
Plot to verify that there is a linear relation.