cost.curves: Plot Cost Curves

cost.curvesR Documentation

Plot Cost Curves

Description

This function plots Cost Curves of several classification predictions.

Usage

cost.curves(
  predictions,
  gt,
  methods.names = NULL,
  positive = levels(factor(gt))[1],
  type = c("auto", "fuzzy", "hard"),
  ...
)

Arguments

predictions

The predictions of one or several classification models. Four shapes are accepted: a factor of hard labels (one model); a numeric vector of scores for the positive class (one model); a matrix of class probabilities, i.e. one column per class named after it, as returned by predict (model, x, fuzzy = TRUE) (one model); or any other matrix/data.frame, read as one column per model.

gt

Actual labels of the dataset (factor or vector), two classes only.

methods.names

The name of the compared methods (vector).

positive

The label of the positive class. Defaults to the first level of gt, as everywhere else in the package – note that for the usual alphabetical ordering this is often the negative class, so it is worth setting explicitly.

type

"auto" (default) reads predictions according to its shape, "fuzzy" requires scores and refuses hard labels, "hard" reduces everything to the predicted class first (this is the coarse three-point curve discussed above).

...

Other parameters, passed to the underlying plot.

Value

Nothing; the curves are drawn on the current graphics device.

See Also

roc.curves, performance

Examples

require (datasets)
data (iris)
d = iris
levels (d [, 5]) = c ("+", "+", "-") # Building a two classes dataset
model.nb = NB (d [, -5], d [, 5])
model.lda = LDA (d [, -5], d [, 5])
# From the estimated probabilities (the meaningful version)
cost.curves (predict (model.nb, d [, -5], fuzzy = TRUE), d [, 5])
# From hard labels, for comparison
cost.curves (cbind (predict (model.nb, d [, -5]), predict (model.lda, d [, -5])),
             d [, 5], c ("NB", "LDA"), type = "hard")

fdm2id documentation built on Aug. 28, 2026, 9:07 a.m.