<jupyter_start><jupyter_text>Import  Modules<jupyter_code>import sys
from datetime import timedelta, datetime
from pathlib import Path

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
from sklearn.metrics import mean_absolute_error, mean_squared_error, r2_score
from sklearn.model_selection import train_test_split
from sklearn.linear_model import PoissonRegressor<jupyter_output><empty_output><jupyter_text>Setup figure plot settings<jupyter_code>%config InlineBackend.figure_format = 'retina'
az.style.use("arviz-darkgrid")
sns.set_palette("deep")<jupyter_output><empty_output><jupyter_text>Setup paths to import scripts<jupyter_code>PROJECT_ROOT = Path.cwd().parent.resolve()
sys.path.append(str(PROJECT_ROOT))<jupyter_output><empty_output><jupyter_text>Scripts<jupyter_code>from src.data.make_dataset import get_cases_data, to_datetime, subset_latest_outbreak, get_daily_cases_stats<jupyter_output><empty_output><jupyter_text>Data<jupyter_code>raw_cases_data = get_cases_data()<jupyter_output><empty_output><jupyter_text>Audit<jupyter_code>raw_cases_data.info()
raw_cases_data.head()<jupyter_output><empty_output><jupyter_text>Preprocess Raw Data<jupyter_code># Transform column notification_date to datetime
raw_cases_data = to_datetime('notification_date', raw_cases_data)

# Subset data to the latest outbreak
interim_data = subset_latest_outbreak('2021-06-01', 'Overseas', raw_cases_data)

# Aggregate number of cases by day
data = get_daily_cases_stats(interim_data)
data<jupyter_output><empty_output><jupyter_text>Split Predictor and Target Columns Get initial number of cases, based on weekly rolling mean<jupyter_code>mask = data['Epidemiological Days'] == 0
initial_number_of_cases = data.loc[mask, 'Weekly Rolling Average'].values[0]
print(f"Initial number of cases: {initial_number_of_cases}")<jupyter_output>Initial number of cases: 45.0<jupyter_text>Split predictor and target columns<jupyter_code>mask = data['Epidemiological Days'] >= 0
X = data.loc[mask, ["Epidemiological Days", 'Daily Number of Cases', 'Pct Change']]
y = data.loc[mask, "Weekly Rolling Average"]<jupyter_output><empty_output><jupyter_text>Model Training  Data Preparation Train-test split<jupyter_code>train_size = 0.7
X_train, X_test, y_train, y_test = train_test_split(X, y, train_size=train_size)<jupyter_output><empty_output><jupyter_text>Setting up initial parameters for Bayesian modelling<jupyter_code>daily_number_of_cases_std = X_train['Daily Number of Cases'].std()
average_pct_change = X_train['Pct Change'].mean()
std_pct_change = X_train['Pct Change'].std()

print(f"Daily number of cases std: {daily_number_of_cases_std}")
print(f"Average percenntage change: {average_pct_change}")
print(f"Standard deviation of percentage change: {std_pct_change}")<jupyter_output>Daily number of cases std: 48.96283771519154
Average percenntage change: 0.10203126654564262
Standard deviation of percentage change: 0.35077546910006835<jupyter_text>Selecting only epidemiological days for predictor and define datasets as `np.ndarray` objects<jupyter_code>X_train = X_train["Epidemiological Days"].values
y_train = y_train.values
X_test = X_test["Epidemiological Days"].values
y_test = y_test.values

X = X["Epidemiological Days"].values
y = y.values<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09513742071881606, 'fraction_numerical': 0.020839625490788282, 'mean_word_length': 9.930693069306932, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '228245', 'license': 'MIT', 'n_tokens_mistral': 1199, 'n_tokens_neox': 1129, 'n_words': 230, 'path': 'notebooks/Poisson_regression.ipynb', 'repo_name': 'hsteinshiromoto/covid19_nsw', 'size': '3311'}