我正在尝试使用caret
包对某些栅格数据进行分类。使用RandomForest
一切正常,我只想尝试SVM分类器,但是我收到错误。
数据从不同的栅格聚合(1x1 km,50cm分辨率聚合到2.5m,统计数据最大值,最小值,平均值,中位数和标准值),存储在如下数据框中:
Unscaled table with classification training data
然后我使用以下代码缩放此数据(training_high_final是训练表,第1列是“index”,第22列是“classvalue”:
# scale and center data
thf_scaled <- as.data.frame(scale(training_high_final[,c(-1,-22)], center= T, scale = T))
# Reset Row Numbers
rownames(thf_scaled) <- seq(length=nrow(thf_scaled))
thf_scaled$index <- training_high_final$index
thf_scaled$id <- as.factor(training_high_final$classvalue)
Scaled table看起来像这样: Scaled table
发生错误的反向特征消除代码:
# RFE-Control
# for random forest
# ctrl_rfe <- rfeControl(method = "repeatedcv", number = 9, repeats= 5, functions = rfFuncs, allowParallel = T)
# for SVM
ctrl_rfe <- rfeControl(method = "repeatedcv", number = 9, repeats= 5, allowParallel = T)
sizes = c(1:20)
# RFE (Col 21 is index (not needed), Col 22 the classvalue)
rfe_high <- rfe(thf_scaled[,c(-21,-22)], thf_scaled[,22], sizes = sizes, rfeControl = ctrl_rfe, method="lssvmPoly")
结果:
> rfe_high <- rfe(thf_scaled[,c(-21,-22)], thf_scaled[,22], sizes = sizes, rfeControl = ctrl_rfe, method="lssvmPoly")
Error in { : task 1 failed - "missing value where TRUE/FALSE needed"
我之前尝试过更多变量(现在只有20个,在我有~80之前)并且得到了错误
任务1失败 - “停止”。
有170个没有NA数据的训练样本。