Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add vs pandas notebook #3

Closed
raybellwaves opened this issue Sep 27, 2020 · 1 comment
Closed

add vs pandas notebook #3

raybellwaves opened this issue Sep 27, 2020 · 1 comment

Comments

@raybellwaves
Copy link
Owner

import xarray as xr
import pandas as pd
import numpy as np
import xskillscore as xs
from sklearn.metrics import mean_squared_error

stores = np.arange(100)
skus = np.arange(100)
dates = pd.date_range("1/1/2020", "1/10/2020", freq="D")

rows = []
for _, date in enumerate(dates):
    for _, store in enumerate(stores):
        for _, sku in enumerate(skus):
            rows.append(
                dict(
                    {
                        "DATE": date,
                        "STORE": store,
                        "SKU": sku,
                        "QUANTITY_SOLD": np.random.randint(9) + 1,
                    }
                )
            )
df = pd.DataFrame(rows)
df.rename(columns={"QUANTITY_SOLD": "y"}, inplace=True)
df.set_index(['DATE', 'STORE', 'SKU'], inplace=True)
noise = np.random.uniform(-1, 1, size=len(df['y']))
df['yhat'] = (df['y'] + (df['y'] * noise)).astype(int)

df.groupby(['STORE', 'SKU']).apply(lambda x: mean_squared_error(x.y, x.yhat))

ds = df.to_xarray()
ds.xs.mse('y', 'yhat', 'DATE')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant