我试图使用 dask 来解决 kaggle 欺诈检测分类问题。但是,当我构建模型时,模型将所有值预测为 1。
我真的很惊讶,因为测试数据中有 56,000 个 zeor 和 92 个 zeor,但模型仍然以某种方式将所有值预测为 1。
我显然做错了什么。如何正确使用模型?
MWE
import numpy as np
import pandas as pd
import dask
import dask.dataframe as dd
import dask_ml
from dask_ml.xgboost import XGBClassifier
import collections
from dask_ml.model_selection import train_test_split
from dask.distributed import Client
# set up cluster
client = Client(n_workers=4)
# load the data
ifile = "https://github.com/vermaji333/MLProject/blob/master/creditcard.zip?raw=true"
#!wget https://github.com/vermaji333/MLProject/blob/master/creditcard.zip?raw=true
#ifile = 'creditcard.zip'
ddf = dd.read_csv(ifile,compression='zip',
blocksize=None,
assume_missing=True)
# train-test split
target = 'Class'
Xtr, Xtx, ytr, ytx = train_test_split(
ddf.drop(target,axis=1),
ddf[target],
test_size=0.2,
random_state=100,
shuffle=True
)
# modelling
model = XGBClassifier(n_jobs=-1,
random_state=100,
scale_pos_weight=1, # default
objective='binary:logistic')
model.fit(Xtr,ytr)
ypreds = model.predict(Xtx)
ytx = ytx.compute()
ypreds = ypreds.compute()
# model evaluation
print(collections.Counter(ytx)) # Counter({0.0: 56607, 1.0: 92})
print(collections.Counter(ypreds)) # this gives all 1's
更新
我尝试了各种比例 pos 权重值。
I tried various scale_pos_weights
collections.Counter(ytr)
Counter({0.0: 227708, 1.0: 400})
scale_pos_weight= 227708/400
scale_pos_weight= 400/227708
scale_pos_weight= other values
But, for all parameters, I got all 1's as the result:
print(collections.Counter(ytx)) # Counter({0.0: 56607, 1.0: 92})
print(collections.Counter(ypreds)) # this gives all 1's
Counter({0.0: 56607, 1.0: 92})
Counter({1: 56699})