我正在使用的数据集可以在线获得。它是一个包含569个观察值和32个变量的数据集。第一列是使用者ID,第二列是实例类别的标签;即M(恶性肿瘤)或B(良性肿瘤)。以下30个属性是实值输入特征(预测变量),根据乳房质量的细针抽吸物(FNA)的数字化图像计算得出。数据集中有357个良性实例和212个恶性实例。
cancerdata <- read.csv("http://archive.ics.uci.edu/ml/machine-learning-databases/breast-cancer-wisconsin/wdbc.data",head=FALSE)
我已经使用以下代码将数据集分为训练和测试集。
set.seed(1245)
#Split the data into a training set and a test set by randomly selecting 119 observations/instances in your test set.
sample.size <- floor(0.79086116 * nrow(cancerdata))
train.index <- sample(seq_len(nrow(cancerdata)), size = sample.size)
train.set <- cancerdata[train.index,]
test.set <- cancerdata[-train.index,]
我很难理解的是,对于具有30个预测变量的数据集,我将如何使用LASSO进行10倍交叉验证。过去我使用过:
cv.lasso <- cv.glmnet(train_set$x2, train_set$y, type.measure="mse", nfolds=10, alpha=1)
但是根据此数据集,有30个预测变量,因此x可以取30个值。有什么办法吗?我是否需要创建一个包含所有变量的模型,然后进行交叉验证?