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
# Interesting way of calling pip from inside python | |
# Source: https://colab.research.google.com/github/cleanlab/cleanlab-docs/blob/master/v2.4.0/tutorials/datalab/tabular.ipynb | |
if "google.colab" in str(get_ipython()): # Check if it's running in Google Colab | |
%pip install cleanlab==v2.4.0 | |
cmd = ' '.join([dep for dep in dependencies if dep != "cleanlab"]) | |
%pip install $cmd |
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 typing import List | |
import matplotlib.pyplot as plt | |
import pandas as pd | |
import numpy as np | |
from memory_profiler import memory_usage | |
from multiprocessing import Pool, cpu_count | |
import gc | |
def mem_inline(function, *arg) -> float: | |
return memory_usage(proc=(function, arg), max_usage=True)#[0] |
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 typing import List | |
import matplotlib.pyplot as plt | |
import pandas as pd | |
import numpy as np | |
from timeit import repeat | |
from multiprocessing import Pool, cpu_count | |
def time_inline(function: str, *arg) -> float: | |
stmt = f'{function}(*{arg})' | |
return min(repeat(stmt, repeat=5, number=1, globals=globals())) |
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 math import log | |
def abbreviate(value, base=1000, precision=2, suffixes=None): | |
if suffixes is None: | |
suffixes = ['', 'K', 'M', 'B', 'T'] | |
if value == 0: | |
return f'{0}{suffixes[0]}' |