Saturday, November 28, 2026

Tracking Questions asked in interviews

Basics that one needs to be up to date with at all times:

  • Metrics: 
    • Accuracy, Precision, Recall, Specificity, Sensitivity, F1 score 
    • TPR, FPR
    • Type 1 error, Type 2 error
    • L1 and L2 regularization and when each of them is used


These were actually asked:

  • Basics:
    • What is pandas?
    • When is L1 used and when is L2 used - pros and cons of each?
    • How to handle bias variance in a model? What is bias in a model and what is variance in a model?
    • In a decision tree, when does bias occur and when does variance occur?
  • Coding:
    • Write a python code to identify transactions from a card that has occured in two different cities/ countries in the last 15 minutes?
    • Write a python code to identify accounts with a transaction amount exceeding $10K in the last 12 hours?
    • Write a python code to identify accounts that have exceeded spends over 90% of their limit in the first 24hr?

  • Modelling questions:
    • What is champion and challenger model?
    • How to create a model for test charge fraud prediction? 


#Python function for merging two databases
 soldprice_comparison= soldprice_by_age.merge(soldprice_by_weight,on='AGE',how='OUTER')
 
 #Sorting dataframes by column values
 ipl_auction_df[['Player_name','Sold_price']].sort_values('Sold_price')[0:5]
 
 #Value_counts() - occurence of each unique value in a column
 ipl_auction_df.country.value_counts()
 
 
 
 #------------------------
 #Python program using group by
 import pandas as pd

data = {
    'Region': ['East', 'East', 'West', 'West', 'East'],
    'Product': ['A', 'A', 'B', 'A', 'B'],
    'Sales': [100, 150, 200, 300, 250],
    'Quantity': [2, 3, 4, 5, 6]
}
df = pd.DataFrame(data)

# Group by Region and Product, then sum Sales
grouped = df.groupby(['Region', 'Product'])['Sales'].sum()
print(grouped)

#Multiple aggregation
summary = df.groupby(['Region', 'Product'], as_index=False).agg(
    total_sales=('Sales', 'sum'),
    avg_sales=('Sales', 'mean'),
    total_qty=('Quantity', 'sum'),
    order_count=('Quantity', 'count')
)

 
 #----------------------------
#Python program to get transactions of >$10k in a rolling window
 
import pandas as pd

# Sample transaction data
data = [
    {"customer_id": "C1", "timestamp": "2026-11-20 08:00:00", "amount": 4000},
    {"customer_id": "C1", "timestamp": "2026-11-20 18:00:00", "amount": 5000},
    {"customer_id": "C1", "timestamp": "2026-11-21 07:30:00", "amount": 2000}, # Total 11,000 in < 24h
    {"customer_id": "C2", "timestamp": "2026-11-20 08:00:00", "amount": 6000},
    {"customer_id": "C2", "timestamp": "2026-11-21 09:00:00", "amount": 6000}, # > 24h apart
]

df = pd.DataFrame(data)

# 1. Convert timestamps to datetime objects and sort chronologically
df["timestamp"] = pd.to_datetime(df["timestamp"])
df = df.sort_values(["customer_id", "timestamp"])

# 2. Calculate the rolling 24-hour sum per customer
rolling_sums = ( df.set_index("timestamp").groupby("customer_id")["amount"].rolling("24h").sum() )

# 3. Filter for customers whose rolling sum exceeds 10,000
flagged_customers = rolling_sums[rolling_sums > 10000].index.get_level_values("customer_id").unique().tolist()

print("Flagged customers:", flagged_customers)
# Output: Flagged customers: ['C1']

No comments:

Post a Comment

Tracking Questions asked in interviews

Basics that one needs to be up to date with at all times: Metrics:   Accuracy, Precision, Recall, Specificity, Sensitivity, F1 score  TPR, F...