Skip to content

Commit 5ecc760

Browse files
committed
forecasting with linear regression
1 parent 3516113 commit 5ecc760

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/************ Forecasting with Linear Regression **************/
2+
3+
/*
4+
5+
so far, we have been working with past data.
6+
Now we want to make future predictions based on those past data using Linear Regression.
7+
8+
y=mx + b
9+
m: slope
10+
b: y intercept
11+
y: predicted value
12+
x: input value
13+
14+
Let's try and predict the amount of free memory will be available given a particular CPU utilization.
15+
*/
16+
17+
-- first we will find m and b values : m = -0.46684018640161745, b = 0.6664934543856621
18+
SELECT
19+
REGR_SLOPE(free_memory, cpu_utilization) AS m,
20+
REGR_INTERCEPT(free_memory, cpu_utilization) AS b
21+
FROM time_series.utilization
22+
WHERE event_time BETWEEN '2019-03-05' AND '2019-03-06';
23+
24+
25+
-- let's say we want to predict free memory based on 65% CPU utilization
26+
-- we predicted 0.36304733322461075 (about 36% of free memory)
27+
SELECT
28+
REGR_SLOPE(free_memory, cpu_utilization) * 0.65 +
29+
REGR_INTERCEPT(free_memory, cpu_utilization) AS b
30+
FROM time_series.utilization
31+
WHERE event_time BETWEEN '2019-03-05' AND '2019-03-06';
32+
33+
34+
35+
36+

0 commit comments

Comments
 (0)