AI/ML perfplot for performance Plotting
perfplot extends Python's timeit by testing snippets with input parameters (e.g., the size of an array) and plotting the results. This has also option for live update to the ui.
The code is like below
import perfplot, string
np.random.seed(123)
def shape(df):
return df[df.education == 'a'].shape[0]
def len_df(df):
return len(df[df['education'] == 'a'])
def query_count(df):
return df.query('education == "a"').education.count()
def sum_mask(df):
return (df.education == 'a').sum()
def sum_mask_numpy(df):
return (df.education.values == 'a').sum()
def make_df(n):
L = list(string.ascii_letters)
df = pd.DataFrame(np.random.choice(L, size=n), columns=['education'])
return df
perfplot.show(
setup=make_df,
kernels=[shape, len_df, query_count, sum_mask, sum_mask_numpy],
n_range=[2**k for k in range(2, 25)],
logx=True,
logy=True,
equality_check=False,
xlabel='len(df)')
References:
https://stackoverflow.com/questions/35277075/python-pandas-counting-the-occurrences-of-a-specific-value
https://pypi.org/project/perfplot/
No comments:
Post a Comment