我正在使用来自库 (MASS) 的数据 (birthwt),我想在 Lasso 模型中使用 R 计算 Mathews 相关系数 (MCC)。我真的很困惑。提前致谢
birthwt=birthwt[,-10]
boot=sample(nrow(birthwt), 40)
train.data=birthwt[-boot, ]
test.data=birthwt[boot, ]
x =model.matrix(low~., train.data)[,-1]
y =train.data$low
套索模型:
library(glmnet)
set.seed(123)
cv.lasso = cv.glmnet(x, y, alpha = 1, family = "binomial")
model.lasso=glmnet(x,y,alpha=1,family="binomial",lambda= cv.lasso$lambda.min)
coef(model.lasso)
x.test = model.matrix(low ~., test.data)[,-1]
proba.lasso = predict(model.lasso,newx = x.test)
class.lasso = ifelse(proba.lasso > 0.5, 1, 0)
class.obs = test.data$low