【发布时间】:2018-03-27 06:46:23
【问题描述】:
我正在使用 xgboost 构建模型。数据集只有 200 行和 10000 列。
我尝试 chi-2 得到 100 列,但我的混淆矩阵如下所示:
1 0
1 190 0
0 10 0
我尝试使用 10000 个属性,随机选择 100 个属性,根据 chi-2 选择 100 个属性,但我从来没有得到 0 案例预测。是因为数据集,还是因为我使用 xgboost 的方式?
我的 factor(pred.cv) 总是只显示 1 个级别,而 factor(y+1) 有 1 或 2 个级别。
param <- list("objective" = "binary:logistic",
"eval_metric" = "error",
"nthread" = 2,
"max_depth" = 5,
"eta" = 0.3,
"gamma" = 0,
"subsample" = 0.8,
"colsample_bytree" = 0.8,
"min_child_weight" = 1,
"max_delta_step"= 5,
"learning_rate" =0.1,
"n_estimators" = 1000,
"seed"=27,
"scale_pos_weight" = 1
)
nfold=3
nrounds=200
pred.cv = matrix(bst.cv$pred, nrow=length(bst.cv$pred)/1, ncol=1)
pred.cv = max.col(pred.cv, "last")
factor(y+1) # this is the target in train, level 1 and 2
factor(pred.cv) # this is the issue, it is always only 1 level
【问题讨论】:
-
因子(y+1)中1/2水平的比例是多少?如果不平衡,可以尝试更改 scale_pos_weight。
-
@missuse 只有 10%,我先试试!
-
@missuse 我想我有一些线索。从网上说要这样做:“pred.cv = matrix(bst.cv$pred, nrow=length(bst.cv$pred)/num.class, ncol=num.class)”,但是当我这样做时, num.class= 2,我的confusionMatrix(factor(y+1), factor(pred.cv)) 返回错误“所有参数必须具有相同的长度”。因为 factor(y+1) 是 980,但是 factor(pred.cv) 是 980/2。你知道怎么解决吗?
-
试试
pred.cv = ifelse(bst$pred < 0.5, 0, 1)和table(pred.cv, y)。 -
@missuse 我实际上在 5 分钟前就知道了,我没有转换概率。是或否:/谢谢!