TIM Edge - example notebook

This notebook illustrates how to use the TIM Edge REST API with a simple example. A model is uploaded, a forecast is run with the uploaded model, its status and logs are checked and results are retrieved. Finally, the notebook shows how to visualize the dataset and evaluate the calculated forecast.

In [1]:
import os, requests, json
import pandas as pd
import plotly as plt
import plotly.express as px
import plotly.graph_objects as go
from io import StringIO

Resources and definitions

In [2]:
api_url = 'http://localhost:8079'
headers = {}

def pretty_print(json_object):
    print(json.dumps(json_object, indent=2))

dataset = {
    'name': 'data',
    'path': os.path.join(os.getcwd(), 'data.csv'),
    'timestamp_format': 'yyyy-mm-dd HH:MM:SS',
    'decimal_separator': '.',
    'csv_separator': ';'
}

model = {
    'name': 'model',
    'path': os.path.join(os.getcwd(), 'model.json'),
}

Dataset visualization

The following dataset contains several predictors as well as electricity load (Load) as target variable that should be forecasted.

In [3]:
pd_data = pd.read_csv(dataset['path'], delimiter=dataset['csv_separator'])
nrow, ncol = pd_data.shape
cols = pd_data.columns

fig = plt.subplots.make_subplots(rows=2, cols=1, shared_xaxes=True, vertical_spacing=0.02)
fig.add_trace(go.Scatter(x=pd_data.loc[:, cols[0]], y=pd_data.loc[:, cols[1]], name=cols[1]), row=1, col=1)

for col in cols[2:ncol]:
    fig.add_trace(go.Scatter(x=pd_data.loc[:, cols[0]], y=pd_data.loc[:, col], name=col), row=2, col=1)

fig.update_layout(height=700, width=1000, title_text="Data visualization")

fig.show()