Skip to contents

Replacement for the reference's section 6 target encoding, which computes the rate over every row (validation labels included). Sites unseen in the training rows get the training-wide rate.

Usage

site_baseline_risk(
  df,
  site_col = "site_source",
  label_col = "readmitted_30d",
  train_mask = NULL
)

Arguments

df

Data frame with the site and label columns.

site_col, label_col

Column names.

train_mask

Logical vector selecting training rows (NULL = all rows; only appropriate inside a CV fold).

Value

Numeric vector, one value per row.