image_output_4.png text_plain_output_2.png text_plain_output_1.png image_output_3.png image_output_2.png image_output_1.png
import matplotlib as plt

import numpy as np # linear algebra

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

dates = pd.read_csv('/kaggle/input/m5-forecasting-accuracy/calendar.csv')
data = pd.read_csv('/kaggle/input/m5-forecasting-accuracy/sales_train_validation.csv')
sale_data = pd.read_csv('/kaggle/input/m5-forecasting-accuracy/sell_prices.csv')
submission = pd.read_csv('/kaggle/input/m5-forecasting-accuracy/sample_submission.csv')

last_date = 1913
original_features = ['id', 'item_id', 'dept_id', 'cat_id', 'store_id', 'state_id']
total_sales = data.mean()
x_data = np.array([int(x[2:]) for x in total_sales.index])
y_data = np.array(total_sales.array)
m, b = np.polyfit(x_data, y_data, 1)

state_groups = data.groupby('state_id')
state_data = state_groups.mean()
print(state_data)
x_data = range(1, last_date + 1)
for i, g in enumerate(state_groups.groups.keys()):
    y_data = [state_data['d_' + str(x)].iloc[i] for x in x_data]
    plt.pyplot.scatter(x_data, y_data, s=5, alpha=0.3)
    m, b = np.polyfit(x_data, y_data, 1)
    print('Group ' + str(i) + ':', g, 'Gradient:', m, 'Intercept:', b)
    plt.pyplot.plot([0, last_date], [b, m * last_date + b], linewidth=4, label=g)
plt.pyplot.legend(loc='upper left')