Evitare di iterazioni durante il calcolo accuratezza media modello
-
16-10-2019 - |
Domanda
sto adattando un modello in R.
- utilizzare il metodo
createFolds
per creare diverse pieghek
dal set di dati - ciclo tra le pieghe, ripetendo il seguente ad ogni iterazione:
-
train
il modello su k-1 pieghe -
predict
i risultati per l'i-esimo piego - precisione calcolare la previsione
-
- media l'accuratezza
La R ha una funzione che si fa pieghe, ripete il modello di sintonizzazione / previsioni e dà la schiena media accuratezza?
Soluzione
Sì, si può fare tutto questo utilizzando il Caret ( http: // accento circonflesso .r-forge.r-project.org / training.html ) pacchetto in R. Ad esempio,
fitControl <- trainControl(## 10-fold CV
method = "repeatedcv",
number = 10,
## repeated ten times
repeats = 10)
gbmFit1 <- train(Class ~ ., data = training,
method = "gbm",
trControl = fitControl,
## This last option is actually one
## for gbm() that passes through
verbose = FALSE)
gbmFit1
che darà l'uscita ??p>
Stochastic Gradient Boosting
157 samples
60 predictors
2 classes: 'M', 'R'
No pre-processing
Resampling: Cross-Validated (10 fold, repeated 10 times)
Summary of sample sizes: 142, 142, 140, 142, 142, 141, ...
Resampling results across tuning parameters:
interaction.depth n.trees Accuracy Kappa Accuracy SD Kappa SD
1 50 0.8 0.5 0.1 0.2
1 100 0.8 0.6 0.1 0.2
1 200 0.8 0.6 0.09 0.2
2 50 0.8 0.6 0.1 0.2
2 100 0.8 0.6 0.09 0.2
2 200 0.8 0.6 0.1 0.2
3 50 0.8 0.6 0.09 0.2
3 100 0.8 0.6 0.09 0.2
3 200 0.8 0.6 0.08 0.2
Tuning parameter 'shrinkage' was held constant at a value of 0.1
Accuracy was used to select the optimal model using the largest value.
The final values used for the model were n.trees = 150, interaction.depth = 3
and shrinkage = 0.1.
Caret offre molte altre opzioni come bene così dovrebbe essere in grado di soddisfare le vostre esigenze.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a datascience.stackexchange