Python 具有非常不平衡数据的广告点击预测

Python 具有非常不平衡数据的广告点击预测,python,machine-learning,xgboost,balance,Python,Machine Learning,Xgboost,Balance,我有一些非常不平衡的数据(3%为正),我正在使用xgboost进行一些学习。这个文件相当大,我以前尝试过logistic回归、randomforest和svm(只使用整个数据的一些子样本,因为数据太大)。为了解释数据不平衡的原因,我尝试使用SMOTE(使数据超大)来调整类权重和平衡数据。但这些似乎都无济于事。当我使用上述任何一种方法时,准确率都会变差 当我尝试xgboost并尝试像文档建议的那样调整scale正权重参数时,它只会使准确性更差。总的来说,我所有的模型都比预测所有0更糟糕 我是否可以

我有一些非常不平衡的数据(3%为正),我正在使用xgboost进行一些学习。这个文件相当大,我以前尝试过logistic回归、randomforest和svm(只使用整个数据的一些子样本,因为数据太大)。为了解释数据不平衡的原因,我尝试使用SMOTE(使数据超大)来调整类权重和平衡数据。但这些似乎都无济于事。当我使用上述任何一种方法时,准确率都会变差

当我尝试xgboost并尝试像文档建议的那样调整scale正权重参数时,它只会使准确性更差。总的来说,我所有的模型都比预测所有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))

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

您可以使用scikit learn的
GridSearchCV

但是,现在有比网格搜索更好的方法来探索参数空间,例如scikit optimize:

示例:(这是一个回归器,bit的工作原理与分类相同

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)