Skip to content

Instantly share code, notes, and snippets.

View dormeir999's full-sized avatar
🎯
Focusing

dormeir dormeir999

🎯
Focusing
View GitHub Profile
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')
{
"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",
@dormeir999
dormeir999 / Flask_deplyoment_ML_model_prediction.py
Last active December 24, 2021 17:04
Flask_deplyoment_ML_model_prediction
import imghdr
import sys
from io import BytesIO
import yaml
from flask import Flask, send_file
from flask_restful import reqparse, Api, Resource
import werkzeug
import os
from utils import last_changed_file
from zipfile import ZipFile
@dormeir999
dormeir999 / Stremalit_Embedding_Jupyter.py
Last active June 10, 2022 14:21
Stremalit_Embedding_Jupyter
# 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']
@dormeir999
dormeir999 / Streamlit_Dynamcially_show_training_results.py
Last active December 25, 2021 11:21
Streamlit_Dynamcially_show_training_results
# 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:
@dormeir999
dormeir999 / Streamlit_Use_models_from_different environemnts.py
Last active December 25, 2021 11:11
Streamlit_Use_models_from_different environemnts.py
# 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)
@dormeir999
dormeir999 / Streamlit_Run_long_parallel_calculations.py
Created December 20, 2021 17:16
Streamlit_Run_long_parallel_calculations
# Helper functions
def get_proc_name(proc):
try:
if "jupyter lab --allow-root" in proc.cmdline():
return "coding_bench"
return os.path.basename([line for line in proc.cmdline() if ".py" in line][0]).split(".py")[0]
except IndexError:
return ""
except psutil.NoSuchProcess:
@dormeir999
dormeir999 / Stremalit_Multi_pages.py
Created December 20, 2021 17:14
Stremalit_Multi_pages
# 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
@dormeir999
dormeir999 / Streamlit_Login_screen.py
Created December 20, 2021 17:13
Streamlit_Login_screen
# 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("")
@dormeir999
dormeir999 / Streamlit_Files_explorer.py
Last active June 19, 2024 10:46
Streamlit_Files_explorer.py
# 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]