馃攳
Regression forecasting and predicting - Practical Machine Learning Tutorial with Python p.5 - YouTube
Channel: sentdex
[1]
What's going on Everybody Welcome [to] the fifth machine Learning and Fourth Regression tutorial in This Tutorial?
[7]
We're Going to be Building on the last one Where
[9]
We created This Linear Regression Algorithm We Found that it's got great Accuracy and all that
[15]
And now we're Ready to actually Predict like out Into the Unknown right
[20]
[so] it Turns out we [Actually] Already do have some Unknown Data Simply Because
[25]
We're Forecasting out this Shift right Which was About 30 Days
[29]
So, we Can [actually] Work with that so what we're Going to do is where We define our?
[36]
our
[37]
[X'S]
[38]
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
[47]
[and] Now I am reminded why, I was doing that negative forecast out so
[53]
So what, we're Going to do Is x?
[56]
Equals x to
[59]
[The] Negative [4] [cast] out
[63]
um
[67]
[Colt] Let's See Negative 4 Cast out to [the] point of Negative 4 cast out
[73]
And then, we're Going to Say
[77]
We're Going to do x
[79]
Underscore [Lately]
[83]
Equals x to the Minus 4 cast out Comp :
[91]
and
[92]
Then we're Going to Drop?
[94]
The Missing Data When, We go to create the labels this way, We have Both our X'S and our x Lately?
[101]
[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
[108]
We just need to figure out what the M and the B. Is right for y. Equals Mx plus B
[111]
We get the answer for y. We've done Linear Regression so?
[116]
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?
[122]
We were not Training or Testing on that Data?
[127]
So now, We have our x lately so the next thing that
[130]
We're Going to go [ahead] and do is Basically, we?
[133]
Down Here and Actually it's going to run this Really quick [Just] to Make Sure, we're Still Actually getting the Accuracy
[138]
We don't have an incorrect number of values okay?
[141]
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?
[147]
We don't Really need That Anymore [and]
[151]
Now to Predict stuff [what] you Would do Is and also Make Sure we Scale See so?
[161]
What we need to do is take this?
[163]
Almost Made a Mistake There and This
[167]
Now Let's run that One More [Time] I make Sure I didn't
[170]
Screw Anything Up
[173]
Good, ok, so now, we're going to do, Is we're Going to come Down Here and
[179]
We need to Predict based on the x Data so the Way that
[183]
We can do this Once You have a classifier doing a prediction is Actually super Easy so
[188]
We're Going to Say forecast set
[191]
Equals Cl. F dot Predicts and Then Here you [can]
[194]
[Actually] Pass A single value or you can
[198]
Pass Like an Array of values to Predict Make a Prediction per Value in That Array and that's what
[204]
We're Going to do right we've got this heat This 30 Days of Data Basically right Here
[209]
So uh
[211]
X lately rather so 30 Days here okay so it's the last 30 Days so x Lately
[217]
We want to Create That With x lately so then, We have our forecast set so now We can, do we Can Print?
[226]
Forecast Set
[229]
Forecast Set Confidence and
[234]
Forecast out just so we [know] how Many Days were Forecasting out Here
[240]
This Up
[242]
[Bo]
[244]
Confidence do We or, Accurate I'm sorry yeah so i changed This I usually use Confidence so Accuracy try
[250]
Again Pull This Up and
[254]
Yes so there We [go] so we've got our Predicted values so these are
[258]
The Basically The next 30 Days of Unknown values for Us that's like These are Just straight up the stock Prices
[266]
Which
[267]
Is actually Pretty cool because, we you know like that whole Scaling part Is also Playing A?
[272]
Major Role Here it's Still Outputting you know Stock Prices That are of
[276]
Decent Value To us anyway [I] think it's cool
[279]
So so These are the next
[281]
30 Days of Prices so then let's Say you, wanted to graph that so what we're Going to do?
[286]
Is we're Going to come Up to the Top and again?
[288]
We're Going to just blast Through Wrapping This if you're Confused or whatever I have matt Plot lib
[293]
Tutorials so you Can Check Those out if You want to learn more About Graphing but Otherwise
[298]
We're Going to Import and in Fact We'll Just Add date Time Here
[304]
Date Time
[306]
And then, we're Going to Import matt Plot plug
[312]
Lib [pie] [Plot] as [P] [lt]. From matt Plot
[316]
Lib
[318]
Import Style and Then, We're Going to Say Styled I use
[322]
Gg Plot so [it's] Just to plot stuff this Is how to Make it Look decent [This] Is how to specify Which
[329]
Decent Looking Thing you want so now
[333]
What we're Going to Say Is we're Come Down?
[338]
[We'll] Just Come Down Here and we're Going to say df
[342]
Forecast
[345]
Equals nP [and] This Just Specifies That that entire Column is Just
[349]
Full of Not a Number Data and you'll see why in a moment but We'll Actually put some Information there Shortly
[356]
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
[362]
Is how we're Going to Actually Plot this on on the the graph so to Say Last Date
[369]
Equals df [Kyle] [Oak]
[371]
Whoops
[373]
Negative 1 so this is the very Last, Date We'll get the name of that and then
[377]
We're Going to Say the last unix Value Is equal to last date Time Stamp and
[383]
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
[391]
86,400 and then the next unix
[394]
Would Be like the next day Right and These are We know These are Daily Prices so we're Just Going to
[399]
We're Kind of Hard Coding this part it just so we Can create a graph but Last unix plus one day
[405]
So when you do a Prediction the Prediction has no idea like what
[410]
Date that Is that's like [Four] all right so remember
[417]
When you're doing machine Learning [x] and y Does not Correspond to like
[422]
Necessarily the Axes on a graph in This case it doesn't x or the Features
[427]
[Y] is the label it Just so happens the label is the Price so [y] it is correct
[432]
What is x correct no because the Date Is not a feature so that's that's why?
[437]
We're Kind of Having to Work Around here Because?
[440]
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
[445]
Next [unix], okay so now we've got the Dates and Now we need to actually Populate the
[451]
Data Frame With the the new Dates and
[455]
The forecast values so the way, we're going to do that Is we're Going to Say for I in
[460]
Forecast Set
[462]
next date Equals [date] Time Date Time dot from [Timestamp]
[470]
Next
[473]
Unix and
[474]
then We're Just going to Say next unix, plus Equals That value of one day so one Day and
[481]
Then Df Dot Loke
[485]
[and] then next date Whoops next Date
[490]
Equals and then, we're Going to, do like a one-Liner for loop here so we're Gonna Say [mpn] for something
[496]
We don't Care about in Range of?
[499]
The Len of df
[501]
Columns
[504]
Let's See, range Minus 1 and then plus I
[513]
So what we're Doing?
[514]
Is we're Iterating Through the forecast set Taking each Forecast and day and then setting Those as the values in the Data Frame
[522]
Basically Making The Features
[525]
[The] Future Feature Is not a number okay [and]
[529]
Then The last line Just Takes all of The first Columns Sets Them to
[534]
Numbers and Then The Final Column is Whatever I is which is the Forecast in This Case?
[541]
so now, we're Going to go ahead and do Is
[545]
We're Going to say df
[549]
Adj dot Close
[552]
Dot Plot and then, we're Going to say df
[556]
Forecast
[557]
for Cast
[559]
Dot Plot and Then
[561]
We're Going to do plt legend we'll put that in The Fourth [Location] that's Just like the Bottom right and then
[568]
We're Gonna Say [Pl] [Tx] label
[571]
And we'll Say that's the date plt Dot Y Label that is your?
[578]
Price and Then Finally plt - oh, okay, [so] we Zoom Through that Hopefully that for Loop is going to Work out
[587]
[We'll] find out Shortly?
[588]
See, i've got a graph Here yes
[591]
[ok] so this is our actual Graph of the Data Pull this Up and
[595]
As you can See this Is this is the known Data Here and Then
[599]
Over [Here] is our Predicted Data so Let me Zoom [Into] [That] spot
[604]
Right so this is like the future Prediction here the forecast, [okay]?
[609]
Um so it's just like a really quick way to visualize the Data and Really the Complex Part the Reason why
[616]
We had All This Nasty to Crap in Here was Just Simply so you Can Have Dates on the Axes?
[623]
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
[631]
The Data and [Actually] do a Prediction but the Crux of doing a Prediction With Scikit-Learn Is
[638]
Right
[640]
Here and
[641]
Just Remember you Can Pass a single value or you could Pass an Array [of] values and it will Just
[647]
Output in The Same order The Array of values and Then from There
[650]
We [just] used Logic to know that each Because each investment Is a day writer each Price Report was it One day?
[657]
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?
[666]
so Anyway
[668]
and i guess the other Thing to think About DFl Oak Just in Case I'm not Sure We ever Actually covered that in
[674]
Pandas But What Happens There is Basically dot [Lok] is going to be Referencing the
[679]
Index for the Data Frame so when you do [df] [not] Lok, next date Basically what that's Saying
[685]
Is that next date is a date Stamp right and that next day Is um
[692]
the
[695]
Index of the Data Frame so Maybe it Would Help Just
[701]
Let's See print do you have to [ahead] so if You're not if You're not
[703]
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
[708]
That for Loop I just want to explain that for loop Just so everyone. No, One's like what the hell
[713]
So Anyways so yeah so here [write] the date Is the Index so when We Say [DFx] Date?
[719]
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
[725]
Okay, then, we're Saying [npm] for underscore in Range lang df Columns Minus, One What the heck Is that?
[734]
What that [is] Is Just A list of Values [that] [are] Mp nan so Basically
[739]
We're Saying it's Mp nan for a just a high percent Change but all this stuff is Just
[743]
Not a number right Because this is Into the future, We don't have Information on that Data okay then?
[750]
Coming Back Down Here then, we're Saying plus I
[753]
Remember I is the forecast right Right I in forecast set so then
[757]
We're Just Saying so basically Is Just this list plus one Value so it's like this Huge List
[763]
Well not Huge it's Just These this Many, Columns right, well then
[766]
We just Add forecasts at the very end so that's Just our super Hacky way of?
[771]
Doing the Following I said to head There but Probably Would've Been More Useful to Say Tail and
[775]
so you can see the end of this Data Frame
[780]
How yet These are all Those np Nan's and then Finally Just [forecasts] okay so that's all that Is
[787]
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
[793]
It now
[794]
Then There's Actually One More Thing I want to show you all before
[798]
We dive Into Regression and Actually Write a regression Algorithm all on our Own and that's Pickling and the Reason why?
[805]
You'd want to Pickle is imagine you have rather than Training a classifier on this you know Relatively Small Data set
[812]
We just Had Daily values for the last few Years?
[815]
But you Know if you save this to a file you know it's Probably like you know 500 Kilobytes Or something who knows
[820]
But let's Say you!
[820]
Had Like Intraday Data and You've Got like Two gigabytes Worth of Data that's going to take a while to
[826]
Train The Classifier on that Data, so wouldn't it be Nice if Every Time you wanted to Make a prediction so just Consider
[834]
Making a Prediction using future Data
[837]
Consider Every Time you wanted to Make a Prediction that you Would have to train the Classifier Is that not Just
[843]
Crazy Sounding so yes That's Crazy Sounding so in the next tutorial
[847]
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
[854]
so Definitely very
[856]
Useful With Machine Learning
[858]
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?
[863]
All the support and Subscriptions and until next Time
Most Recent Videos:
You can go back to the homepage right here: Homepage





