text_plain_output_1.png
import matplotlib.pyplot as plt

import pandas as pd

from pathlib import Path
import datetime as dt
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn import metrics
plt.style.use('ggplot')
plt.rcParams['figure.figsize'] = (10, 10)

class CFG:
    n_roadways = 65
    seed = 42
def create_roadways(df):
    roads = list(range(CFG.n_roadways))
    return roads * int(len(df) / CFG.n_roadways)
def preprocess(df):
    df_ = df.copy()
    df_['roadway'] = create_roadways(df_)
    df_['time'] = pd.to_datetime(df_['time'])
    return df_

train = pd.read_csv(PATH / 'train.csv')
train = preprocess(train)
test = pd.read_csv(PATH / 'test.csv')
test = preprocess(test)
train

df_roadway = train[train['roadway'] == 0].reset_index(drop=True)

ax = train.groupby('direction')['congestion'].mean().plot.bar()
ax.bar_label(ax.containers[0])
plt.xticks(rotation=0);

df_sub = test[['row_id', 'roadway']].copy()
preds_test = train.groupby('roadway')['congestion'].median().rename('congestion').reset_index().round(0).astype(int)
df_sub = df_sub.merge(preds_test, on='roadway', how='left')
df_sub