我在 R 中运行了偏最小二乘法 (PLS),我想提取变量以便我可以运行决策树或随机森林或其他类型的模型。
我试过 pls1$coefficients
# split data into 2 parts for pls training (75%) and prediction (25%)
set.seed(1)
samp <- sample(nrow(newdata), nrow(newdata)*0.75)
analogous.train <- newdata[samp,]
analogous.valid <- newdata[-samp,]
#First use cross validation to find the optimal number of dimensions
pls.model = plsr(meanlog ~ ., data = analogous.train, validation = "CV")
# Find the number of dimensions with lowest cross validation error
cv = RMSEP(pls.model)
best.dims = which.min(cv$val[estimate = "adjCV", , ]) - 1
best.dims
#This told me that 8 dimensions was the best
#Now fit a model with 8 components and includes leave one out cross
#validated predictions
pls1 <- plsr(meanlog ~ ., ncomp = best.dims, data = analogous.train,
validation = "LOO")
#a fited model is often used to predict the response values of new
#observations.
predict(pls1, ncomp = 8, newdata = analogous.valid)
我想要它创建的实际变量本身。例如,PCA 创建 PC1、PC2 等。我假设(可能不正确)PLS 也是如此。