application_vnd.jupyter.stderr_output_1.png
import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

import random

import seaborn as sns

import tensorboard as tb

import tensorflow as tf

import torch

import copy
from pathlib import Path
import warnings
import holidays
import seaborn as sns
import matplotlib
import matplotlib.dates as mdates
import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')
import numpy as np
import pandas as pd
import pytorch_lightning as pl
from pytorch_lightning.callbacks import EarlyStopping, LearningRateMonitor
from pytorch_lightning.loggers import TensorBoardLogger
import torch
DEVICE = 'cuda' if torch.cuda.is_available() else 'cpu'
from pytorch_forecasting import Baseline, TemporalFusionTransformer, TimeSeriesDataSet
from pytorch_forecasting.data import GroupNormalizer, NaNLabelEncoder
from pytorch_forecasting.metrics import SMAPE, PoissonLoss, QuantileLoss
from pytorch_forecasting.models.temporal_fusion_transformer.tuning import optimize_hyperparameters
import random
import tensorflow as tf
import tensorboard as tb
tf.io.gfile = tb.compat.tensorflow_stub.io.gfile
random.seed(30)
np.random.seed(30)
tf.random.set_seed(30)
torch.manual_seed(30)
torch.cuda.manual_seed(30)

train = pd.read_csv('/kaggle/input/tabular-playground-series-sep-2022/train.csv')
test = pd.read_csv('/kaggle/input/tabular-playground-series-sep-2022/test.csv')
train['date'] = pd.to_datetime(train['date'])
test['date'] = pd.to_datetime(test['date'])
data = pd.concat([train, test], axis=0, ignore_index=True)
assert len(data.drop_duplicates(['country', 'store', 'product', 'date'])) == len(data)
assert len(data.drop_duplicates(['country', 'store', 'product'])) == len(data) // data['date'].nunique()

train.isna().sum(axis=0).rename('nans_per_column_train').rename_axis('column').reset_index().set_index('column').join(test.isna().sum(axis=0).rename('nans_per_column_test').rename_axis('column').reset_index().set_index('column'))

train.nunique(axis=0).rename('n_unique_per_column_train').rename_axis('column').reset_index().set_index('column').join(test.nunique(axis=0).rename('n_unique_per_column_test').rename_axis('column').reset_index().set_index('column'))

fig, ax = plt.subplots(1,1, figsize=(20, 6))

sns.kdeplot(data=train, x = 'num_sold', hue = 'country', fill=True, alpha = 0.15, ax = ax, linewidth=3, palette='pastel')
ax.set_xlabel('num_sold', color='black', fontweight='bold', fontsize=13)
ax.set_ylabel('density', color='black', fontweight='bold', fontsize=13)
ax.set_xlim(0, 700)
ax.xaxis.set_tick_params(labelsize=15)
ax.yaxis.set_ticklabels([])
ax.set_title('Density plot for num_sold per country (clipped at 700)', fontweight = 'bold', fontsize = 20);

fig, ax = plt.subplots(1, 1, figsize=(20, 6))
sns.kdeplot(data=train, x='num_sold', hue='store', fill=True, alpha=0.15, ax=ax, linewidth=2.5)
ax.set_xlabel('num_sold', color='black', fontweight='bold', fontsize=13)
ax.set_ylabel('density', color='black', fontweight='bold', fontsize=13)
ax.set_xlim(0, 700)
ax.set_title('Density plot for num_sold per store (clipped at 700)', fontweight='bold', fontsize=20)
ax.xaxis.set_tick_params(labelsize=15)
ax.yaxis.set_ticklabels([])