Strategy | Cross-validation set | Test set | Forecast |
---|---|---|---|
Direct | 14.302 | 8.378 | 13.124 |
Recursive | 14.302 | 8.378 | 16.471 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
from anytree.search import findall | |
def find_by_keyword(self, keyword) -> Node: | |
""" | |
Find the node whose regex matches the keyword given as input | |
""" | |
def match_regex(node): | |
has_regex = hasattr(node, "regex") and node.regex is not None | |
if has_regex: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from anytree.exporter import DotExporter | |
COLOR_SCHEME = ["aliceblue", "antiquewhite", "azure", "coral", "palegreen"] | |
def export(self): | |
""" | |
Export tree into graphviz format in both *.dot file and image *.png file | |
""" | |
def nodeattr_fn(node): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from anytree import Node, RenderTree | |
from anytree.search import find | |
class TaxonomyParser: | |
""" | |
This class is a wrapper on a Tree class from the anytree library to hold | |
different data hierarchies read from a JSON representation | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"L0": [ | |
{ "name": "device" } | |
], | |
"L1": [ | |
{ "name": "Networking", "parent": "Device" }, | |
{ "name": "Computer", "parent": "Device" } | |
], | |
"L2": [ | |
{ "name": "Router", "parent": "Networking" }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "Device", | |
"children": [ | |
{ | |
"name": "Networking", | |
"children": [ | |
{ "name": "Router", "children": [] }, | |
{ "name": "Switch" }, | |
{ "name": "Firewall", "children": [] } | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app = dash.Dash(__name__) | |
app.layout = html.Div(children=[ | |
html.Div(dcc.Markdown(description)), | |
html.Hr(), | |
html.Div([ | |
html.Div(id="parameters-box-id", children=[ | |
dcc.Markdown(params_description), | |
dcc.Input( | |
id="tottime-input-id", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def direct_forecast(y, model, lags, | |
n_steps=FCAST_STEPS, step="1H"): | |
""" | |
Parameters | |
---------- | |
y: pd.Series holding the input time-series to forecast | |
model: a ML model not trained | |
lags: list of lags used for training the model | |
n_steps: how many steps forecast into the future |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def recursive_forecast(y, model, lags, | |
n_steps=FCAST_STEPS, step="1H"): | |
""" | |
Parameters | |
---------- | |
y: pd.Series holding the input time-series to forecast | |
model: pre-trained machine learning model | |
lags: list of lags used for training the model | |
n_steps: number of time periods in the forecasting horizon |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from sklearn.preprocessing import StandardScaler | |
from statsmodels.tsa.stattools import pacf | |
def create_lag_features(y): | |
scaler = StandardScaler() | |
features = pd.DataFrame() | |
partial = pd.Series(data=pacf(y, nlags=48)) |