<jupyter_start><jupyter_text>Table of Contents Forecasting Demand for Optimized Inventory Planning ImportsSimple processingTrain/test splitSimple xgboost  Forecasting Demand for Optimized Inventory Planning   Imports<jupyter_code>import pandas as pd
import numpy as np
pd.set_option('display.max_columns', 50)

import matplotlib.pyplot as plt
%matplotlib inline
plt.rcParams['figure.figsize'] = (10.0, 8.0) # set default size of plots
import seaborn as sns
sns.set()<jupyter_output><empty_output><jupyter_text>The 2 cells below can be skipped if not wanted<jupyter_code>%%javascript
$('#menubar').toggle();
# This is optional and can be skipped if not installed
%load_ext autoreload
%autoreload 2
import sys
sys.path.append("../main")

from utils import read_data, process_time, merge_data
infos, items, orders = read_data()<jupyter_output><empty_output><jupyter_text>**OBS:** This time processing is different than Tobias; I consider the **two** last weeks, he considers just the last **one** week<jupyter_code>process_time(orders)<jupyter_output><empty_output><jupyter_text>Simple processing<jupyter_code>orders.head()
aggs = {"order": "sum", "salesPrice": "mean"}
df = orders.groupby(["group_backwards", "itemID"],
                    as_index=False).agg(aggs)
df.rename(columns={x: x+"_"+y for x, y in aggs.items()}, inplace=True)
df.head()
df = merge_data(df, items, infos)
df.head()
# Remove some columns..,
# we could prob use simulationPrice, but lets not for now
data = df.drop(columns=["promotion", "itemID", "simulationPrice"])
data.set_index("group_backwards", inplace=True)
data.sort_index(inplace=True)<jupyter_output><empty_output><jupyter_text>Train/test split<jupyter_code>train = data.loc[2:]
x_train = train.drop(columns="order_sum")
y_train = train["order_sum"]

test = data.loc[1]
x_test = test.drop(columns="order_sum")
y_test = test["order_sum"]
y_train.sum(), y_test.sum()
x_train.shape, x_test.shape<jupyter_output><empty_output><jupyter_text>Simple xgboost<jupyter_code>import xgboost as xgb
dtrain = xgb.DMatrix(x_train, y_train)
dtest = xgb.DMatrix(x_test, y_test)
# specify parameters via map
#param = {'max_depth':2, 'eta':0.3, 'objective': 'reg:squarederror'}
param = {'objective': 'reg:squarederror'}
num_round = 100
bst = xgb.train(param, dtrain,
                num_round, early_stopping_rounds=5,
                evals = [(dtrain, 'train'), (dtest, 'test')])
y_train.std(), y_test.std()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.135046919624643, 'fraction_numerical': 0.0073439412484700125, 'mean_word_length': 6.544615384615384, 'pattern_counts': {'":': 2, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '292630', 'license': 'MIT', 'n_tokens_mistral': 886, 'n_tokens_neox': 854, 'n_words': 201, 'path': 'bruno/1.1-First Model.ipynb', 'repo_name': 'joaopedromattos/DMC2020', 'size': '2451'}