LR: Classification using Logistic Regression

LRR Documentation

Classification using Logistic Regression

Description

This function builds a classification model using Logistic Regression.

Usage

LR(
  train,
  labels,
  reg = c("none", "ridge", "lasso", "elastic"),
  lambda = NULL,
  alpha = 0.5,
  nfolds = 10,
  tune = FALSE,
  methodparameters = NULL,
  graph = FALSE,
  seed = NULL,
  ...
)

Arguments

train

The training set (description), as a data.frame.

labels

Class labels of the training set (vector or factor).

reg

The penalty applied to the coefficients, as in LINREG: "none" (the default) fits the plain multinomial logistic regression of multinom, while "ridge" (L2), "lasso" (L1) and "elastic" (a mix of the two, weighted by alpha) fit a penalized one with glmnet. Penalizing is what makes logistic regression usable when the predictors are numerous or strongly correlated, where the unpenalized fit either fails to converge or separates the classes perfectly with unbounded coefficients.

lambda

The grid of penalty strengths searched by cross-validation; the retained value is the one minimising the cross-validated deviance. NULL (the default) lets glmnet derive the grid from the data, which is the recommended choice: a fixed grid reaching very small penalties makes the fit fail to converge on separable data.

alpha

The elastic net mixing parameter, between 0 (ridge) and 1 (lasso). Used by reg = "elastic" only.

nfolds

The number of folds of the cross-validation used to choose lambda.

tune

If true, the function returns parameters instead of a classification model.

methodparameters

Present for interface consistency with performance (which always passes it when fitting a model). Currently unused: LR does not support reusing pre-tuned parameters.

graph

Whether the cross-validation curve used to choose lambda is plotted. Ignored by reg = "none", which has nothing to choose.

seed

A specified seed for random number generation, so that two runs on the same data give the same model. Every learning method accepts it, so that it can be set the same way whatever the method; the deterministic ones simply have nothing to draw and give the same model with or without it.

...

Other parameters.

Value

The classification model.

See Also

multinom, glmnet, LINREG

Examples

require (datasets)
data (iris)
LR (iris [, -5], iris [, 5])

# Penalized variants: same three penalties as LINREG()
d = splitdata (iris, 5, seed = 0)
model = LR (d$train.x, d$train.y, reg = "lasso")
evaluation (predict (model, d$test.x), d$test.y)


fdm2id documentation built on Aug. 28, 2026, 9:07 a.m.