caret modelLookup() in R: Find Tuning Parameters
The modelLookup() function in caret returns a small data frame describing any model's tuning parameters, whether it handles regression or classification, and whether it produces class probabilities. Call it before train() to know exactly which hyperparameters caret will tune.
modelLookup("rf") # one model
modelLookup("glmnet") # model with two tuning params
modelLookup() # every available method
nrow(modelLookup()) # count parameters across all models
unique(modelLookup()$model) # list of model names
subset(modelLookup(), forClass & probModel) # classifiers with probabilities
subset(modelLookup(), forReg & parameter != "parameter") # regression models with tuningNeed explanation? Read on for examples and pitfalls.
What modelLookup() does in one sentence
modelLookup() is caret's model registry index. You pass a method string and it returns a data frame with one row per tuning parameter, plus flags showing whether the model supports regression (forReg), classification (forClass), and class probabilities (probModel). Call it without arguments and you get the same data for every method caret knows.
The point of modelLookup() is reconnaissance. Before you write train(..., method = "gbm", tuneGrid = ...), you need to know which columns the tuneGrid data frame must contain. modelLookup("gbm") tells you in one line.
modelLookup() syntax and arguments
The signature has one required argument and two switches. Most calls use only the first.
modelLookup() accepts a single argument:
model: a character string naming a caret method ("rf","glmnet","xgbTree", etc.). DefaultNULLreturns the registry for every model caret ships.
The returned data frame has six columns:
model: the method string you pass totrain(method = ...).parameter: the tuning parameter name. Use these astuneGridcolumns.label: a human-readable description of the parameter.forReg:TRUEif the model supports regression.forClass:TRUEif the model supports classification.probModel:TRUEif the model can return class probabilities viapredict(type = "prob").
modelLookup() only reads metadata, it does not fit a model. Calls are cheap and have no side effects. You can run it repeatedly inside a loop or a Shiny app without performance concerns.modelLookup() examples by use case
1. Look up one model
The most common call: pass a method string and read the tuning parameters.
Random forest tunes a single parameter, mtry. So tuneGrid must be a data frame with one column named mtry. The forReg and forClass flags say the same model code handles both tasks.
glmnet returns two rows because it tunes alpha (elastic-net mixing) and lambda (regularization strength). The tuneGrid data frame needs both columns.
2. List every available method
Call with no arguments to get the whole registry.
Each row is one tuning parameter, not one model. To count unique models, deduplicate on model.
3. Filter to models that match a task
Subset the registry by the forReg, forClass, and probModel flags to find models for a specific job.
Useful when your downstream code needs predict(type = "prob") for ROC curves or calibration plots. Models without probModel = TRUE can still classify, but only return hard class labels.
modelLookup() with getModelInfo() for a full picture. modelLookup() returns the parameter names; getModelInfo("rf") returns the parameter ranges, default values, and the actual fit and predict functions. The two functions are complementary.4. Build a tuneGrid from modelLookup() output
The cleanest workflow uses modelLookup() to fetch the parameter names, then constructs tuneGrid programmatically.
This pattern is robust to model swaps. If you change method = "knn" to method = "kknn", modelLookup() returns three parameters instead of one, and your grid builder adapts without code edits.
modelLookup() vs getModelInfo()
Both functions index caret's model registry, but they answer different questions. Pick by what you need.
| Aspect | modelLookup() |
getModelInfo() |
|---|---|---|
| Return type | Data frame | List of model definitions |
| Information | Parameter names, task flags | Fit, predict, grid, sort logic |
| Common use | Pre-train reconnaissance | Custom model construction |
| Cost | Negligible | Negligible for inspection |
| Regex on model name | No | Yes, via regex = TRUE |
Use modelLookup() when you want a quick table of tuning parameters. Use getModelInfo("rf", regex = FALSE)$rf when you need to read or modify the underlying fit and predict code.
Common pitfalls
modelLookup() returns one row per parameter, not per model. If you write nrow(modelLookup()), you get parameter count (460+), not model count (~238). Always deduplicate on the model column before counting models.
Models with no tuning parameter still appear with a placeholder row. modelLookup("lm") returns one row with parameter = "parameter" and label = "parameter". That single literal row is caret's signal that the model has nothing to tune; do not pass it as a real tuneGrid column.
modelLookup("randomForest") returns an empty data frame because the caret method is "rf", not "randomForest". Always sanity-check with nrow(modelLookup("yourmethod")) > 0 before piping into train().Try it yourself
Try it: Use modelLookup() to list every model that supports both regression and classification probabilities. Save the unique model names to ex_dual_models and print how many there are.
Click to reveal solution
Explanation: Combine the three logical flag columns with &, subset the registry, then deduplicate on model. The result is the set of methods you can drop into train() for either task and still call predict(type = "prob").
Related caret functions
- [
train()](caret-train-in-R.html) consumes the parameter names thatmodelLookup()returns. - [
trainControl()](caret-trainControl-in-R.html) defines the resampling strategy passed alongsidetuneGrid. getModelInfo()returns the full model definition list when you need fit and predict internals.- [
varImp()](caret-varImp-in-R.html) reports variable importance from any modeltrain()produced. - [
confusionMatrix()](caret-confusionMatrix-in-R.html) evaluates classification predictions from those models.
FAQ
How do I find all models caret supports?
Call modelLookup() with no arguments and pull the unique values from the model column: unique(modelLookup()$model). As of caret 6.0-94, the registry holds about 238 methods. The official list at topepo.github.io/caret/available-models.html mirrors this output and adds the source package for each method.
What does forReg mean in modelLookup output?
forReg = TRUE says the same method string handles regression. Some methods support only one task: glm with family = "binomial" is classification-only, while lm is regression-only. Models like "rf", "glmnet", and "xgbTree" flip both flags to TRUE and switch behavior based on the outcome variable's type.
Why does modelLookup("lm") return a row with parameter = "parameter"?
That single literal row is caret's placeholder for models with no tunable hyperparameters. Linear regression has no grid to search, so caret manufactures a stub row to keep the schema consistent. Do not pass that literal "parameter" column to tuneGrid; instead, omit tuneGrid entirely or use tuneLength = 1.
What is the difference between modelLookup and getModelInfo?
modelLookup() returns a tidy data frame describing tuning parameters and task support. getModelInfo() returns a list with the same metadata plus the actual fit, predict, prob, and grid functions caret uses to drive training. Use modelLookup() for inspection; use getModelInfo() when you build a custom method or debug caret's internals.
Can I use modelLookup with custom models?
Yes. If you register a custom model with train(method = my_model_list, ...), modelLookup() will read the parameters element from the list and include it in the output. The list must have parameters as a data frame with columns parameter, class, and label. See ?caret::models or getModelInfo("rf", regex = FALSE)$rf$parameters for the expected structure.