LoslegenKostenlos loslegen

Fit glmnet with custom trainControl

Now that you have a custom trainControl object, fit a glmnet model to the "don't overfit" dataset. Recall from the video that glmnet is an extension of the generalized linear regression model (or glm) that places constraints on the magnitude of the coefficients to prevent overfitting. This is more commonly known as "penalized" regression modeling and is a very useful technique on datasets with many predictors and few values.

glmnet is capable of fitting two different kinds of penalized models, controlled by the alpha parameter:

  • Ridge regression (or alpha = 0)
  • Lasso regression (or alpha = 1)

You'll now fit a glmnet model to the "don't overfit" dataset using the defaults provided by the caret package.

Diese Übung ist Teil des Kurses

Machine Learning with caret in R

Kurs anzeigen

Anleitung zur Übung

  • Train a glmnet model called model on the overfit data. Use the custom trainControl from the previous exercise (myControl). The variable y is the response variable and all other variables are explanatory variables.
  • Print the model to the console.
  • Use the max() function to find the maximum of the ROC statistic contained somewhere in model[["results"]].

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

# Fit glmnet model: model
model <- train(
  ___, 
  ___,
  method = "glmnet",
  trControl = ___
)

# Print model to console


# Print maximum ROC statistic
Code bearbeiten und ausführen