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.
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)
Examples
# Attach cvmslibrary(cvms)# Create a tibble with 5 classes and 10 observations# Apply softmax to make sure the probabilities sum to 1multiclass_probability_tibble( num_classes =5, num_observations =10, apply_softmax =TRUE)# Using the rnorm function to generate the random numbersmulticlass_probability_tibble( num_classes =5, num_observations =10, apply_softmax =TRUE, FUN = rnorm
)# Add targets and predicted classesmulticlass_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" predictionsrcertain <-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
)