fit.keras.src.models.model.Model {keras3} | R Documentation |
Train a model for a fixed number of epochs (dataset iterations).
Description
Train a model for a fixed number of epochs (dataset iterations).
Usage
## S3 method for class 'keras.src.models.model.Model'
fit(
object,
x = NULL,
y = NULL,
...,
batch_size = NULL,
epochs = 1L,
callbacks = NULL,
validation_split = 0,
validation_data = NULL,
shuffle = TRUE,
class_weight = NULL,
sample_weight = NULL,
initial_epoch = 1L,
steps_per_epoch = NULL,
validation_steps = NULL,
validation_batch_size = NULL,
validation_freq = 1L,
verbose = getOption("keras.verbose", default = "auto"),
view_metrics = getOption("keras.view_metrics", default = "auto")
)
Arguments
object |
Keras model object |
x |
Input data. It could be:
|
y |
Target data. Like the input data |
... |
Additional arguments passed on to the model |
batch_size |
Integer or |
epochs |
Integer. Number of epochs to train the model.
An epoch is an iteration over the entire |
callbacks |
List of |
validation_split |
Float between 0 and 1.
Fraction of the training data to be used as validation data.
The model will set apart this fraction of the training data,
will not train on it, and will evaluate
the loss and any model metrics
on this data at the end of each epoch.
The validation data is selected from the last samples
in the |
validation_data |
Data on which to evaluate
the loss and any model metrics at the end of each epoch.
The model will not be trained on this data. Thus, note the fact
that the validation loss of data provided using
|
shuffle |
Boolean, whether to shuffle the training data
before each epoch. This argument is
ignored when |
class_weight |
Optional named list mapping class indices (integers, 0-based)
to a weight (float) value, used for weighting the loss function
(during training only).
This can be useful to tell the model to
"pay more attention" to samples from
an under-represented class. When |
sample_weight |
Optional array of weights for
the training samples, used for weighting the loss function
(during training only). You can either pass a flat (1D)
array/vector with the same length as the input samples
(1:1 mapping between weights and samples),
or in the case of temporal data,
you can pass a 2D array (matrix) with shape
|
initial_epoch |
Integer. Epoch at which to start training (useful for resuming a previous training run). |
steps_per_epoch |
Integer or |
validation_steps |
Only relevant if |
validation_batch_size |
Integer or |
validation_freq |
Only relevant if validation data is provided.
Specifies how many training epochs to run
before a new validation run is performed,
e.g. |
verbose |
|
view_metrics |
View realtime plot of training metrics (by epoch). The
default ( |
Details
Unpacking behavior for iterator-like inputs:
A common pattern is to pass an iterator like object such as a
tf.data.Dataset
or a generator to fit()
,
which will in fact yield not only features (x
)
but optionally targets (y
) and sample weights (sample_weight
).
Keras requires that the output of such iterator-likes be
unambiguous. The iterator should return a tuple()
of length 1, 2, or 3, where the optional second and third elements
will be used for y
and sample_weight
respectively.
Any other type provided will be wrapped in
a length-one tuple()
, effectively treating everything as x
. When
yielding named lists, they should still adhere to the top-level tuple
structure,
e.g. tuple(list(x0 = x0, x = x1), y)
. Keras will not attempt to separate
features, targets, and weights from the keys of a single dict.
Value
A keras_training_history
object, which is a named list:
list(params = <params>, metrics = <metrics>")
, with S3 methods
print()
, plot()
, and as.data.frame()
. The metrics
field is
a record of training loss values and metrics values
at successive epochs, as well as validation loss values
and validation metrics values (if applicable).