Linear Regression in Machine Learning

Linear Regression in machine learning is one of the algorithms that help us to establish a relationship between two variables.

We have seen before that it belongs to the supervised learning types.

Moreover, it helps us to predict the best outcome based on the datasets that we provide to the machine.

Now in this first section on linear regression we will see what kind of libraries we have used and how we have got the prediction. 

To start with let us take the Iris Datasets from the Toy Datasets of scikit-learn library. 

Usuually the Iris Datasets are used for classification. But one can use it for other purposes such as linear regression models.


If you are a complete beginner your journey to learn TensorFlow might start from here.

For the TensorFlow beginners we have a dedicated category – TensorFlow for Beginners.
But besides that, you may need to learn several other machine learning and data science libraries.

As a result, you may check these categories as well – NumPy, Pandas, Matplotlib.

However, without learning Python, you cannot learn the usages of these libraries. Why? Because they all use Python as the Programming language.

Therefore please learn Python at the very beginning and start learning TensorFlow.

And, finally please check our Mathematics, Discrete Mathematics and Data Structures categories specially. We have tried to discuss from basic to intermediate level so that you can pick up the core ideas of TensorFlow.

However, in our case, we have first imported three machine learning libraries and see the number of columns and rows. 

They are Matplotlib, NumPy and scikit-learn.

import matplotlib.pyplot as plt
import numpy as np
from sklearn import datasets, linear_model, model_selection


X, y = datasets.load_iris(return_X_y=True)

print(X.shape)
print(X[2])

Here goes the output.

(150, 4)
[4.7 3.2 1.3 0.2]

Consequently, the above output shows us that 150 instances. And there are three types of Iris flowers which have 4 numeric, predictive attributes and the class.

Since there are four columns, and 150 rows, we have given output of the third row. Right?

We can check it in our output in which we have slightly changed the code.

import seaborn as sns
import matplotlib.pyplot as plt
# this will pick up the head part
iris_head = sns.load_dataset('iris')
iris_head.head()

The output below displays the first five rows.

First Data table form Iris datasets
First Data table form Iris datasets

Now what does linear regression mean at the first hand? As we said earlier, there are two variables – one is independent which we plot on the x axis.

Besides, we have a dependent variable that we plot on the y axis.

When the value of the dependent variable increases with the increase in the independent variable, we consider the line positive. 

However, if it does not happen, we call it negative.

Now in our case, we see the positive outcome.

That means with the petal length, the width increases.

Linear Regression in Machine Learning
Linear Regression in Machine Learning

How the code works, we will discuss in the next section.

So stay tuned, happy and cheer up.

For the respective GitHub repository please visit the page.

What Next?

Books at Leanpub

Books in Apress

My books at Amazon

GitHub repository

Flutter, Dart, Python and TensorFlow

C, C++ Java, and Game Development

Twitter

Comments

Leave a Reply