adapted from victoriarollison.com
Methode | Beschreibung |
k-fold cross-validation |
Trennt die Daten in k-Teile, verwendet |
Bootstrap |
Über B Bootstrap Runden ziehe |
Methode | Beschreibung |
k-fold cross-validation |
Trennt die Daten in k-Teile, verwendet |
Bootstrap |
Über B Bootstrap Runden ziehe |
Methode | Beschreibung |
k-fold cross-validation |
Trennt die Daten in k-Teile, verwendet |
Bootstrap |
Über B Bootstrap Runden ziehe |
Regularizedloss=n∑i(yi−ˆyi)2+λp∑jf(βj))
Name | Funktion | Strafe |
Lasso | |βj| |
Proportional zu den |
Ridge | βj2 |
Proportional zu den |
Elastic net | |βj| + βj2 | Summe von Lasso und Ridge. |
from mallorcazeitung.es
Parameter | Beschreibung |
|
Regression mit Lasso Regularisierung. |
|
Regression mut Ridge Regularisierung. |
|
Gewicht der Regularisierung. |
# Trainiere ridge regressiontrain(form = einkommen ~ ., data = basel, method = "glmnet", trControl = ctrl, tuneGrid = expand.grid(alpha = 0, # Ridge lambda = 1)) # Lambda# Trainiere lasso regressiontrain(form = einkommen ~ ., data = basel, method = "glmnet", trControl = ctrl, tuneGrid = expand.grid(alpha = 1, # Lasso lambda = 1)) # Lambda
Loss=Impurity+cp∗(nterminalnodes)
Parameter | Beschreibung |
Niedriger |
Niedrige Strafe, die zu |
Hoher |
Hohe Strafe, die zu |
Loss=Impurity+cp∗(nterminalnodes)
Parameter | Beschreibung |
Niedriger |
Niedrige Strafe, die zu |
Hoher |
Hohe Strafe, die zu |
# Decision Tree mit cp = .01train(form = einkommen ~ ., data = basel, method = "rpart", trControl = ctrl, tuneGrid = expand.grid(cp = .01))# Decision Tree mit cp = .2train(form = einkommen ~ ., data = basel, method = "rpart", trControl = ctrl, tuneGrid = expand.grid(cp = .2))
Parameter | Beschreibung |
Niedriges |
|
Hohes |
|
Parameter | Beschreibung |
Niedriges |
|
Hohes |
|
# Random forest mit mtry = 2train(form = einkommen ~ ., data = basel, method = "rf", trControl = ctrl, tuneGrid = expand.grid(mtry = 2)) # Random forest mit mtry = 5train(form = einkommen ~ ., data = basel, method = "rf", trControl = ctrl, tuneGrid = expand.grid(mtry = 5))
Argument | Beschreibung |
|
Die Resampling Methode; verwende cv für Cross Validation. |
|
Die Anzahl der "Folds". |
# Spezifiziere 10-fache Cross Validationctrl_cv <- trainControl(method = "cv", number = 10)# Prädiziere einkommen mit glmnetglmnet_mod <- train(form = einkommen ~ ., data = basel, method = "glmnet", trControl = ctrl_cv)
# Spezifiziere 10-fache Cross Validationctrl_cv <- trainControl(method = "cv", number = 10)# Prädiziere einkommen mit glmnetglmnet_mod <- train(form = einkommen ~ ., data = basel, method = "glmnet", trControl = ctrl_cv, tuneGrid = expand.grid( alpha = c(0, .5, 1), lambda = 1:100))
# Printe Überblickglmnet_mod
At the end...
RMSE was used to select the optimal model using the smallest value.
The final values used for the model were alpha = 1 and lambda = 27.
glmnet 6120 samples 19 predictorNo pre-processingResampling: Cross-Validated (10 fold) Summary of sample sizes: 5506, 5507, 5508, 5509, 5507, 5509, ... Resampling results across tuning parameters: alpha lambda RMSE Rsquared MAE 0.0 1 1054 0.8717 844.0 0.0 2 1054 0.8717 844.0 0.0 3 1054 0.8717 844.0 0.0 4 1054 0.8717 844.0 0.0 5 1054 0.8717 844.0 0.0 6 1054 0.8717 844.0 0.0 7 1054 0.8717 844.0 0.0 8 1054 0.8717 844.0 0.0 9 1054 0.8717 844.0 0.0 10 1054 0.8717 844.0 0.0 11 1054 0.8717 844.0 0.0 12 1054 0.8717 844.0
# Visualisiere Tuningparameter Fehlerkurveplot(glmnet_mod)
At the end...
RMSE was used to select the optimal model using the smallest value.
The final values used for the model were alpha = 1 and lambda = 27.
# Modellparameter unter dem besten Werten# für alpha und lambdacoef(glmnet_mod$finalModel, glmnet_mod$bestTune$lambda)
25 x 1 sparse Matrix of class "dgCMatrix" 1(Intercept) 873.7053id . geschlechtm . alter 108.5944groesse 1.6993gewicht -1.1578bildungobligatorisch -43.2194bildungsek II -77.9362bildungsek III -20.9463konfessionevangelisch-reformiert -7.8896konfessionkatholisch . konfessionkonfessionslos 45.1148konfessionmuslimisch 103.6467kinder 2.3714glueck -209.4458fitness 26.3446essen 2.7141alkohol 25.9812tattoos -16.4525rhein 3.6709datause 0.1059arztbesuche -1.5933wandern -0.1534fasnachtnein . sehhilfenein -0.1204
# Einfaches Modellglm_mod <- train(form = einkommen ~ ., data = basel, method = "glm", trControl = ctrl_cv)# Berechne Performanzen resamples_mod <- resamples( list(glmnet = glmnet_mod, glm = glm_mod))# Zeige Überblicksummary(resamples_mod)
Vergleiche die Vorhersageperformanz mehrerer Modelle mit resamples()
.
Das summary()
des Outputobjekts printet Vorhersage Fehlerstatistiken der Cross Validation während des Trainings. Das ist eine
Call:summary.resamples(object = resamples_mod)Models: glmnet, glm Number of resamples: 10 MAE Min. 1st Qu. Median Mean 3rd Qu. Max. NA'sglmnet 769.4 827.1 836.9 832.1 843.9 880.6 0glm 788.2 813.2 840.3 832.4 849.0 865.0 0RMSE Min. 1st Qu. Median Mean 3rd Qu. Max. NA'sglmnet 957.1 1025 1050 1040 1054 1103 0glm 988.2 1017 1044 1040 1064 1085 0Rsquared Min. 1st Qu. Median Mean 3rd Qu. Max. NA'sglmnet 0.8601 0.8661 0.8720 0.8721 0.8774 0.8854 0glm 0.8558 0.8647 0.8736 0.8719 0.8768 0.8847 0
adapted from victoriarollison.com
Keyboard shortcuts
↑, ←, Pg Up, k | Go to previous slide |
↓, →, Pg Dn, Space, j | Go to next slide |
Home | Go to first slide |
End | Go to last slide |
Number + Return | Go to specific slide |
b / m / f | Toggle blackout / mirrored / fullscreen mode |
c | Clone slideshow |
p | Toggle presenter mode |
t | Restart the presentation timer |
?, h | Toggle this help |
Esc | Back to slideshow |