【发布时间】:2020-02-16 11:15:15
【问题描述】:
我有我的数据(目前是虚拟数据):
data_for_prediction <- original_data[,c(1,3)]
如果您想重现问题,则以下内容足以解决此错误:
data_for_prediction <- data.frame(
diff = c(1,2,3),
f.mean_slope = c (1,2,3)
)
仅包含两行:“diff”(Y)和“f.mean_slope”(x)
然后我对整个事情进行采样:
set.seed(101)
trainingRowIndex <- sample(1:nrow(data_for_prediction), 0.8*nrow(data_for_prediction))
trainingData <- data_for_prediction[trainingRowIndex, ]
testData <- data_for_prediction[-trainingRowIndex, ]
然后我创建一个适合:
model_fit <- lm(diff ~ ., data = trainingData, method = "model.frame")
当我现在尝试预测某事时:
newdata <- data.frame(
f.mean_slope = c(1,2,3)
)
distPred <- predict(model_fit, newdata)
然后 R Studio 只返回错误消息:
UseMethod("predict") 中的错误:没有适用于“predict”的方法应用于“data.Frame”类的对象
这让我发疯了,因为我在互联网上搜索了大量类似问题的问题,但没有一个有效......
有人有想法吗?
【问题讨论】:
标签: r dataframe machine-learning linear-regression