[PYTHON] Getting Started with Tensorflow-About Linear Regression Hypothesis and Cost

Learning goals

Understand why you make hypotheses with Linear Regression Make a line of Hypothesis Understand the Loss Function that can identify hypotheses that are close to the correct answer

Glossary

the term Description
Linear Regression Linear regression
Hypothesis hypothesis
the term Description
H(x) Hypothesis
Wx Inclined(W (I don't know what it stands for))
b deviation(bias)

Reasons to make a hypothesis with Linear Regression

For the sake of simplicity, we have prepared the following training data.

x y
1 1
2 2
3 3

This is expressed linearly as follows.

スクリーンショット 2016-08-21 14.02.25.png

There are many such linear and predictable things in the world. For example:

If you want to estimate the rent of a house (the larger the house, the higher the rent) If you want to predict your exam grades (the more time you spend studying, the higher your grades)

And so on.

How to make a hypothetical line

Let's make a line to make a hypothesis Training data x and arbitrary data Make it by adding W and b.

In the formula, write as follows.

スクリーンショット 2016-08-21 14.21.25.png

What is Cost Function?

The figure below is a linear version of three hypotheses.

スクリーンショット 2016-08-21 14.10.18.png

Because the training data is x = 1, y = 1, x = 2, y = 2, x = 3, y = 3 You can see that the blue line applies to the training data. (There are only three hypotheses) But we need a way to find it mathematically so that the computer can understand it.

Therefore, we use a Loss Function.

Roughly speaking, Cost Function It is to compare the distance (y) between the "hypothetical line" and the "correct line" and identify that the shorter the distance, the more correct the line.

Compare the standing distances as shown in the figure below.

スクリーンショット 2016-08-21 15.07.10.png

"Line made by hypothesis"-"Standing distance (y)" The formula I just said is as follows.

スクリーンショット 2016-08-21 15.13.02.png

However, with this If y is larger than the hypothesized line It will be negative, so square it.

スクリーンショット 2016-09-04 15.51.33.png

Applying this formula to this training data gives:

スクリーンショット 2016-08-21 15.23.24.png

The training data is three, so I divided it by three.

To express it as an expression that can be used for millions of training data, express it as follows.

スクリーンショット 2016-08-21 16.44.32.png

Where H is スクリーンショット 2016-08-21 14.21.25.png It was the result of So I think it can be expressed as follows.

スクリーンショット 2016-08-21 16.48.06.png

Also, the smaller the cost value (W, b), the closer to the correct hypothesis can be identified. Therefore, it is expressed as follows.

スクリーンショット 2016-08-21 16.47.29.png

Conclusion so far

Make a hypothetical line using training data and arbitrary W, b values The smaller the Cost (W, b) value, the closer to the correct line.

Recommended Posts

Getting Started with Tensorflow-About Linear Regression Hypothesis and Cost
Linear regression with statsmodels
1.1 Getting Started with Python
Getting Started with Golang 2
Getting started with apache2
Getting Started with Python
Getting Started with Django 1
Getting Started with Optimization
Getting Started with Golang 3
Regression with linear model
Getting Started with Numpy
Getting started with Spark
Getting Started with Python
Getting Started with Pydantic
Getting Started with Golang 4
Getting Started with Jython
Getting Started with Django 2
Getting Started with python3 # 2 Learn about types and variables
Getting Started with Yocto Project with Raspberry Pi 4 and WSL2
Translate Getting Started With TensorFlow
Getting Started with Python Functions
Getting Started with Tkinter 2: Buttons
Getting Started with Go Assembly
Getting Started with Python Django (4)
Getting Started with Python Django (3)
Getting Started with Python Django (6)
[Python] Linear regression with scikit-learn
Getting Started with Django with PyCharm
Python3 | Getting Started with numpy
Getting Started with Python Django (5)
Robust linear regression with scikit-learn
Getting Started with Python responder v2
Getting Started with Git (1) History Storage
Getting started with Sphinx. Generate docstring with Sphinx
Getting Started with Python Web Applications
Getting Started with Python for PHPer-Classes
Getting Started with Sparse Matrix with scipy.sparse
Getting Started with Python Basics of Python
Linear regression with Student's t distribution
Getting Started with Cisco Spark REST-API
Getting started with USD on Windows
Getting Started with Python Genetic Algorithms
Getting started with Python 3.8 on Windows
Getting Started with Python for PHPer-Functions
Getting Started with CPU Steal Time
First TensorFlow (Revised) -Linear Regression and Logistic Regression
Getting Started with python3 # 1 Learn Basic Knowledge
Getting Started with Flask with Azure Web Apps
Getting Started with Python Web Scraping Practice
Difference between linear regression, Ridge regression and Lasso regression
Getting Started with Python Web Scraping Practice
Getting Started with Lisp for Pythonista: Supplement
Understanding data types and beginning linear regression
Getting Started with Heroku, Deploying Flask App
Getting Started with TDD with Cyber-dojo at MobPro
Getting Started with Processing and p5.js (for those who have done other languages) 02
Getting Started with Processing and p5.js (for those who have done other languages) 01
Linear regression
Getting started with Python with 100 knocks on language processing
MongoDB Basics: Getting Started with CRUD in JAVA
Getting Started with Drawing with matplotlib: Writing Simple Functions