Skip to content

Instantly share code, notes, and snippets.

@DavidRosen
DavidRosen / raw_metric_samples.py
Last active September 8, 2021 16:21
generate the samples one by one and save the metrics
from tqdm import trange
DFLT_NBOOTS=500
def raw_metric_samples(metrics, *data_args, nboots=DFLT_NBOOTS, sort=False,
**metric_kwargs):
"""Return dataframe containing metric(s) for nboots boot sample datasets.
metrics is a metric func or iterable of funcs e.g. [m1, m2, m3]
"""
if callable(metrics): metrics=[metrics] # single metric func to list
metrics=list(metrics) # in case it is a generator
dforig=pd.DataFrame\
@DavidRosen
DavidRosen / default_confusion.py
Last active September 27, 2021 22:10
Imbalanced Data article
hardpredtst=gbc.predict(Xtest)
def conf_matrix(y,pred):
((tn, fp), (fn, tp)) = metrics.confusion_matrix(y, pred)
((tnr,fpr),(fnr,tpr))= metrics.confusion_matrix(y, pred, normalize='true')
return pd.DataFrame([[f'TN = {tn} (TNR = {tnr:1.2%})', f'FP = {fp} (FPR = {fpr:1.2%})'], # 97
[f'FN = {fn} (FNR = {fnr:1.2%})', f'TP = {tp} (TPR = {tpr:1.2%})']],#96
index=['True 0(Legit)', 'True 1(Fraud)'],
columns=['Pred 0(Approve as Legit)', 'Pred 1(Deny as Fraud)'])
conf_matrix(ytest,hardpredtst)