r - Predict() 仅返回带有随机森林的 NA
问题描述
我使用随机森林构建了一个模型,并尝试使用 predict() 在另一个数据库上对其进行测试。但是,它只返回 NA。
RF=randomForest(intention~., data=train,ntree=1000,na.action=na.roughfix)
#no NA in the train nor the test dataset
# Predicting
pred <-predict(RF, newdata=test,type="response")
#pred vector is only set to NA
我检查了这个页面并检查了我的数据集没有 NA。但是,我继续获得相同的回报。 https://www.kaggle.com/c/the-analytics-edge-mit-15-071x/discussion/7808
我也检查了这个页面,但对于随机森林来说似乎并不准确(或者我不明白)。 r - loess 预测返回 NA
感谢您的帮助 !
解决方案
正如@Allan Cameron 猜测的那样,问题来自数据集的不对称性。在运行 RF 算法时遇到问题,我在这个论坛上找到了一个建议,使用以下代码删除值太少的变量。
index <- c()
for (j in (1 : 41)) {
if (is.numeric(train[ ,j]) & length(unique(as.numeric(train[ ,j]))) == 1 )
{index <- append(index,j)}
train <- train[ ,-index]
#ran on test dataset too
但是,我没有看到它在火车上删除了 5 列,在测试中删除了 9 列。函数 predict() 尝试将使用 51 个变量构建的模型应用于具有 47 个变量的数据集返回 NA 但没有错误。
推荐阅读
- python - 将类型/类实例作为参数传递给类构造函数?
- python - 如何使用numpy将除前n个值之外的矩阵(二维数组)的所有值清零?
- reactjs - 反应 setState 工作然后变得未定义
- java - java - 如何比较两个txt文件中的元素并将它们合并到一个文件中?
- c# - Password_Verify 哈希密码问题
- python - 什么是 tf.losses.absolute_difference 的替代品
- c - 忽略scanf返回值并重新定义函数;不同的基本类型
- javascript - 从 php 文件中的 Javascript 调用 php 函数
- javascript - 如何使用 v-if 从显示值为 null 的数组对象中进行条件处理
- php - 通过 curl 表单登录和发布参数