Kaggle competition: M5 Forecasting - Accuracy
linear_reg_pred = linear_reg.predict(x_test )<train_on_grid>
submission = pd.read_csv('/kaggle/input/local-submission-files-m5/submission_46.csv' )
ridge = Ridge()
parameters = {'alpha' : [1,2]}
rid = GridSearchCV(ridge,param_grid = parameters, cv=kfold, scoring= sklearn.metrics.make_scorer(mean_squared_log_error), n_jobs= -1, verbose = 1)
 rid.fit(x_train,y_train)
 print(math.sqrt(rid.best_score_))
print(rid.best_params_ )<find_best_params>
sales = pd.read_csv(f'/kaggle/input/m5-forecasting-accuracy/sales_train_validation.csv')
 ids = sorted(list(set(sales['id'])))
 d_cols = [f'd_{x}' for x in range(1258,1914)]
rid_best = rid.best_estimator_<compute_test_metric>
def calc_coef(x,y, alpha):
y = np.mean(y, axis = 0)
 slope, intercept, r_value, p_value, std_err = stats.linregress(x,y)
 line = slope*x+intercept
return 1 +(slope*y.shape[0]/alpha )
print('R-squared value for ridge regression on train data is ', r2_score(y_train,rid_best.predict(x_train)) )<predict_on_test>
stores = ['CA_1', 'CA_2', 'CA_3', 'CA_4', 'TX_1', 'TX_2', 'TX_3', 'WI_1', 'WI_2', 'WI_3']
for store in stores:
submission.loc[submission['id'].str.contains(store), [f'F{x}' for x in range(1,29)]] *= coefs[store]
<train_on_grid><EOS> 
submission.to_csv('submission.csv', index = False )