Lecture: Learning Linear Regression and Machine Learning, python, R ver. 4

Last Updated on November 22, 2021 by shibatau

I. What do you learn?

We will learn Linear Regression and Machine Learning and think about the different ways of traditional Statistics and Machine Learning to find a regression fit line.

II. Linear Regression

The scripts are here:


Sample data

Showing the different losses between the two lines put casually.

Finding the best regression fit line.

III. Least Squares

1.Searching regression fit lines with R



2.Searching regression fit lines interactively

Least Squares Regression Line

IV. Machine Learning

Refer to the following post for creating Gradient Descent animation with Python

Gradient Descent animation: 1. Simple linear Regression

I have created an animation according to the scripts above on Google Colaboratory. Scripts are here:




Splitting the dataset into the training set and the test set, Machine Learning  trains the former and test the latter.

Calculate an R squared value. This is a metric for prediction. The predominant task of Machine Learning is predictive modeling: the creation of models for predicting labels of new examples.

r_sq = regressor.score(X, y)
print('coefficient of determination:', r_sq)
# coefficient of determination: 0.9565349708076958

The value of R square ranges between [0, 1].
R2= 1- SSres / SStot
– SSres represents the sum of squares of the residual errors of the data model.
– SStot represents the total sum of the errors.

Higher is the R square value, better is the model and the results.

Refer to: Coefficient of Determination – R squared value in PYthon

About shibatau

I was born and grown up in Kyoto. I studied western philosophy at the University and specialized in analytic philosophy, especially Ludwig Wittgenstein at the postgraduate school. I'm interested in new technology, especially machine learning and have been learning R language for two years and began to learn Python last summer. Listening toParamore, Sia, Amazarashi and MIyuki Nakajima. Favorite movies I've recently seen: "FREEHELD". Favorite actors and actresses: Anthony Hopkins, Denzel Washington, Ellen Page, Meryl Streep, Mia Wasikowska and Robert DeNiro. Favorite books: Fyodor Mikhailovich Dostoyevsky, "The Karamazov Brothers", Shinran, "Lamentations of Divergences". Favorite phrase: Salvation by Faith. Twitter: @shibatau

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.