Forecasting API: An Example with Django and Google Trends | by Davide Burba | Aug, 2023

Build a web application to predict the evolution of Google Trends.

Davide Burba

Towards Data Science

Image by Myriams-Fotos from Pixabay

What is Django?

Django is a high-level Python web framework. It’s designed to be fast, secure, and scalable, making it a popular choice for developing robust web applications that are expected to grow in complexity. For an introduction to Django, you can check this tutorial.

In this example we are going to use Django Rest Framework (DRF), which is an extension of Django that facilitates the development of REST APIs. For an introduction to DRF, you can check this tutorial.


We’ll start to design our application by listing out some hypothetical requirements:

  • Overall goal: Implement a system to forecast future time-series values.
  • Data: Google Trends at weekly frequency for both features and targets, likely to be extended in the future. Data should be downloaded on demand.
  • Preprocessing: Use only lagged values.
  • ML Model: A global LightGBM model (check this article if you want to know more about global vs local models).
  • Inference: Generate online predictions (as opposed to batch ones), but without having to provide input features.

The complete code used in this tutorial is available here.

Set up the Environment

Let’s start by listing the needed dependencies.

python = "^3.8"
Django = "^4.2.1"
lightgbm = "^3.3.5"
pandas = "^2.0.1"
djangorestframework = "^3.14.0"
pytrends = "^4.9.2"
drf-extensions = "^0.7.1"

We are gonna use poetry to manage the dependencies, and Docker to containerize the project. You can check poetry and docker files used in this project here.


Source link

Leave a Comment