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:

https://colab.research.google.com/drive/15GwBydJBsbgIeSSBCCDm7YMD08cJKteM?usp=sharing

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

https://github.com/thomasp85/gganimate/issues/335

### 2.Searching regression fit lines interactively

## 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:

https://colab.research.google.com/drive/1tPpAxXCef_CFu_ui8nLHSWpq7I-yyXaN?usp=sharing

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

Here,

– 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