Skip to contents

Defines the learner, its optimizer, learning rate, number of epochs, loss function, and regularisation, as a distinct stage prior to training. With nofit = TRUE (the default here is FALSE) the object is returned without being fitted, enabling batch control of expensive fits.

Usage

morie_ml_model(
  type = c("logistic", "linear"),
  optimizer = c("adam", "gd", "sgd"),
  learning_rate = 0.1,
  epochs = 200L,
  loss = NULL,
  batch_size = 32L,
  l2 = 0,
  tol = 1e-08,
  seed = 42L,
  nofit = FALSE
)

Arguments

type

One of "logistic" (classification) or "linear" (regression). Distinguishes the default loss.

optimizer

One of "gd" (full-batch gradient descent), "sgd" (stochastic minibatch), or "adam".

learning_rate

Step size (default 0.1). Lower values give longer but more stable descent (ML7.4).

epochs

Number of passes over the data (default 200).

loss

Loss name; defaults to "logloss" for logistic and "mse" for linear. Custom losses may be supplied by name in .ml_loss.

batch_size

Minibatch size for "sgd" (default 32).

l2

Ridge (L2) penalty (default 0).

tol

Convergence tolerance on the loss (default 1e-8).

seed

RNG seed.

nofit

If TRUE, morie_ml_train returns the untrained spec.

Value

A morie_ml_model specification.

Examples

morie_ml_model("logistic", optimizer = "adam", epochs = 50)
#> <morie_ml_model>
#>   type=logistic loss=logloss optimizer=adam lr=0.1 epochs=50 l2=0