Skip to content

Instantly share code, notes, and snippets.

View erykml's full-sized avatar

Eryk Lewinson erykml

View GitHub Profile
# for reproducibility
np.random.seed(42)
# generate the DataFrame with dates
range_of_dates = pd.date_range(
start="2017-01-01",
end="2020-12-30"
)
X = pd.DataFrame(index=range_of_dates)
# create a sequence of day numbers
X["day_nr"] = range(len(X))
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from datetime import date
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import FunctionTransformer
from sklearn.metrics import mean_absolute_error
from sklego.preprocessing import RepeatingBasisFunction
import pandas as pd
import glob
import os
from config import RAW_DIR, PROCESSED_DIR, REPORTS_DIR, AUGMENTED_DIR
from deepchecks.tabular import Dataset
from deepchecks.tabular.suites import full_suite
# prepare output dir for the data validation reports
import os
import pandas as pd
from config import RAW_DIR, PROCESSED_DIR, AUGMENTED_DIR
from imblearn.over_sampling import RandomOverSampler, SMOTE, ADASYN
from imblearn.under_sampling import RandomUnderSampler
RANDOM_STATE = 42
# define the considered augmentations
import pandas as pd
from config import RAW_DIR, PROCESSED_DIR
import os
from sklearn.preprocessing import RobustScaler
from sklearn.model_selection import train_test_split
# load data
df = pd.read_csv(f"{RAW_DIR}/creditcard.csv")
# directories
RAW_DIR = "data/raw"
PROCESSED_DIR = "data/processed"
AUGMENTED_DIR = "data/augmented"
REPORTS_DIR = "data_validation"
pred_df["TP"] = np.where(pred_df["class"] == 1, pred_df["prob"], 0)
pred_df["FP"] = np.where(pred_df["class"] == 1, 1 - pred_df["prob"], 0)
pred_df["TN"] = np.where(pred_df["class"] == 0, 1- pred_df["prob"], 0)
pred_df["FN"] = np.where(pred_df["class"] == 0, pred_df["prob"], 0)
pred_df
import pandas as pd
import numpy as np
pred_df = pd.DataFrame(
data={"class": [1, 1, 1, 0, 0],
"prob": [0.9, 0.85, 0.6, 0.4, 0.2]}
)
pred_df
<html>
<head>
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
<py-env>
- numpy
- matplotlib
</py-env>
</head>
<html>
<head>
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
</head>
<body> <py-script> print('Hello, World!') </py-script> </body>
</html>