呼叫日志FTR7%计算异常:L2列值差异导致数值波动排查
关于呼叫日志FTR计算结果异常的问题
我用Python的pandas和numpy库基于呼叫日志数据集计算首次解决率(First Time Resolution,FTR)百分比。处理calls_logs_cleaned_2025-05-02.csv时,FTR7%约为63.8%;但处理另一个仅填充了L2列有效值(原文件L2列全为空)的CSV文件时,FTR7%骤降至约39.8%。
我的FTR计算逻辑完全没用到l1_intent和l2_intent列,所以对结果差异感到困惑。CSV文件包含列:customer_account_no、agent_id、agent_name、start_time、l1_intent、l2_intent。
计算代码
import pandas as pd import numpy as np # Loading data df = pd.read_csv('calls_logs_cleaned_2025-05-02.csv') # Converting start_time to datetime df['start_time'] = pd.to_datetime(df['start_time'], format='mixed', dayfirst=True) # Sorting data by customer and time df = df.sort_values(by=['customer_account_no', 'start_time']).reset_index(drop=True) # Function to calculate FTR7 and FTR14 def calculate_ftr(group): times = group['start_time'].values.astype('datetime64[ns]') n = len(times) ftr7, ftr14 = np.ones(n, dtype=int), np.ones(n, dtype=int) for i in range(1, n): current_time = times[i] # Check if there is a previous call within 7 days left_bound_7 = current_time - np.timedelta64(7, 'D') idx_7 = np.searchsorted(times[:i], left_bound_7, side='right') ftr7[i] = 0 if idx_7 < i else 1 # Check if there is a previous call within 14 days left_bound_14 = current_time - np.timedelta64(14, 'D') idx_14 = np.searchsorted(times[:i], left_bound_14, side='right') ftr14[i] = 0 if idx_14 < i else 1 return pd.DataFrame({'FTR7': ftr7, 'FTR14': ftr14}, index=group.index) # Applying function per customer group df[['FTR7', 'FTR14']] = df.groupby('customer_account_no', group_keys=False).apply(calculate_ftr) # Calculate overall percentages ftr7_percent = df['FTR7'].mean() * 100 ftr14_percent = df['FTR14'].mean() * 100 print(f"FTR7%: {ftr7_percent:.1f}%") print(f"FTR14%: {ftr14_percent:.1f}%")
问题
- 为何填充了有效L2值的文件会让FTR7%从63.8%降到39.8%?
- 代码里没显式用到的L2列值会不会影响计算结果?
- 需要检查或调试哪些内容才能弄明白这个差异?
样本数据
| id | customer_account_no | agent_id | start_time | l1_val | l2_val | call_time |
|---|---|---|---|---|---|---|
| bq1001 | 79423 | 88110 | 02-01-2025 | l1_cat1 | l2_cat1 | 120 |
| bq1003 | 88445 | 64566 | 02-01-2025 | l1_cat1 | l2_cat2 | 143 |
| bq1005 | 99345 | 88110 | 02-01-2025 | l1_cat1 | l2_cat3 | 234 |
| bq1009 | 66754 | 34233 | 02-01-2025 | l1_cat1 | l2_cat2 | 112 |
| bq1011 | 49423 | 92343 | 03-01-2025 | l1_cat1 | l2_cat3 | 99 |
| bq1012 | 48445 | 64566 | 03-01-2025 | l1_cat1 | l2_cat2 | 187 |
| bq1013 | 79423 | 92343 | 04-01-2025 | l1_cat1 | l2_cat1 | 55 |
| bq1014 | 99345 | 64566 | 05-01-2025 | l1_cat1 | l2_cat3 | 342 |
| bq1015 | 79423 | 34233 | 07-01-2025 | l1_cat1 | l2_cat2 | 87 |
| bq1016 | 99345 | 34233 | 07-01-2025 | l1_cat1 | l2_cat4 | 132 |
内容的提问来源于stack exchange,提问作者IAIMT2024
相关产品推荐
相关产品推荐

