metric_tweak | R Documentation |
metric_tweak()
allows you to tweak an existing metric .fn
, giving it a
new .name
and setting new optional argument defaults through ...
. It
is similar to purrr::partial()
, but is designed specifically for yardstick
metrics.
metric_tweak()
is especially useful when constructing a metric_set()
for
tuning with the tune package. After the metric set has been constructed,
there is no way to adjust the value of any optional arguments (such as
beta
in f_meas()
). Using metric_tweak()
, you can set optional arguments
to custom values ahead of time, before they go into the metric set.
metric_tweak(.name, .fn, ...)
.name |
A single string giving the name of the new metric. This will be
used in the |
.fn |
An existing yardstick metric function to tweak. |
... |
Name-value pairs specifying which optional arguments to override and the values to replace them with. Arguments |
The function returned from metric_tweak()
only takes ...
as arguments,
which are passed through to the original .fn
. Passing data
, truth
,
and estimate
through by position should generally be safe, but it is
recommended to pass any other optional arguments through by name to ensure
that they are evaluated correctly.
A tweaked version of .fn
, updated to use new defaults supplied in ...
.
mase12 <- metric_tweak("mase12", mase, m = 12)
# Defaults to `m = 1`
mase(solubility_test, solubility, prediction)
# Updated to use `m = 12`. `mase12()` has this set already.
mase(solubility_test, solubility, prediction, m = 12)
mase12(solubility_test, solubility, prediction)
# This is most useful to set optional argument values ahead of time when
# using a metric set
mase10 <- metric_tweak("mase10", mase, m = 10)
metrics <- metric_set(mase, mase10, mase12)
metrics(solubility_test, solubility, prediction)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.