我在R中有两个包含多个data.frames的列表。一个列表是训练数据集,另一个是测试数据集。我想使用训练数据来训练模型,然后为测试数据创建预测。到目前为止,我可以使用训练列表对单个数据集进行预测(survey_points是data.frame对象)。这会产生与train_list对象中的每个训练data.frame相对应的预测列表,完美:
true_preds = lapply(train_list, function(x) predict(ranger(bc_title4 ~ ACurr15 + Bath15 + Comp13 + East15 + Mcur15 + Nor15 + vrm15 + Slop11 + MWav13 + X1IC2CR3IS4,
data = x), survey_points)$predictions)
但是,当我尝试使用以下代码使用训练data.frames列表预测我的test data.frames列表时:
test_preds = lapply(train_list, function(x) predict(ranger(bc_title4 ~ ACurr15 + Bath15 + Comp13 + East15 + Mcur15 + Nor15 + vrm15 + Slop11 + MWav13 + X1IC2CR3IS4,
data = x), test_list)$predictions)
我得到以下错误和回溯:
Error in data[, forest$independent.variable.names, drop = FALSE] :
incorrect number of dimensions
7.
predict.ranger.forest(forest, data, predict.all, num.trees, type,
se.method, seed, num.threads, verbose, object$inbag.counts,
...)
6.
predict(forest, data, predict.all, num.trees, type, se.method,
seed, num.threads, verbose, object$inbag.counts, ...)
5.
predict.ranger(ranger(bc_title4 ~ ACurr15 + Bath15 + Comp13 +
East15 + Mcur15 + Nor15 + vrm15 + Slop11 + MWav13 + X1IC2CR3IS4,
data = x), test_list)
4.
predict(ranger(bc_title4 ~ ACurr15 + Bath15 + Comp13 + East15 +
Mcur15 + Nor15 + vrm15 + Slop11 + MWav13 + X1IC2CR3IS4, data = x),
test_list)
3.
predict(ranger(bc_title4 ~ ACurr15 + Bath15 + Comp13 + East15 +
Mcur15 + Nor15 + vrm15 + Slop11 + MWav13 + X1IC2CR3IS4, data = x),
test_list)
2.
FUN(X[[i]], ...)
1.
lapply(train_list, function(x) predict(ranger(bc_title4 ~ ACurr15 +
Bath15 + Comp13 + East15 + Mcur15 + Nor15 + vrm15 + Slop11 +
MWav13 + X1IC2CR3IS4, data = x), test_list))