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
# Helper functions | |
def tree(dir_path: Path, prefix: str = ''): | |
"""A recursive generator, given a directory Path object | |
will yield a visual tree structure line by line | |
with each line prefixed by the same characters | |
""" | |
contents = list(dir_path.iterdir()) | |
# contents each get pointers that are ├── with a final └── : | |
pointers = [tee] * (len(contents) - 1) + [last] |
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
assert df.isna().sum().sum() == 0 | |
total_sales_5_days_rolling_window = df.groupby(['product','date']).sales.sum().rolling(5, min_periods=0).agg(['min','max','mean','sum']).add_prefix('country_sales_rolling_5_') | |
df = df.merge(total_sales_5_days_rolling_window, on=['product','date'], how='left') |
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
{ | |
"instances": [ | |
{ | |
"start": "2011-11-01 00:00:00", | |
"target": [5.0, 9.0, "NaN", 100.0, 113.0], | |
"cat": [0, 1], | |
"dynamic_feat": [[1.0, 1.1, 2.1, 0.5, 3.1, 4.1, 1.2, 5.0]] | |
}, | |
{ | |
"start": "2022-01-30", |
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.py file ### | |
# Packages needed for all 10 features in the article | |
import yaml | |
import streamlit as st | |
import contextlib | |
import os | |
import subprocess | |
import sys |
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
# Helper functions | |
def get_jupyter_configs(file_name=None): | |
if file_name == None: | |
file_name = os.path.expanduser(os.path.join(("~"), ".jupyter", "jupyter_notebook_config.py")) | |
with open(file_name) as f: | |
lines = f.readlines() | |
relevant_lines = [line.replace("\n", "") for line in lines if | |
not line.lstrip().startswith("#") and not line == '\n'] |
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
# Helper functions | |
def data_preprocess(state, process_table_sidebar): | |
autosave_session(state) | |
st.title("Data Preprocess") | |
... | |
def training(state, process_table_sidebar): | |
autosave_session(state) | |
st.title("Train Model") | |
... | |
... # evaluation, prediction, save_and_load, free_coding, deployment |
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
# Helper fucntions | |
def is_authenticated(user, password): | |
if (user == 'Admin' and password == "12345678"): | |
return True | |
else: | |
return False | |
def linespace_generator(n_spaces=1): | |
for i in range(n_spaces): | |
st.write("") |
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
# Helper functions | |
def models_table(files_in_dir=None, models_dir=configs['MODELS_DIR'], use_models_dir=True): | |
if use_models_dir is False: | |
models_dir = os.getcwd() | |
if files_in_dir is None: | |
files_in_dir = os.listdir(models_dir) | |
if ".gitignore" in files_in_dir: | |
files_in_dir.remove(".gitignore") | |
file_modified_time = [ |
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
# Helper functions | |
def last_changed_file(dir_path=None, ends_with="", report_error=True): | |
try: | |
if dir_path is None: | |
dir_path = os.getcwd() | |
list_of_files = glob.glob(dir_path + '/*') | |
if len(ends_with) > 0: | |
list_of_files = [file for file in list_of_files if file.endswith(ends_with)] | |
try: |
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
# Helper functions | |
def now_string(seconds=False, microsec=False, only_date=False, log_timestamp=False): | |
now = datetime.datetime.now() | |
if log_timestamp: | |
return str(now.day) + "-" + str(now.month) + "-" + str(now.year) + ' ' + str(now.hour) + ":" + str( | |
now.minute) + ":" + str(now.second) + "." + str(now.microsecond)[:2] + " ~~ " | |
if only_date: | |
return str(now.day) + "_" + str(now.month) + "_" + str(now.year) | |
now_str = str(now.day) + "_" + str(now.month) + "_" + str(now.year) + '_' + str(now.hour) + "_" + str(now.minute) |
NewerOlder