text_html_output_1.png text_plain_output_1.png
from sklearn.metrics import mean_absolute_error

import pandas as pd

train = pd.read_csv('../input/tabular-playground-series-mar-2022/train.csv', parse_dates=['time'])
train['hour'] = train['time'].dt.hour
train['minute'] = train['time'].dt.minute
submission_in = pd.read_csv('../input/tabular-playground-march-2022-04/lightautoml_rounded_special_ve_37_v2.csv')
sep = train[(train.time.dt.hour >= 12) & (train.time.dt.weekday < 5) & (train.time.dt.dayofyear >= 246)]
lower = sep.groupby(['hour', 'minute', 'x', 'y', 'direction']).congestion.quantile(0.2).values
upper = sep.groupby(['hour', 'minute', 'x', 'y', 'direction']).congestion.quantile(0.65).values
submission_out = submission_in.copy()
submission_out['congestion'] = submission_in.congestion.clip(lower, upper)
submission_out.to_csv('submission.csv', index=False)
mae = mean_absolute_error(submission_in.congestion, submission_out.congestion)
print(f'Mean absolute modification: {mae:.4f}')
print(f'Submission was below lower bound: {(submission_in.congestion < lower - 0.5).sum()}')
print(f'Submission was above upper bound: {(submission_in.congestion > upper + 0.5).sum()}')
submission_out