Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mayer79 opened this issue Oct 8, 2023 · 2 comments
Open

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

mayer79 opened this issue Oct 8, 2023 · 2 comments

Comments

@mayer79
Copy link
Contributor

mayer79 commented Oct 8, 2023

Similar to: microsoft/LightGBM#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

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
@trivialfis
Copy link
Member

Thank you for the suggestion, I think this default makes sense and am happy to make the change.

@jameslamb
Copy link
Contributor

Although I forgot about it... we made the same change in v4.0 of {lightgbm}: microsoft/LightGBM#6131 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants