fit: Train a Model

fit.ggml_sequential_modelR Documentation

Train a Model

Description

Trains the model on data for a fixed number of epochs. This is the keras-compatible interface; it delegates to ggml_fit.

Usage

## S3 method for class 'ggml_sequential_model'
fit(
  object,
  x,
  y,
  epochs = 1L,
  batch_size = 32L,
  validation_split = 0,
  validation_data = NULL,
  verbose = 1L,
  shuffle = TRUE,
  callbacks = list(),
  ...
)

## S3 method for class 'ggml_functional_model'
fit(
  object,
  x,
  y,
  epochs = 1L,
  batch_size = 32L,
  validation_split = 0,
  validation_data = NULL,
  verbose = 1L,
  shuffle = TRUE,
  callbacks = list(),
  ...
)

Arguments

object

A compiled model object.

x

Training data. Matrix, array, or list of matrices (multi-input).

y

Training labels (matrix, one-hot encoded for classification).

epochs

Number of training epochs (default 1).

batch_size

Batch size (default 32).

validation_split

Fraction of data for validation (default 0).

validation_data

Optional list(x_val, y_val).

verbose

0 = silent, 1 = progress (default 1).

shuffle

Shuffle the training data (default TRUE, as in keras3). Set to FALSE for time series or exactly reproducible runs.

callbacks

List of callback objects (default list()).

...

Additional arguments passed to ggml_fit.

Value

The trained model (invisibly), with model$history.

Examples


model <- ggml_model_sequential() |>
  ggml_layer_dense(10, activation = "softmax", input_shape = 4)
model <- compile(model, optimizer = "adam",
                 loss = "categorical_crossentropy")
# model <- fit(model, x_train, y_train, epochs = 5, batch_size = 32)


ggmlR documentation built on Oct. 23, 2026, 1:07 a.m.