<jupyter_start><jupyter_text>Let's quickly check out our data.<jupyter_code>import pandas as pd
# https://www.kaggle.com/olistbr/brazilian-ecommerce?select=olist_geolocation_dataset.csv
orders = pd.read_csv('../dynamic_pricing/olist/olist_orders_dataset.csv')
orders.head()
order_list = pd.read_csv('../dynamic_pricing/olist/olist_order_items_dataset.csv')
order_list.head()
order_list.loc[order_list.product_id == 'e44f675b60b3a3a2453ec36421e06f0f']
order_list.product_id.value_counts()
olg = order_list[['product_id', 'price','order_id']].groupby(['product_id', 'price']).count().sort_values('order_id', ascending=False).reset_index() #.reset_index().sort_values('order_id', ascending=False)
olg.columns = ['product_id', 'price','orders']
olg.head(50)
olg.loc[olg.product_id == 'aca2eb7d00ea1a7b8ebd4e68314663af']
olg.product_id.value_counts()
olg.loc[olg.product_id == '437c05a395e9e47f9762e677a7068ce7']
olg[['price','orders']].loc[(olg.product_id == '437c05a395e9e47f9762e677a7068ce7') & (olg.orders > 4)].plot.scatter(x='price',y='orders')
products = pd.read_csv('../dynamic_pricing/olist/olist_products_dataset.csv')
nms = pd.read_csv('../dynamic_pricing/olist/product_category_name_translation.csv')
products = products.merge(nms, on='product_category_name')
products.head()
mpol = olg.merge(products[['product_id', 'product_category_name_english']], on='product_id')
mpol.head()
# mpol.to_csv('merged.csv', index=False)
mpol[['price', 'orders', 'product_category_name_english']].groupby('product_category_name_english').describe()
mpol.product_category_name_english.value_counts()
mpol.loc[(mpol.product_category_name_english == 'bed_bath_table') & (mpol.price < 250)].hist(column='price')
a = mpol.loc[(mpol['product_category_name_english'] == 'bed_bath_table') & (mpol.price <= 300) & (mpol.orders >= 2)][['product_id']].value_counts().reset_index()
a.columns = ['prod', 'cnt']
a.loc[a['cnt'] > 2]<jupyter_output><empty_output><jupyter_text>Pick one Item to run through the Demand Model Build<jupyter_code>samp = mpol.loc[mpol.product_id == '2a2d22ae30e026f1893083c8405ca522']
samp
olg[['price','orders']].loc[(olg.product_id == '2a2d22ae30e026f1893083c8405ca522') & (olg.orders >= 2)].plot.scatter(x='price',y='orders')
import numpy as np

X = samp[['price']].to_numpy()
y = samp[['orders']].to_numpy()
nm = np.dot(np.dot(np.linalg.inv(np.dot(X.T, X)), X.T), y)
nm
samp = olg[['price','orders']].loc[(olg.product_id == '2a2d22ae30e026f1893083c8405ca522') & (olg.orders >= 2)]
X = np.array(list(samp['price']))
X = np.vstack([X, np.ones(len(X))]).T
y = np.array(list(samp['orders']))
X
# y = mx + c,
m, c = np.linalg.lstsq(X, y, rcond=None)[0]
m, c
nm
import matplotlib.pyplot as plt
plt.plot(X[:,0], y, 'o', label='Original data', markersize=10)
plt.plot(X[:,0], m*X[:,0] + c, 'r', label='Fitted line')
plt.legend()
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19490934449093444, 'fraction_numerical': 0.0596234309623431, 'mean_word_length': 8.314935064935066, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 14, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '657270', 'license': 'MIT', 'n_tokens_mistral': 1281, 'n_tokens_neox': 1180, 'n_words': 146, 'path': 'eda.ipynb', 'repo_name': 'samroon2/dynamic_pricing_and_demand', 'size': '2868'}