View source: R/generic_sequential_fit.R
| generic_sequential_fit | R Documentation |
This function serves as the internal engine for fitting kerasnip models that
are based on the Keras sequential API. It is not intended to be called
directly by the user. The function is invoked by parsnip::fit() when a
kerasnip sequential model specification is used.
generic_sequential_fit(formula, data, layer_blocks, ...)
formula |
A formula specifying the predictor and outcome variables,
passed down from the |
data |
A data frame containing the training data, passed down from the
|
layer_blocks |
A named list of layer block functions. This is passed
internally from the |
... |
Additional arguments passed down from the model specification. These can include:
|
Generic Fitting Function for Sequential Keras Models
The function orchestrates the three main steps of the model fitting process:
Build and Compile: It calls
build_and_compile_sequential_model() to construct the Keras model
architecture based on the provided layer_blocks and hyperparameters.
Process Data: It preprocesses the input (x) and output (y)
data into the format expected by Keras.
Fit Model: It calls keras3::fit() with the compiled model
and processed data, passing along any fitting-specific arguments (e.g.,
epochs, batch_size, callbacks).
A list containing the fitted model and other metadata. This list is
stored in the fit slot of the parsnip model fit object. The list
contains the following elements:
fit: The raw, fitted Keras model object.
history: The Keras training history object.
lvl: A character vector of the outcome factor levels (for
classification) or NULL (for regression).
# This function is not called directly by users.
# It is called internally by `parsnip::fit()`.
# For example:
library(parsnip)
# create_keras_sequential_spec(...) defines my_sequential_model
# spec <- my_sequential_model(hidden_1_units = 128, fit_epochs = 10) |>
# set_engine("keras")
# # This call to fit() would invoke generic_sequential_fit() internally
# fitted_model <- fit(spec, y ~ x, data = training_data)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.