OK, guys, and welcome back to our class of our course with the complete introduction to data science
with Python.
So in the past few classes, we talked about all the different algorithms that exist.
And basically we talked about the theory behind all of those algorithms.
So basically right now, you should have some basic knowledge about each of those algorithms.
And right now we are going to practice writing them down on your text editor, which is.
So basically, we're going to write down some of those algorithms inside of picture.
So pretty simple today.
We are going to start with linear regression.
So basically, we're going to learn what we're going to create a linear regression model with Aristo.
Basically, we're going to generate arrays and create a linear regression model.
So for the purpose of this class, we're going to use non-pay to be able to make these calculations
and work with arrays as well as matplotlib to be able to visualize everything that we will create.
So let's start.
So, as always, the first thing that we need to do is import the tools that we are going to work with.
And in this case, we are going to work with numpties.
So we are going to import it and we are going to work with matplotlib.
Here we go.
So that Bayport as BLT.
All right.
So when we have everything so right now, we have imported everything that we need.
So we have no idea as well as by blood.
And as I said, the first thing that we need to do is create our IRI's because we will work with those
numbers.
So basically, this would be our database to have our X's and our ways inside of the graph that we are
going to create.
So let's start basically where are X right now?
So the value of X, as I said, will be a Arry.
So let's write it down.
So pretty simple.
What I'll ask you guys to do is to write down from 10 to 15 numbers.
It can be random numbers.
So you you write down whatever you guys want.
Doesn't have to be big numbers.
It doesn't have to be small numbers.
You guys decide what you want to write.
All right.
Next thing is writing down our Y values.
Right now we have our X values and write down our white values.
All right.
So once again, you decide what numbers you want to write down.
And what I want to do right now is simply print everything to be sure that our hours worked perfectly,
that we didn't make any mistake.
All right, so that's everything, all right.
So right now, we have our eyes right here so you can see everything works perfectly, everything works
fine.
It's awesome.
So the next thing I want to do so if you want to keep your print, you can keep it.
If you want to delete it, you can delete.
Want to do right now is want to create a function that will allow us to generate those.
Well, to make the calculation for our well for our plug in.
Well not our upload but our sloup inside of our regression model.
So we will do it by using the Bollywood function.
So basically we'll return an array of coefficients that will minimize the squared error.
So basically how exactly we write it down is pretty simple.
So we'll create a function that will call function.
So function one where you can limit whatever you guys want.
So it's going to be ENPI because we are referring to a number by two in number by function and it's
going to be following that.
So inside of our prolific function we have three arguments.
So we have the X in our case, the Y.
So basically the database that we are going to use and finally we have a number.
So it's going to be one in our case.
So if we run everything.
I mean, just that's the function, I forgot to print it.
So if we print our function one and we run everything.
As you can see, this would be the answer of this function right here.
So this is the answer that is generated.
All right.
So next thing that I want to do, we want to create our graph.
So basically we are going to use a Matlab function, which is that blood.
So we want to plug all our points.
So as always, we are using X and Y as data and what type of points we want.
It's pretty simple.
We want small circles.
So to have small circles will just write down points.
So we have a point.
So if we run everything.
I just write it down, Kielty got so.
So we have our small points right here, so basically those points represent our well, all the points
that we have right here and want to do right now, it's pretty simple.
We want to add a line right here to be able to have a linear regression.
Once again, the points right here are not really representative of something, but we'll be able to
have an average line in the middle right now.
All right.
So how exactly do we do this?
It's pretty simple.
We will simply add another function.
So once again, we'll write down our block function.
And in this case, we will need to use another function, which is the function and basically dysfunctional.
Allow us to add a line that I'm talking about.
So pretty simple, how do we do this?
It's pretty simple, so we will need a few arguments to make it work.
So we'll have our X, which will be part of our database then where we are going to make a reference
to numbers and p that public info.
And in this case we will have our function.
So we are making reference to our function, which is function.
26.
And finally, the last little thing that went right down would be our miners and then simply show everything.
So basically we have all the arguments that we need right now to be able to write down our function.
So if we run everything, as you can see, we have our life right here in the middle.
So the main problem of all this so basically what we can see with this model right now is that there
is no correlation between X and Y.
So basically, there is nothing that well, there is no correlation between those two points, because
once again, the points are everywhere on the graph and the line is just right here.
So basically, the line doesn't mean a lot because in our case, the points are just everywhere on the
graph.
But basically there is no correlation between X's and Y's in this example.
If, for example, the points where, I don't know, in the street or.
So basically, let's say it's one, two, three, four and etc..
Well, to have different.
So let's let me just show you another dataset.
So let's say instead of all this, we have another that I said that looks something like this, so more
simple.
So one, two, three, four or five.
And we are up.
So as you can see, it's a bit more representative right now.
The line is a bit more representative and it makes more sense because the points, the more R X grows,
the more are Y groups.
Basically, this is this this is what we can understand from our graph right here.
And it makes a little bit more sense that the graph where the points were everywhere on the graph.
So we get this help us find a correlation between X and Y, and in this case, we have a correlation.
It's not a really strong correlation, but once again, it's a we have a correlation there.
Well, there are statistical ways to find the correlation between X and Y, between the well, between
X and Y and the points on the graph.
Once again, we're not going to talk about this right now.
You know how to create a basic linear regression model and how exactly you can evaluate this model.
So that's a first class guys in you in our next class.