Giter VIP home page Giter VIP logo

redis-kats's Introduction

Description

Implement some TimeSeries Analysis using the serverless engine RedisGears, Redis TimeSeries and Facebook Kats as toolkit to analyze time series data.

It shows how to:

  • build a custom Redis docker image with given modules
  • generate timeseries mocked data using Kats from an external python process
  • define a RedisGears function to perform timeseries forecasting using Kats
  • load RedisGears function from an external python process
  • fetch the predictions from a (java) Spring Boot client invoking the RedisGears function

Jupiter notebook provided, containing the Kats logic used in the project: here.

Preparing the environment

Run Redis

Build docker image

docker-compose up # --build # First Time

Manually install dependencies in RedisGears venv

๐Ÿ˜ฃ Struggled a lot trying to install KATS to be run in RedisGears venv.
The only way I was able to make it work was manually installing dependencies. :( See RedisGears Configuration

$ docker ps # Get process id
$ docker exec -ti <id> /bin/bash
# activate rg venv
$ source /var/opt/redislabs/modules/rg/.venv-/bin/activate
$ ln -s /usr/lib/x86_64-linux-gnu/libffi.so.7 /usr/lib/x86_64-linux-gnu/libffi.so.6
$ pip3 install --upgrade pip
$ pip3 install --no-cache-dir setuptools
$ pip3 install numpy pandas convertdate Cython~=0.22 pystan~=2.18
$ pip3 install fbprophet==0.7.1
$ pip3 install kats

Load Mocked Data from external Python process

Kats needs to be installed on python < 3.9. Create 3.8 venv and install requirements.

Run Simulator for generating time series data.

Load Redis Gears functions (Serverless Engine in Redis)

Run the python client to load RG functions.

Watch redis server log while RG functions and dependencies installation are being loaded and requested.

RedisGears functions

Name Description
Forecaster Contains the forecasting logic using the Prophet model. Trigger: GetValuesPerDayPredictions. Input args: x[1] days to be predicted. CLI Execution: RG.TRIGGER GetValuesPerDayPredictions 10

Rest Endpoint:

Spring Boot Process offers a Rest endpoint to retrieve the predicted values for the next days.

# Get Predicted values for next 3 days
curl http://localhost:8080/3
[{"t":1640995200000,"v":6068.410402495052},{"t":1641081600000,"v":5706.191453574134},{"t":1641168000000,"v":5617.7999465757375}]

The Prophet Model needs to be trained to provide accurate results

redis-kats's People

Contributors

oalles avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.