Skip to Content
Practical Predictive Analytics
book

Practical Predictive Analytics

by Ralph Winters
June 2017
Beginner to intermediate
576 pages
15h 22m
English
Packt Publishing
Content preview from Practical Predictive Analytics

Computing the EMA using a function

The following code will compute an EMA with a ratio of .8, using a lookback period of 5. The ratio of .8 will give the most weight to the most recent period, whilel still allowing the past to influence the prediction.

Then we will use cbind() to display the data point, as well as the simple and exponential moving averages:

ExpMA <- EMA(x, n = 5, ratio = 0.8)cbind(head(x, 15), head(MA, 15), head(ExpMA, 15)) >            [,1]      [,2]      [,3]>  [1,] 0.1541247        NA        NA>  [2,] 0.1574131        NA        NA>  [3,] 0.1629424        NA        NA>  [4,] 0.1609860        NA        NA>  [5,] 0.1485338 0.1568000 0.1568000>  [6,] 0.1474000 0.1554551 0.1492800>  [7,] 0.1523271 0.1544379 0.1517177>  [8,] 0.1464598 0.1511414 0.1475114>  [9,] 0.1433967 0.1476235 0.1442196> [10,] 0.1455136 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Data Superstream: Analytics Engineering

Data Superstream: Analytics Engineering

Alistair Croll, Anna Filippova, Emilie Schario, Lewis Davies, Jacob Frackson, Benn Stancil, Nick Acosta, Elizabeth Caley
R: Predictive Analysis

R: Predictive Analysis

Tony Fischetti, Eric Mayor, Rui Miguel Forte
Python: Advanced Predictive Analytics

Python: Advanced Predictive Analytics

Ashish Kumar, Joseph Babcock

Publisher Resources

ISBN: 9781785886188Supplemental Content