Convert a tabular dataset to a matrix, one-hot encoding factors, if present.
Details
This is a convenience function that uses features(), preprocess(), as.matrix().
Examples
# reorder columns so that we have a categorical feature
x <- set_outcome(iris, "Sepal.Length")
feature_matrix(x) |> head()
#> 2026-02-22 18:59:27
#> One hot encoding Species...
#>
#> ✓
#> [one_hot]
#>
#> 2026-02-22 18:59:27
#> Preprocessing done.
#> [preprocess]
#> Sepal.Width Petal.Length Petal.Width Species_setosa Species_versicolor
#> [1,] 3.5 1.4 0.2 1 0
#> [2,] 3.0 1.4 0.2 1 0
#> [3,] 3.2 1.3 0.2 1 0
#> [4,] 3.1 1.5 0.2 1 0
#> [5,] 3.6 1.4 0.2 1 0
#> [6,] 3.9 1.7 0.4 1 0
#> Species_virginica
#> [1,] 0
#> [2,] 0
#> [3,] 0
#> [4,] 0
#> [5,] 0
#> [6,] 0