@@ -489,7 +489,7 @@ def plot_roc_pr_curves(vanilla_model, tuned_model, *, title):
489
489
_ , ax = plt .subplots ()
490
490
ax .hist (amount_fraud , bins = 100 )
491
491
ax .set_title ("Amount of fraud transaction" )
492
- _ = ax .set_xlabel ("Amount ($ )" )
492
+ _ = ax .set_xlabel ("Amount (€ )" )
493
493
494
494
# %%
495
495
# Addressing the problem with a business metric
@@ -501,8 +501,8 @@ def plot_roc_pr_curves(vanilla_model, tuned_model, *, title):
501
501
# transaction result in a loss of the amount of the transaction. As stated in [2]_, the
502
502
# gain and loss related to refusals (of fraudulent and legitimate transactions) are not
503
503
# trivial to define. Here, we define that a refusal of a legitimate transaction is
504
- # estimated to a loss of $5 while the refusal of a fraudulent transaction is estimated
505
- # to a gain of $50 dollars and the amount of the transaction. Therefore, we define the
504
+ # estimated to a loss of 5€ while the refusal of a fraudulent transaction is estimated
505
+ # to a gain of 50€ and the amount of the transaction. Therefore, we define the
506
506
# following function to compute the total benefit of a given decision:
507
507
508
508
@@ -557,22 +557,22 @@ def business_metric(y_true, y_pred, amount):
557
557
benefit_cost = business_scorer (
558
558
easy_going_classifier , data_test , target_test , amount = amount_test
559
559
)
560
- print (f"Benefit/cost of our easy-going classifier: $ { benefit_cost :,.2f} " )
560
+ print (f"Benefit/cost of our easy-going classifier: { benefit_cost :,.2f} € " )
561
561
562
562
# %%
563
563
# A classifier that predict all transactions as legitimate would create a profit of
564
- # around $ 220,000. We make the same evaluation for a classifier that predicts all
564
+ # around 220,000.€ We make the same evaluation for a classifier that predicts all
565
565
# transactions as fraudulent.
566
566
intolerant_classifier = DummyClassifier (strategy = "constant" , constant = 1 )
567
567
intolerant_classifier .fit (data_train , target_train )
568
568
benefit_cost = business_scorer (
569
569
intolerant_classifier , data_test , target_test , amount = amount_test
570
570
)
571
- print (f"Benefit/cost of our intolerant classifier: $ { benefit_cost :,.2f} " )
571
+ print (f"Benefit/cost of our intolerant classifier: { benefit_cost :,.2f} € " )
572
572
573
573
# %%
574
- # Such a classifier create a loss of around $ 670,000. A predictive model should allow
575
- # us to make a profit larger than $ 220,000. It is interesting to compare this business
574
+ # Such a classifier create a loss of around 670,000.€ A predictive model should allow
575
+ # us to make a profit larger than 220,000.€ It is interesting to compare this business
576
576
# metric with another "standard" statistical metric such as the balanced accuracy.
577
577
from sklearn .metrics import get_scorer
578
578
@@ -607,7 +607,7 @@ def business_metric(y_true, y_pred, amount):
607
607
608
608
print (
609
609
"Benefit/cost of our logistic regression: "
610
- f"$ { business_scorer (model , data_test , target_test , amount = amount_test ):,.2f} "
610
+ f"{ business_scorer (model , data_test , target_test , amount = amount_test ):,.2f} € "
611
611
)
612
612
print (
613
613
"Balanced accuracy of our logistic regression: "
@@ -645,7 +645,7 @@ def business_metric(y_true, y_pred, amount):
645
645
# %%
646
646
print (
647
647
"Benefit/cost of our logistic regression: "
648
- f"$ { business_scorer (tuned_model , data_test , target_test , amount = amount_test ):,.2f} "
648
+ f"{ business_scorer (tuned_model , data_test , target_test , amount = amount_test ):,.2f} € "
649
649
)
650
650
print (
651
651
"Balanced accuracy of our logistic regression: "
@@ -691,7 +691,7 @@ def business_metric(y_true, y_pred, amount):
691
691
business_score = business_scorer (
692
692
model_fixed_threshold , data_test , target_test , amount = amount_test
693
693
)
694
- print (f"Benefit/cost of our logistic regression: $ { business_score :,.2f} " )
694
+ print (f"Benefit/cost of our logistic regression: { business_score :,.2f} € " )
695
695
print (
696
696
"Balanced accuracy of our logistic regression: "
697
697
f"{ balanced_accuracy_scorer (model_fixed_threshold , data_test , target_test ):.3f} "
0 commit comments