evaluate: Evaluate a Model

View source: R/keras_api.R

evaluateR Documentation

Evaluate a Model

Description

Generic for computing loss and metrics on test data.

Usage

evaluate(object, ...)

## S3 method for class 'ggml_sequential_model'
evaluate(object, x, y, batch_size = NULL, ...)

## S3 method for class 'ggml_functional_model'
evaluate(object, x, y, batch_size = NULL, ...)

Arguments

object

A trained model object.

...

Additional arguments passed to ggml_evaluate.

x

Test data.

y

Test labels.

batch_size

Batch size. NULL (default) uses 32, as in keras3.

Value

A named list with loss and metric values.

Relationship to the generics package

generics::evaluate declares its first argument as x, so S3 dispatch happens on whatever is bound to x. With the keras3 argument order evaluate(model, x, y) that works positionally, but naming the data explicitly – evaluate(model, x = x, y = y) – binds the *data* to x, dispatches on it, and fails with "no applicable method". Declaring the generic here with object as its first argument fixes that and also resolves the S3 generic/method consistency warning from R CMD check.

The trade-off: attaching both ggmlR and keras3 makes the two evaluate generics mask one another, and the later-attached package wins. Qualify the call (ggmlR::evaluate(...)) if both are loaded. compile() and fit() are unaffected – generics declares those with object first, so they are still re-exported from there.


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