Learn R Programming

cvms (version 0.2.0)

multiclass_probability_tibble: Generate a multiclass probability tibble

Description

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 rowwise.

Usage

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

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 rowwise. This will transform the numbers to probabilities that sum to 1 rowwise.

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.

Examples

Run this code
# NOT RUN {
# 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)

# 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)
# }

Run the code above in your browser using DataLab