# Correct way of calculating probability

I have some data which shows how many orders were made by a certain customer group that bought a certain product type: And the same format but showing how many refunds were made: I am trying to answer a question:

What is the probability that an order is made by a customer in the group [A - B] and is refunded?

My approach was:

being_in_group = df_final[df_final.customer_group.isin(['A','B','C','D'])]\
.groupby('customer_group')\
.agg({'order_id': 'count'}).sum(axis = 0)

all_orders = df_final.groupby('customer_group').agg({'order_id': 'count'})\
.sum(axis = 0)

p_being_in_group = round(being_in_group / all_orders, 5)

being_refunded = df_final[(df_final.refund == True) & (df_final.customer_group.isin(['A','B']))]\
.groupby('customer_group')\
.agg({'order_id': 'count'})\
.sum(axis = 0)
# or taking all customer groups
being_refunded_all = df_final[(df_final.refund == True)]\
.groupby('customer_group')\
.agg({'order_id': 'count'})\
.sum(axis = 0)

p_being_refunded = round(being_refunded / all_orders, 5)
p_being_refunded_all = round(being_refunded_all / all_orders, 5)

p_final_1 = p_being_in_group * p_being_refunded * 100
p_final_2 = p_being_in_group * p_being_refunded_all * 100


I am wondering if that is the correct approach - calculating the probability of an order being made by the group A & B and then checking the refunded orders - should I check the refunded orders in all of the data or only in the data where customer_group is A & B?

If my understanding is correct, your p_final_1 should give the correct result.

More simply:

P(groupAB ^ refunded)   = #(groupAB ^ refunded) / #(total)


where

• #(groupAB ^ refunded) is the number of orders in group A and B which are refunded
• #(total) is the total number of orders

I think that this should be equal to p_final_1 because:

p_final_1 = p_being_in_group * p_being_refunded
= p(groupAB)       * p(refunded | groupAB)
= p(groupAB)       * p(refunded ^ groupAB) / p(groupAB)
= p(refunded ^ groupAB)