dmlc / dmlc/xgboost

[R] multiclass predictions: change default to `reshape = TRUE`?

Open
#9,640 2 comments 0 reactions 0 assignees View on GitHub
feature-request
Dominant language
C++
Stars
28.8k
Forks
8.9k
Avg merge
1d 12h
Merged PRs (30d)
54

Description

Similar to: https://github.com/microsoft/LightGBM/issues/6131

Probabilistic multiclass prediction in R returns a vector with $m \times n$ values, where $n$ is the number of observations, and $m$ the number of classes.

Setting `predict(..., reshape = TRUE)` gives the much more intuitive $n \times m$ matrix.

Changing defaults is not the sexiest thing on earth. Still: would it be possible to change the default to `reshape = TRUE`? I could open a PR with this proposal.

## Example

```r
library(xgboost)

params <- list(objective = "multi:softprob", num_class = 3, learning_rate = 0.2)
X_pred <- data.matrix(iris[, -5])
dtrain <- xgb.DMatrix(X_pred, label = as.integer(iris[, 5]) - 1)

fit <- xgb.train(params = params, data = dtrain, nrounds = 100)

# Current default is unintuitive
predict(fit, head(X_pred, 2))
# Gives: 0.995540798 0.003178120 0.001281114 0.994982302 0.003176337 0.001841350

# IMHO the much better default
predict(fit, head(X_pred, 2), reshape = TRUE)
# Gives:
# [,1] [,2] [,3]
# [1,] 0.9955408 0.003178120 0.001281114
# [2,] 0.9949823 0.003176337 0.001841350
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.