The fraud detection team at Stripe aims to reduce merchant fraud risk for Stripe with minimal pain to good merchants through machine learning. To provide initial data for training this machine learning model, you are tasked with developing a system to assess the fraud risk associated with transactions made to various merchants.
Description
You are given transactions_list which is a list of transactions for a certain day, merchants_list which is a list of merchants, and rules_list which is a list of rules corresponding to each transaction.
A transaction denotes a payment made by a customer to a merchant. Each merchant in merchants_list is assigned a base_score.
Your task is to assign each merchant a fraud score based on their transaction(s), where each transaction can have different risk factors based on certain categories, e.g. transaction amount, frequency of similar transactions, user activity.
To do this:
- Initialize a merchant's
current_scoreas theirbase_score. - For each transaction in the
transactions_list, calculate and update the merchant'scurrent_score. This should be done in separate passes over the entire list for each step:- If the transaction amount is greater than the corresponding rule's
min_transaction_amount, multiplycurrent_scoreby the corresponding rule'smultiplicative_factor. - If the same
customer_idhas made three or more transactions to thatmerchant_idincluding the current transaction, add all the corresponding rules'additive_factorstocurrent_score, cumulatively. For example, if the merchant's score at the third transaction isX, which includes the first, second, and thirdadditive_factors, the fourth transaction should be:X + the fourth transaction additive_factor - If a transaction is the third or more from the same
customer_idin the same hour for the samemerchant_idincluding the current transaction, do the following:- If the hour is between 12 to 17 inclusive: Add the penalty each time. This includes the first and second transactions as well as all the ones after the third.
- If the hour is between 9 to 11, or 18 to 21 inclusive: Subtract the penalty each time. This includes the first and second transactions as well as all the ones after the third.
- If the hour falls outside the above ranges, don't do anything.
- If the transaction amount is greater than the corresponding rule's
Input
Note: You may assume that there won't be any integer overflows.
transactions_list: A list of lengthnwhere1 <= n <= 1000, where each transaction is represented as a comma-separated string.- A string
merchant_idwith length> 0, representing the merchant who receives payment. - An integer
amount, representing the amount of the payment. - A string
customer_idwith length> 0, representing the customer who makes payment. - An integer
hour, where0 <= hour <= 23, representing the hour of the transaction.
- A string
rules_list: A list of lengthnwhere1 <= n <= 1000, where each rule is represented as a comma-separated string and corresponds to each transaction intransactions_list.- An integer
min_transaction_amountof the corresponding transaction to consider fraudulent. - An integer
multiplicative_factor. - An integer
additive_factor. - An integer
penalty.
- An integer
merchants_list: A list of lengthm, where1 <= m <= 1000, where each item is a merchant profile represented as a comma-separated string that gives additional context for the score.- A string
merchant_idwith length> 0, representing the merchant who receives payment. - An integer
base_score, where1 <= base_score <= 50. Represents the base risk score of the merchant.
- A string
Output
Return a list of comma-separated strings denoting the merchants in lexicographical order and their fraud scores.
Example Input
n = 6
transactions_list = [
"merchant1,1200,customer1,10",
"merchant1,500,customer1,10",
"merchant2,2400,customer1,15",
"merchant1,800,customer1,16",
"merchant1,1000,customer2,17",
"merchant1,1400,customer1,10",
]
rules_list = [
"1000,2,8,15",
"1400,5,3,19",
"2300,3,17,3",
"1800,2,9,6",
"1000,4,8,2",
"1200,3,11,7",
]
m = 2
merchants_list = [
"merchant1,10",
"merchant2,20",
]Example Output
[
"merchant1,50", # 10 -> 10*2=20 -> 20*3=60 -> 60+8+3+9+11=91 -> 91-15-19-7=50
"merchant2,60" # 20 -> 20*3=60
]我们也有代面试,面试辅助,OA代写等服务助您早日上岸~

