私は以下のコード使用してキャレットで加重観察を適用したい:エラー(R)
model_weights <- ifelse(train$y == 0,
(1/table(train$y)[1]) * 0.5,
(1/table(train$y)[2]) * 0.5)
xgbT <- train(x = as.matrix(train[,-21]), y = make.names(as.factor(train$y)),
method = "xgbTree",
trControl = cctrl1,
metric = "MCC",
maximize = TRUE,
weights = model_weights,
preProc = c("center", "scale"),
tuneGrid = expand.grid(nrounds = c(150), #number of trees
max_depth = c(7), #max tree depth
eta = c(0.03), #learning rate
gamma = c(0.3), #min split loss
colsample_bytree = c(0.7),
min_child_weight = c(10, 1, 5), #min number of instances in the leaf
subsample = c(0.6)), #subsample ratio of the training instance
early_stop_round = c(3), #if no improvements over specified rounds
objective = c("binary:logistic"),
silent = 0)
はしかし、それは私に、このエラーを与える:Error in model.frame.default(formula = .outcome ~ ., data = dat, weights = wts) : variable lengths differ (found for '(weights)')
私はそれらの長さは以下のコードと同じであることが確認されているものの:
> table(model_weights)
model_weights
0.0000277654375832963 0.000231481481481481
18008 2160
> table(train$y)
0 1
18008 2160
任意のアイデアどのようにこの問題を解決するには?
注:weights
パラメータなしでtrain
機能を実行できます。
、私はここでそれを確認:https://topepo.github.io/caret /train-models-by-tag.html#Accepts_Case_Weights –
どちらですか?リンクを共有してください –
申し訳ありません、朝...私はリンクしていると仮定しました:[ここ](https://github.com/topepo/caret/blob/master/RegressionTests/Code/xgbTree.R)それは - 'test_class_cv_form_weight 'example – missuse