私は R で作業しており、いくつかの方法を使用して、変数の選択と重み付けにキャレットを使用することを検討しています。ここでは、それぞれの調整パラメーターを使用して、前方段階的最小角度回帰 (LARS) を使用して調査しています。以下のコードでは、従属変数 (y) と予測子のサブセット (x) を任意に選択し、データの 70% のサブセットを使用してトレーニング アルゴリズムを介してそれらを実行しました。そのために、10 分割の交差検証を繰り返し適用しています。私が苦労しているのは、トレーニング関数から派生した最終的なモデル パラメーター (切片、ベータ重みなど) を特定するコマンドを見つけることです。object$finalModel を呼び出すと、すぐにはわかりません。リストされている方法 (順方向ステップワイズ回帰と LARS) を使用して R でこれらを回復する方法はありますか? これはあってしかるべきだと思います……。
ありがとう!
library (caret)
library(AppliedPredictiveModeling)
data(abalone)
str(abalone)
set.seed(18)
inTrain <- sample(1:(round(nrow(abalone)*.7)),replace=FALSE)
train_df <- abalone [inTrain,]
test_df <- abalone [-inTrain,]
#predicting Diameter using several of the dataset's variables#
train_df_x <- train_df [,4:8]
test_df_x <- test_df [,4:8]
y_train <- train_df [,3]
y_test <- test_df [,3]
set.seed(18)
fold.ids <- createMultiFolds(y_train,k=10,times=3)
fitControl <- trainControl(method = "repeatedcv",
number = 10,
repeats = 3,
returnResamp = "final",
index = fold.ids,
summaryFunction = defaultSummary,
selectionFunction = "oneSE")
### Forward regression ###
library(leaps)
forwardLmGrid <- expand.grid (.nvmax=seq(2,5))
set.seed(18)
F_OLS_fit <- train(train_df_x, y_train,"leapForward",trControl = fitControl,metric="RMSE", tuneGrid=forwardLmGrid)
### LARS ###
larGrid <- expand.grid(.fraction=seq(.01,.99,length=50))
library(lars)
Lar_fit <- train(train_df_x, y_train,"lars",trControl = fitControl,metric="RMSE", tuneGrid=larGrid)