Skip to contents

Draw training and validation losses against training progress using a LineConfig. This function accepts an ordinary table and does not require rtemis. Supply a data frame containing its recorded learning curve.

Usage

draw_learning_curve(
  data,
  unit = attr(data, "unit", exact = TRUE),
  selected = attr(data, "selected", exact = TRUE),
  xlab = NULL,
  ylab = "Loss",
  title = NULL,
  theme = NULL,
  width = NULL,
  height = NULL,
  element_id = NULL,
  filename = NULL,
  ...,
  legend_position = "top",
  legend_placement = "outside"
)

Arguments

data

Data frame: Numeric iteration and at least one of loss_training or loss_validation. An optional tree column identifies ensemble members. Iterations must be unique within each tree.

unit

Optional Character: Unit of progress, such as "epochs" or "leaves". Read from the table's unit attribute when omitted. NULL uses "Iteration" for the axis label.

selected

Optional Numeric: Selected step. Read from the table's selected attribute when omitted. NA or NULL means no selected step.

xlab

Optional Character: Horizontal axis label, overriding unit.

ylab

Optional Character: Vertical axis label.

title

Optional Character: Chart title.

theme

Optional Theme: Theme override. Set palette in ... to override its series colors.

width

Optional Character or Numeric: Widget width.

height

Optional Character or Numeric: Widget height.

element_id

Optional Character: Explicit DOM element ID for the widget container. NULL lets htmlwidgets generate one.

filename

Optional Character: If provided, save the widget to this file via save_drawing().

...

Additional appearance and axis arguments to setup_LineConfig(), such as palette, zoom, points, xlim, and margin_top. The data bindings are determined by the loss table.

legend_position

Character {"top", "bottom", "left", "right", "top-left", "top-right", "bottom-left", "bottom-right"}: Legend anchor. Top/bottom anchors use horizontal rows; left/right anchors use a vertical column. Corner anchors align within the top or bottom row.

legend_placement

Character {"outside", "inside"}: Relation to the plotting area. Outside placement reserves space for the complete legend; inside placement overlays the data. Neither setting adds a missing legend.

Value

htmlwidget: ECharts learning curve.

Details

Steps are sorted numerically. With a tree column, losses are averaged at each step over trees with a nonmissing loss for that series. Trees that have stopped contribute no value at later steps. Entirely missing series are omitted; missing values within a series remain gaps.

The selected point uses training loss if that series exists, otherwise validation loss. An absent step or missing loss produces no selected marker. selected = NULL disables it. The marker follows the line config's points setting, so points = FALSE hides it along with the other point symbols.

For another interface, materialize columns iteration, Training, Validation, and optionally Selected (missing except at the selected step), omitting unavailable loss columns. Bind these with setup_LineConfig() using x = "iteration" and y naming the loss columns. Store the unit as xlab. That data and config reproduce the chart without R attributes or a fitted model; aggregation is performed before rendering.

Examples

losses <- data.frame(
  iteration = 1:4,
  loss_training = c(4, 2, 1, 0.5),
  loss_validation = c(4.5, 2.5, 2, 2.2)
)
draw_learning_curve(losses, unit = "epochs", selected = 3)