小编cho*_*all的帖子

为什么在套索回归中计算 MSE 会给出不同的输出?

我正在尝试对来自 lasso2 包的前列腺癌数据运行不同的回归模型。当我使用 Lasso 时,我看到了两种不同的方法来计算均方误差。但他们确实给了我完全不同的结果,所以我想知道我是否做错了什么,或者这是否只是意味着一种方法比另一种更好?

# Needs the following R packages.
library(lasso2)
library(glmnet)

# Gets the prostate cancer dataset
data(Prostate)

# Defines the Mean Square Error function 
mse = function(x,y) { mean((x-y)^2)}

# 75% of the sample size.
smp_size = floor(0.75 * nrow(Prostate))

# Sets the seed to make the partition reproductible.
set.seed(907)
train_ind = sample(seq_len(nrow(Prostate)), size = smp_size)

# Training set
train = Prostate[train_ind, ]

# Test set
test = Prostate[-train_ind, ]

# Creates matrices for independent and dependent …
Run Code Online (Sandbox Code Playgroud)

r machine-learning lasso-regression glmnet mean-square-error

5
推荐指数
1
解决办法
7726
查看次数