multiclass_probability_tibble {cvms}R Documentation

Generate a multiclass probability tibble

Description

[Maturing]

Generate a tibble with random numbers containing one column per specified class. When the softmax function is applied, the numbers become probabilities that sum to 1 row-wise. Optionally, add columns with targets and predicted classes.

Usage

multiclass_probability_tibble(
  num_classes,
  num_observations,
  apply_softmax = TRUE,
  FUN = runif,
  class_name = "class_",
  add_predicted_classes = FALSE,
  add_targets = FALSE
)

Arguments

num_classes

The number of classes. Also the number of columns in the tibble.

num_observations

The number of observations. Also the number of rows in the tibble.

apply_softmax

Whether to apply the softmax function row-wise. This will transform the numbers to probabilities that sum to 1 row-wise.

FUN

Function for generating random numbers. The first argument must be the number of random numbers to generate, as no other arguments are supplied.

class_name

The prefix for the column names. The column index is appended.

add_predicted_classes

Whether to add a column with the predicted classes. (Logical)

The class with the highest value is the predicted class.

add_targets

Whether to add a column with randomly selected target classes. (Logical)

Author(s)

Ludvig Renbo Olsen, r-pkgs@ludvigolsen.dk

Examples

# Attach cvms
library(cvms)

# Create a tibble with 5 classes and 10 observations
# Apply softmax to make sure the probabilities sum to 1
multiclass_probability_tibble(
  num_classes = 5,
  num_observations = 10,
  apply_softmax = TRUE
)

# Using the rnorm function to generate the random numbers
multiclass_probability_tibble(
  num_classes = 5,
  num_observations = 10,
  apply_softmax = TRUE,
  FUN = rnorm
)

# Add targets and predicted classes
multiclass_probability_tibble(
  num_classes = 5,
  num_observations = 10,
  apply_softmax = TRUE,
  FUN = rnorm,
  add_predicted_classes = TRUE,
  add_targets = TRUE
)

# Creating a custom generator function that
# exponentiates the numbers to create more "certain" predictions
rcertain <- function(n) {
  (runif(n, min = 1, max = 100)^1.4) / 100
}
multiclass_probability_tibble(
  num_classes = 5,
  num_observations = 10,
  apply_softmax = TRUE,
  FUN = rcertain
)


[Package cvms version 1.3.3 Index]