【问题标题】:Ad click prediction with very unbalanced data数据非常不平衡的广告点击预测
【发布时间】:2017-05-26 16:12:16
【问题描述】:

我有一些非常不平衡的数据(3% 肯定),我正在使用 xgboost 进行一些学习。该文件很大,我之前尝试过逻辑回归、随机森林和 svm(仅使用整个数据的一些子样本,因为数据太大)。为了解决数据不平衡,我尝试了使用 SMOTE 的类权重和平衡数据(这使得数据超级大)。但这似乎无济于事。当我使用上述任何一种方法时,准确率都会变差。

当我尝试 xgboost 并尝试像文档建议的那样调整 scale-positive-weight 参数时,它只会使准确性更差。总的来说,我所有的模型都比仅仅预测全 0 效果更差。

无论如何我可以解释这种数据不平衡吗?

这是我的 xgboost 代码

x = data[:,3:] 
y = data[:,2]
from xgboost import XGBClassifier 
model = XGBClassifier(scale_pos_weight = np.sum(y==0)/np.sum(y==1))
model.fit(x, y, eval_metric="auc")
# make predictions for test data
y_pred = model.predict(x)
#predictions = [round(value) for value in y_pred]
# evaluate predictions
accuracy = accuracy_score(y, y_pred)
print("Accuracy: %.2f%%" % (accuracy * 100.0))

【问题讨论】:

    标签: python machine-learning xgboost balance


    【解决方案1】:

    似乎大多数使用 XGBoost(或其他方式)处理不平衡数据的在线建议是通过搜索进行超参数调整。

    你可以使用 scikit-learn 的 GridSearchCV: http://scikit-learn.org/stable/modules/generated/sklearn.model_selection.GridSearchCV.html

    但是,现在有比网格搜索更好的方法来探索参数空间,例如scikit 优化:https://scikit-optimize.github.io/#skopt.BayesSearchCV

    示例:(这是一个回归量,位对分类的作用相同

    from xgboost import XGBRegressor
    from skopt import BayesSearchCV
    
    n_features = X_train.shape[1] - 1
    
    sum_pos = np.sum(y_train==1)
    sum_neg = np.sum(y_train==0)
    
    opt = BayesSearchCV(
        XGBRegressor(objective='reg:linear', n_jobs=4, scale_pos_weight = sum_neg/sum_pos),
        {
            'n_estimators': (1, 50),
            'max_depth': (1, 20),
            'learning_rate': (10**-5, 10**0, "log-uniform"),
            'min_child_weight': (1, 5),
            'max_delta_step': (1, 10)
        },
        n_iter=8, # may want to have more iterations here... :)
        verbose=99
    )
    
    opt.fit(X_train[:,1:], y_train)
    

    【讨论】:

      猜你喜欢
      • 2018-11-24
      • 2018-12-13
      • 1970-01-01
      • 1970-01-01
      • 2012-02-01
      • 1970-01-01
      • 2017-11-23
      • 2010-09-30
      • 1970-01-01
      相关资源
      最近更新 更多