招行数字金融挑战赛数据赛道赛题一

赛题描述:根据提供的用户行为数据,选手需要分析用户行为特征与广告内容的匹配关系,准确预测用户对测试集广告的点击情况,通过AUC计算得分。

得分0.6120,排名60+。

尝试了很多模型都没有能够提升效果,好奇大佬的代码是咋写的。

分享一下思路:

特征处理

时间特征是大多数广告点击预测任务中的核心因素 。用户在不同时间段的行为差别较大(比如:晚上适合网易云)。

从曝光时间中提取出了,week,hour,hour_m,cos_hour,day_of_week特征,将一天划分成了四个时间段:早上、下午、晚上、夜晚,增加了一个工作时间的判断。

python 复制代码
data['exposure_time'] = pd.to_datetime(data['exposure_time'])
data['week'] = data['exposure_time'].dt.isocalendar().week
data['hour'] = data['exposure_time'].dt.hour
data['hour_m'] = data['hour'] + data['exposure_time'].dt.minute / 60
data['cos_hour'] = np.cos(2 * np.pi * data['hour_m'] / 24)
data['day_of_week'] = data['exposure_time'].dt.dayofweek

def get_time_period(hour):
    if 6 <= hour < 12:
        return 'morning'
    elif 12 <= hour < 18:
        return 'afternoon'
    elif 18 <= hour < 24:
        return 'evening'
    else:
        return 'night'
data['time_period'] = data['hour'].apply(get_time_period)
data['is_work_time'] = data['hour'].apply(lambda x: 1 if 9 <= x < 17 else 0)

除此之外,增添了两个新的特征。
purchase_efficiency:购买效率。
ad_quality_score:广告质量。

python 复制代码
data['purchase_efficiency'] = data['purchase_history'] / (data['activity_score'] + 1e-6)
data['ad_quality_score'] = data['advertiser_score'] * data['historical_ctr']

并对职业、地区、广告类型等数据使用了LabelEncoder 编码。

python 复制代码
label_encoders = {}
for col in ['occupation', 'category', 'material_type', 'region', 'device', 'time_period']:
    le = LabelEncoder()
    data[col] = le.fit_transform(data[col])
    label_encoders[col] = le

对于职业、地区、设备等数据就行了频率编码,捕捉类别的热门程度。

python 复制代码
data['purchase_efficiency'] = data['purchase_history'] / (data['activity_score'] + 1e-6)
data['ad_quality_score'] = data['advertiser_score'] * data['historical_ctr']

创建了三个交互特征:职业-广告类型,设备-广告类型,地区-商品材质。

python 复制代码
data['occupation_category'] = data['occupation'].astype(str) + '_' + data['category'].astype(str)
data['region_material_type'] = data['region'].astype(str) + '_' + data['material_type'].astype(str)
data['device_category'] = data['device'].astype(str) + '_' + data['category'].astype(str)

对purchase_history,activity_score进行分箱,减少对异常值的敏感。

python 复制代码
bins_purchase = [0, 1, 5, 10, 20, 50, 100]
labels_purchase = [0, 1, 2, 3, 4, 5]
data['purchase_history_bin'] = pd.cut(data['purchase_history'], bins=bins_purchase, labels=labels_purchase, include_lowest=True)

bins_activity = [0, 10, 20, 30, 40, 50, 100]
labels_activity = [0, 1, 2, 3, 4, 5]
data['activity_score_bin'] = pd.cut(data['activity_score'], bins=bins_activity, labels=labels_activity, include_lowest=True)
模型参数设置

使用LightGBM模型进行训练。

python 复制代码
params = {
    'boosting_type': 'gbdt',
    'objective': 'binary',
    'metric': 'auc',
    'num_leaves': 63,
    'learning_rate': 0.01,
    'feature_fraction': 0.8,
    'bagging_fraction': 0.8,
    'bagging_freq': 5,
    'verbose': -1,
    'n_estimators': 5000,
    'n_jobs': -1
}

使用 StratifiedKFold 进行交叉验证,保证每个折中的正负样本比例相似。每个折内,我们训练一个LightGBM模型,并计算每个折的AUC。

python 复制代码
skf = StratifiedKFold(n_splits=10, shuffle=True, random_state=42)
oof_preds = np.zeros(len(df_train))
test_preds = np.zeros(len(df_test))
auc_scores = []

for fold, (train_idx, val_idx) in enumerate(skf.split(df_train, df_train[label])):
    X, X_val = df_train[feats].iloc[train_idx], df_train[feats].iloc[val_idx]
    y, y_val = df_train[label].iloc[train_idx], df_train[label].iloc[val_idx]
    model = LGBMClassifier(**params)
    model.fit(X, y, eval_set=[(X_val, y_val)], early_stopping_rounds=100, verbose=200)
    val_pred = model.predict_proba(X_val)[:, 1]
    auc = roc_auc_score(y_val, val_pred)
    auc_scores.append(auc)
相关推荐
Maydaycxc17 小时前
gentic RPA 深度解析|AI Agent 与 RPA 混合架构、落地痛点、选型要点
人工智能·ai·自动化·rpa
摸鱼仙人~17 小时前
从 AI 应用开发到 GPU 计算软件:一份完整的 GPGPU、PyTorch、vLLM 与 AI Infra 学习路线
人工智能·pytorch·vllm
znnnk17 小时前
【AI技术】从 Vibe Coding 到 Harness:以 DeepSeek Harness 为例看 AI 项目的工程化维护
人工智能·ai·deepseek·ai工程化·harness·项目维护
BK贝壳21 小时前
亿级用户签到位图选型复盘:用 bool-hybrid-array 扛冷启动打卡,也把它和 Roaring/Redis 的边界测清楚了
数据结构·python·性能优化·numpy
2601_966949651 天前
如何根据研究的起止时间截取分钟级行情?Python 实战与 QuantDash 数据处理指南
开发语言·python·pandas·量化交易·1024程序员节·股票数据·quantdash
张彦峰ZYF1 天前
越过边界之前:Reward Seeker 实验如何改写智能体安全的时间逻辑
人工智能·ai agent·anthropic·智能体安全·reward seeker·“控制评价过程”泛化跨领域策略·envbom
拓恒技术1 天前
无人机巡检AI算法的工程化落地:从需求到交付的5个核心环节
人工智能·算法·无人机
罗西的思考1 天前
AI 时代的 “房谋杜断”:如何培养能力、品味与判断力
人工智能·算法·机器学习
在世修行1 天前
智学文枢:页面切换与跨页数据预填
python·桌面应用·signal·1024程序员节·pyside·跨页跳转·状态预填
字节跳动视频云技术团队1 天前
720P 直升 8K,解密 2026 抖音美好奇妙夜巨幕超分黑科技
人工智能·音视频开发