• #### 科普

SCIENCE

#### 英语

ENGLISH

#### 科技

TECHNOLOGY

MOVIE

FOOD

#### 励志

INSPIRATIONS

#### 社会

SOCIETY

TRAVEL

#### 动物

ANIMALS

KIDS

#### 卡通

CARTOON

#### 计算机

COMPUTER

#### 心理

PSYCHOLOGY

#### 教育

EDUCATION

#### 手工

HANDCRAFTS

#### 趣闻

MYSTERIES

CAREER

GEEKS

#### 时尚

FASHION

• 精品课
• 公开课
• 欢迎下载我们在各应用市场备受好评的APP

点击下载Android最新版本

点击下载iOS最新版本

扫码下载译学馆APP

#### 《机器学习Python实践》#7 回归是如何实现的

Regression How it Works - Practical Machine Learning Tutorial with Python p.7

What is going on everybody and welcome to part seven of our machine learning with Python tutorial series in this video.

We are going to be beginning to break down linear regression

and begin to build it back up in pure Python code from scratch ourselves.

Before we get started we have to kind of break down linear regression theoretically

before we actually know what to to program

by the time we’re done here you’ll start to at least understand one how linear regression can be threaded

but also most importantly why it works with what’s known as continuous data.

This isn’t just a happenstance is just fundamental to how this linear regression actually works.

So let’s go ahead and cover a couple of examples.

So for let’s say you have a dataset expert visualization by Sentdex like this.

Okay so when you look at these data points do you see any sort of correlation.

Well probably you may see a line that goes something like that okay.

And let’s consider another dataset

And this dataset will do something like this not not the most professional dots but you get the point right.

So you can see how you might draw a line through this.

Right? no problem and in theory this should be a straight line okay.

But then what about a dataset looked like.

Maybe a dataset that looks like this

ignoring this ugly plot over here.

Right? this dataset does it have a best-fit line? yes. does have a correlation?

Not……I mean it probably has some sort of correlation if anything looks looks like it has a slight negative correlation.

But for the most part I mean you could draw a best fit line but would be would it be a good fit line?

Right? any answer of course is is is no.

Okay. so we can see right away that you know is there a relationship between, in our case, x and y.

And it doesn’t look like there is a valid relationship between them.

So in the case where you don’t have a relationship between x and y

doing something like linear regression is not going to be very beneficial

and also it’s just clearly that like yes X could be in theory kind of continuous and y could be continuous data.

But we just see there’s no there’s really no relationship here.

Okay so this this data just would not work with linear regression.

So let’s say though you do you’ve got a graph

and you’ve got got some data okay so we’ve got some data.

And you decide yeah you sure sure can do linear regression like like eyeballing it or something

we might say that.

Okay so so we have this line right this pink line this is our best fit line

right and it is a we’ll assume it’s a straight line

what is the definition like how do you define that line?

Well I will take a journey back to

to middle school where we remember that y equals mx plus b.

right? And obviously where…you know you got your two values

next to each other that they’re being multiplied.

So we know the equation of a line y equals mx plus b.

So at any point along x right like let’s say you’ve got some X

at any point along x you would just you you just plug X into here

and then you need the values of m and b

and then you will just get the answer for whatever y is, okay.

So with the question of y equals mx plus b
x 是多少我们应该都可以知道
we know that we’ll be able to figure out whatever x is.

But we are left trying to figure out what is m and what is b.

So first let’s talk about what m is so we know m is the slop alright that’s the slope of the line.

And we know that b is the y-intercept.

Okay so first let’s consider the slope

so here we are going to just address m which is our slope.

So the equation for m is for a best fit

we’re talking about just for a best fit line here.

The way that you figure that out is m equals

and this is going to be the mean of x times the mean of y.

So when you have a straight line those are supposed to to be straight lines

we have a straight line over the value that’s just the mean.

So x the mean of all the Xs times the mean of all the Ys minus the mean of all the Xs times Ys

Okay so it’s important to understand the difference between those first multiplication and the second multiplication.

Then it’s all of that over the mean of your X squared minus the mean of your X’s squared.

Right? so this is the the mean of all your X’s to the power of 2 minus the mean of X’s to the power of 2.

Right? and that’s all of your Xs okay.

Now we are going to be talking about the the y intercept or best fit y intercept.

So that’s just a b and that is your y intercept I’m going to say y int.

And this one is actually a much easier equation

And that is actually just simply b equals

and this is going to be the mean of Ys minus m times the mean of Xs.

Right so that m is you know from over there.

So that’s how you can calculate the m and b.

So again the line is simply y equals mx plus b

we have our m here we’ve got our b here

So now you’re already to go with the calculation of the best fit line given any Xs and Ys

Now again this is simply on you know

two dimensional data as you as you increase in your dimensions in vector space this can get much more complex

but yes whereas this is very simple regression example.

So anyways that’s the math that goes behind it. it just basically boils down to

you know this is the major algorithm that you are using and to find the values.

you’re using this algorithm and this algorithm.

And that can be very simply translated to Python code so that’s what we’re going to be starting to do.

In the next tutorial is converting these to actually Python code

and then applying it to some actual some actual data here.

So if you have any questions comments concerns whatever, leave them below. otherwise as always thanks for watching. thanks for all the support and subscription and until next time.

##### 译制信息

Python机器学习线性回归数学原理讲解

[B]倔强

[B]刀子