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-package] Cannot pass CSR single-row for prediction #4966

Closed
Tracked by #5153
david-cortes opened this issue Jan 22, 2022 · 5 comments
Closed
Tracked by #5153

[R-package] Cannot pass CSR single-row for prediction #4966

david-cortes opened this issue Jan 22, 2022 · 5 comments

Comments

@david-cortes
Copy link
Contributor

When making predictions on a single row with sparse data, the Python interface for lightgbm allows passing the input as a sparse CSR matrix, and making predictions this way is faster/more efficient than with CSC format when the input is large. The R interface does not allow passing prediction-time inputs in CSR formats (package Matrix has classes dsparseVector and dgRMatrix for that).

@jameslamb
Copy link
Collaborator

Thanks for the report! Are you able to provide a minimal, reproducible example demonstrating this behavior?

And can you elaborate on what "does not allow" means specifically? e.g., is there an error raised, does LightGBM just produce incorrect results, etc.

We're grateful for your reports and happy to try to help resolve these things, but would really appreciate more details so that maintainers don't spend time guessing things that I suspect you already know.

@david-cortes
Copy link
Contributor Author

Reproducible example:

library(lightgbm)
data("mtcars")
ds <- lgb.Dataset(as.matrix(mtcars[, -1]), label=mtcars[,1])
m <- lgb.train(data=ds, obj="regression")

library(Matrix)
m_pred <- as.matrix(mtcars[, -1])
m_pred <- m_pred[1, , drop=FALSE]
x_csc <- as(m_pred, "CsparseMatrix")
x_csr <- as(x_csc, "RsparseMatrix")
x_spv <- as(x_csc, "sparseVector")

predict(m, x_csc) ### fine, but slow
predict(m, x_csr) ### error
predict(m, x_spv) ### error

By "not allows" I mean that it throws errors, because there is no code route to take the input data in those formats.

@jameslamb
Copy link
Collaborator

Excellent, thanks very much for that!

@jameslamb
Copy link
Collaborator

I've added this to #2302, where we document feature requests for this project.

Per this project's policies, I'll close this issue for now. Anyone reading this who is interested in contributing this feature, leave a comment and it can be re-opened.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity since it was closed.
To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues
including a reference to this.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants