【发布时间】:2016-06-18 17:34:24
【问题描述】:
我真的被困在这个问题上,希望有人能帮助我!我有一个包含 54 列的数据集,我想对带有岭回归的测试集进行预测。
nn <-nrow(longley)
index <- 1:nrow(longley)
testindex <- sample(index, trunc(length(index)/3))
testset <- longley[testindex,]
trainset <-longley[-testindex,]
trainset1 <- trainset[,-7]
# Fit the ridge regression model:
mod <- lm.ridge(y ~., data = trainset, lambda = 0.661)
# Predict and evaluate it by using MAE function:
mae <- function(model) {
y = trainset$Employed
y.pred <- predict(model, trainset)
return(mean(abs(y-y.pred)))
}
当我这样做时,我收到以下错误消息:
Error in UseMethod("predict") :
no applicable method for 'predict' applied to an object of class "ridgelm"
还有什么方法可以使用有效的岭回归进行预测(也可以使用 rsquared 和 MAE 等评估指标)?
【问题讨论】:
标签: r regression