[1]:
# Import to be able to import python package from src
import sys
sys.path.insert(0, '../src')
[2]:
import ontime as on
import pandas as pd
The `LightGBM` module could not be imported. To enable LightGBM support in Darts, follow the detailed instructions in the installation guide: https://github.com/unit8co/darts/blob/master/INSTALL.md
The `Prophet` module could not be imported. To enable Prophet support in Darts, follow the detailed instructions in the installation guide: https://github.com/unit8co/darts/blob/master/INSTALL.md

Getting Started#

The library is divided in three parts :

  1. core for all basic features

  2. module for all features using core features. E.g. benchmarking, ml preprocessing, etc.

  3. context for all features related to the usage of onTime in an applied scenario

core Features#

This is a low level API. Most objects and functions are accessible in the base object :

ontime
├── detectors
├── generators
├── Model
├── plots
├── processors
└── TimeSeries

For instance :

[3]:
ts = on.generators.random_walk().generate(start=pd.Timestamp('01-01-2023'), end=pd.Timestamp('12-31-2023'))
ts[0:5]
[3]:
<TimeSeries (DataArray) (time: 5, component: 1, sample: 1)>
array([[[-1.37205979]],

       [[-0.65182852]],

       [[ 0.29932213]],

       [[-0.94618418]],

       [[-0.67047005]]])
Coordinates:
  * time       (time) datetime64[ns] 2023-01-01 2023-01-02 ... 2023-01-05
  * component  (component) object 'random_walk'
Dimensions without coordinates: sample
Attributes:
    static_covariates:  None
    hierarchy:          None
[4]:
ts.plot();
_images/getting_started_5_0.png

module and context features#

High level API with various features. Let’s load some data for an example :

[5]:
from darts.datasets import EnergyDataset
ts = EnergyDataset().load()
[6]:
df = ts.pd_dataframe()
df = df.interpolate()
cols = ['generation biomass', 'generation solar', 'generation nuclear']
df = df[cols]
[7]:
ts = on.TimeSeries.from_dataframe(df)
[8]:
ts_uni = ts['generation solar'].slice(pd.Timestamp('2015'), pd.Timestamp('2016'))
ts_multi = ts.slice(pd.Timestamp('2015'), pd.Timestamp('2016'))

module Features#

High level API with features related to data processing, ML/AI, etc.

[10]:
train, test = on.module.processing.common.train_test_split(ts_uni, test_split=0.3)

context Features#

High level API with features related to a physical machine or process.

Profiler#

[11]:
profiler = on.context.common.Profiler()

What does the common week looks like ?

[12]:
week_mean = profiler.profile(ts_uni, profiler.Period.WEEKLY, profiler.Aggregation.MEAN)
week_median = profiler.profile(ts_uni, profiler.Period.WEEKLY, profiler.Aggregation.MEDIAN)
[13]:
week_mean.plot();
week_median.plot();
_images/getting_started_21_0.png

Generic Predictor#

[14]:
model = on.context.common.GenericPredictor()
[15]:
model.fit(train)
[15]:
<ontime.context.common.generic_predictor.GenericPredictor at 0x2b9906ec0>

What does the future looks like ?

[16]:
pred = model.predict(48)
[17]:
on.plots.prediction(train[-96:], pred, test[:48])
[17]:

Generic Detector#

[18]:
model = on.context.common.GenericDetector()
[19]:
model.fit(train)
[19]:
<ontime.context.common.generic_detector.GenericDetector at 0x2b98d03a0>

Does the current signal has problem ?

[20]:
detected_test = model.detect(test)
[21]:
on.plots.anomalies(test[:72], detected_test[:72])
[21]:

What if we want to have an idea about the future problems ?

[22]:
predetected = model.predetect(72)
[24]:
on.plots.anomalies(test[:72], predetected[:72])
[24]:
[ ]: