-
Notifications
You must be signed in to change notification settings - Fork 518
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
...a Science - Time Series/03.Time Series Analysis/06.Forecasting with Linear Regression.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/************ Forecasting with Linear Regression **************/ | ||
|
||
/* | ||
so far, we have been working with past data. | ||
Now we want to make future predictions based on those past data using Linear Regression. | ||
y=mx + b | ||
m: slope | ||
b: y intercept | ||
y: predicted value | ||
x: input value | ||
Let's try and predict the amount of free memory will be available given a particular CPU utilization. | ||
*/ | ||
|
||
-- first we will find m and b values : m = -0.46684018640161745, b = 0.6664934543856621 | ||
SELECT | ||
REGR_SLOPE(free_memory, cpu_utilization) AS m, | ||
REGR_INTERCEPT(free_memory, cpu_utilization) AS b | ||
FROM time_series.utilization | ||
WHERE event_time BETWEEN '2019-03-05' AND '2019-03-06'; | ||
|
||
|
||
-- let's say we want to predict free memory based on 65% CPU utilization | ||
-- we predicted 0.36304733322461075 (about 36% of free memory) | ||
SELECT | ||
REGR_SLOPE(free_memory, cpu_utilization) * 0.65 + | ||
REGR_INTERCEPT(free_memory, cpu_utilization) AS b | ||
FROM time_series.utilization | ||
WHERE event_time BETWEEN '2019-03-05' AND '2019-03-06'; | ||
|
||
|
||
|
||
|
||
|