What's going on Everybody Welcome [to] the fifth machine Learning and Fourth Regression tutorial in This Tutorial?
We're Going to be Building on the last one Where
We created This Linear Regression Algorithm We Found that it's got great Accuracy and all that
And now we're Ready to actually Predict like out Into the Unknown right
[so] it Turns out we [Actually] Already do have some Unknown Data Simply Because
We're Forecasting out this Shift right Which was About 30 Days
So, we Can [actually] Work with that so what we're Going to do is where We define our?
our
[X'S]
Let's do The Following Let's Actually cut this Come Down here Paste [and] we're Going to Take this drop in A cut-And-Paste
[and] Now I am reminded why, I was doing that negative forecast out so
So what, we're Going to do Is x?
Equals x to
[The] Negative [4] [cast] out
um
[Colt] Let's See Negative 4 Cast out to [the] point of Negative 4 cast out
And then, we're Going to Say
We're Going to do x
Underscore [Lately]
Equals x to the Minus 4 cast out Comp :
and
Then we're Going to Drop?
The Missing Data When, We go to create the labels this way, We have Both our X'S and our x Lately?
[Defined] so the x Lately Basically is the stuff that, we're Going to Actually Predict against so we have the x'S and then
We just need to figure out what the M and the B. Is right for y. Equals Mx plus B
We get the answer for y. We've done Linear Regression so?
So, we're Going to do it against These Lately X's that we Actually don't have a [Y-Value] for which is why?
We were not Training or Testing on that Data?
So now, We have our x lately so the next thing that
We're Going to go [ahead] and do is Basically, we?
Down Here and Actually it's going to run this Really quick [Just] to Make Sure, we're Still Actually getting the Accuracy
We don't have an incorrect number of values okay?
Now, We don't so we're Good so we've got [96%] Accuracy awesome so we'll Come down We'll comment this out?
We don't Really need That Anymore [and]
Now to Predict stuff [what] you Would do Is and also Make Sure we Scale See so?
What we need to do is take this?
Almost Made a Mistake There and This
Now Let's run that One More [Time] I make Sure I didn't
Screw Anything Up
Good, ok, so now, we're going to do, Is we're Going to come Down Here and
We need to Predict based on the x Data so the Way that
We can do this Once You have a classifier doing a prediction is Actually super Easy so
We're Going to Say forecast set
Equals Cl. F dot Predicts and Then Here you [can]
[Actually] Pass A single value or you can
Pass Like an Array of values to Predict Make a Prediction per Value in That Array and that's what
We're Going to do right we've got this heat This 30 Days of Data Basically right Here
So uh
X lately rather so 30 Days here okay so it's the last 30 Days so x Lately
We want to Create That With x lately so then, We have our forecast set so now We can, do we Can Print?
Forecast Set
Forecast Set Confidence and
Forecast out just so we [know] how Many Days were Forecasting out Here
This Up
[Bo]
Confidence do We or, Accurate I'm sorry yeah so i changed This I usually use Confidence so Accuracy try
Again Pull This Up and
Yes so there We [go] so we've got our Predicted values so these are
The Basically The next 30 Days of Unknown values for Us that's like These are Just straight up the stock Prices
Which
Is actually Pretty cool because, we you know like that whole Scaling part Is also Playing A?
Major Role Here it's Still Outputting you know Stock Prices That are of
Decent Value To us anyway [I] think it's cool
So so These are the next
30 Days of Prices so then let's Say you, wanted to graph that so what we're Going to do?
Is we're Going to come Up to the Top and again?
We're Going to just blast Through Wrapping This if you're Confused or whatever I have matt Plot lib
Tutorials so you Can Check Those out if You want to learn more About Graphing but Otherwise
We're Going to Import and in Fact We'll Just Add date Time Here
Date Time
And then, we're Going to Import matt Plot plug
Lib [pie] [Plot] as [P] [lt]. From matt Plot
Lib
Import Style and Then, We're Going to Say Styled I use
Gg Plot so [it's] Just to plot stuff this Is how to Make it Look decent [This] Is how to specify Which
Decent Looking Thing you want so now
What we're Going to Say Is we're Come Down?
[We'll] Just Come Down Here and we're Going to say df
Forecast
Equals nP [and] This Just Specifies That that entire Column is Just
Full of Not a Number Data and you'll see why in a moment but We'll Actually put some Information there Shortly
Now, we need to find out what the last Date was this might not be the bestest way to do something like this but This
Is how we're Going to Actually Plot this on on the the graph so to Say Last Date
Equals df [Kyle] [Oak]
Whoops
Negative 1 so this is the very Last, Date We'll get the name of that and then
We're Going to Say the last unix Value Is equal to last date Time Stamp and
Then One day This Is how Many Seconds are in a day so you can just do the math There if You want but it's
86,400 and then the next unix
Would Be like the next day Right and These are We know These are Daily Prices so we're Just Going to
We're Kind of Hard Coding this part it just so we Can create a graph but Last unix plus one day
So when you do a Prediction the Prediction has no idea like what
Date that Is that's like [Four] all right so remember
When you're doing machine Learning [x] and y Does not Correspond to like
Necessarily the Axes on a graph in This case it doesn't x or the Features
[Y] is the label it Just so happens the label is the Price so [y] it is correct
What is x correct no because the Date Is not a feature so that's that's why?
We're Kind of Having to Work Around here Because?
We actually don't have the date Values I have lost my mouse I have no Idea Where my mouse Is there We go anyway
Next [unix], okay so now we've got the Dates and Now we need to actually Populate the
Data Frame With the the new Dates and
The forecast values so the way, we're going to do that Is we're Going to Say for I in
Forecast Set
next date Equals [date] Time Date Time dot from [Timestamp]
Next
Unix and
then We're Just going to Say next unix, plus Equals That value of one day so one Day and
Then Df Dot Loke
[and] then next date Whoops next Date
Equals and then, we're Going to, do like a one-Liner for loop here so we're Gonna Say [mpn] for something
We don't Care about in Range of?
The Len of df
Columns
Let's See, range Minus 1 and then plus I
So what we're Doing?
Is we're Iterating Through the forecast set Taking each Forecast and day and then setting Those as the values in the Data Frame
Basically Making The Features
[The] Future Feature Is not a number okay [and]
Then The last line Just Takes all of The first Columns Sets Them to
Numbers and Then The Final Column is Whatever I is which is the Forecast in This Case?
so now, we're Going to go ahead and do Is
We're Going to say df
Adj dot Close
Dot Plot and then, we're Going to say df
Forecast
for Cast
Dot Plot and Then
We're Going to do plt legend we'll put that in The Fourth [Location] that's Just like the Bottom right and then
We're Gonna Say [Pl] [Tx] label
And we'll Say that's the date plt Dot Y Label that is your?
Price and Then Finally plt - oh, okay, [so] we Zoom Through that Hopefully that for Loop is going to Work out
[We'll] find out Shortly?
See, i've got a graph Here yes
[ok] so this is our actual Graph of the Data Pull this Up and
As you can See this Is this is the known Data Here and Then
Over [Here] is our Predicted Data so Let me Zoom [Into] [That] spot
Right so this is like the future Prediction here the forecast, [okay]?
Um so it's just like a really quick way to visualize the Data and Really the Complex Part the Reason why
We had All This Nasty to Crap in Here was Just Simply so you Can Have Dates on the Axes?
Because that's How I am I wanted to have the dates There so anyway [but] yeah so that's how you Can Actually forecast out
The Data and [Actually] do a Prediction but the Crux of doing a Prediction With Scikit-Learn Is
Right
Here and
Just Remember you Can Pass a single value or you could Pass an Array [of] values and it will Just
Output in The Same order The Array of values and Then from There
We [just] used Logic to know that each Because each investment Is a day writer each Price Report was it One day?
So then that Just means that each forecast. Was like One Day Later right so we just kind of used our Brains for that One?
so Anyway
and i guess the other Thing to think About DFl Oak Just in Case I'm not Sure We ever Actually covered that in
Pandas But What Happens There is Basically dot [Lok] is going to be Referencing the
Index for the Data Frame so when you do [df] [not] Lok, next date Basically what that's Saying
Is that next date is a date Stamp right and that next day Is um
the
Index of the Data Frame so Maybe it Would Help Just
Let's See print do you have to [ahead] so if You're not if You're not
Confused At This Point Feel free to Care Down to the next Video Where we'll be Talking about Pickling but if you are Confused about
That for Loop I just want to explain that for loop Just so everyone. No, One's like what the hell
So Anyways so yeah so here [write] the date Is the Index so when We Say [DFx] Date?
We're Saying the Index and if that Index doesn't exist it's going to create it and if it did Exist it Would Just Replace it
Okay, then, we're Saying [npm] for underscore in Range lang df Columns Minus, One What the heck Is that?
What that [is] Is Just A list of Values [that] [are] Mp nan so Basically
We're Saying it's Mp nan for a just a high percent Change but all this stuff is Just
Not a number right Because this is Into the future, We don't have Information on that Data okay then?
Coming Back Down Here then, we're Saying plus I
Remember I is the forecast right Right I in forecast set so then
We're Just Saying so basically Is Just this list plus one Value so it's like this Huge List
Well not Huge it's Just These this Many, Columns right, well then
We just Add forecasts at the very end so that's Just our super Hacky way of?
Doing the Following I said to head There but Probably Would've Been More Useful to Say Tail and
so you can see the end of this Data Frame
How yet These are all Those np Nan's and then Finally Just [forecasts] okay so that's all that Is
Sorry if that was a little Confusing Hopefully the Explanation Worked if Not Feel free to ask Question or whatever I'll be happy to Clarify
It now
Then There's Actually One More Thing I want to show you all before
We dive Into Regression and Actually Write a regression Algorithm all on our Own and that's Pickling and the Reason why?
You'd want to Pickle is imagine you have rather than Training a classifier on this you know Relatively Small Data set
We just Had Daily values for the last few Years?
But you Know if you save this to a file you know it's Probably like you know 500 Kilobytes Or something who knows
But let's Say you!
Had Like Intraday Data and You've Got like Two gigabytes Worth of Data that's going to take a while to
Train The Classifier on that Data, so wouldn't it be Nice if Every Time you wanted to Make a prediction so just Consider
Making a Prediction using future Data
Consider Every Time you wanted to Make a Prediction that you Would have to train the Classifier Is that not Just
Crazy Sounding so yes That's Crazy Sounding so in the next tutorial
We're Going to be Talking about Pickling which will let you save your Classifier and then Just Quickly Load it in Without any Training Time
so Definitely very
Useful With Machine Learning
Classifiers so Anyways That's what we'll be Talking About the next Video Questions Comments [leave] them Below Otherwise as always Thanks for Watching Thanks for?
All the support and Subscriptions and until next Time