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

"No covariates found" problem with matrix input #597

Open
nikolausthomsen opened this issue Jan 5, 2022 · 2 comments
Open

"No covariates found" problem with matrix input #597

nikolausthomsen opened this issue Jan 5, 2022 · 2 comments

Comments

@nikolausthomsen
Copy link

nikolausthomsen commented Jan 5, 2022

Hi, many thanks for the ranger package! Is there a way to directly use a matrix as a covariate without colnames? In this version of the package I don't see the solution...

I hope the code explains the issue well. x is a given matrix but without colnames ranger does not accept it.
`

x <- matrix(rnorm(30*2), ncol=2); y <- rnorm(30)
ranger(x=x,y=y)
Error in ranger(x = x, y = y) : Error: No covariates found.
colnames(x)
NULL
colnames(x) <- paste0("x",1:2)
ranger(x=x,y=y)
Ranger result

Call:
ranger(x = x, y = y)

Type: Regression
Number of trees: 500
Sample size: 30
Number of independent variables: 2
Mtry: 1
Target node size: 5
Variable importance mode: none
Splitrule: variance
OOB prediction error (MSE): 1.034131
R squared (OOB): -0.4679862

`

@mnwright
Copy link
Member

Currently, we are relying on the column names to re-identify the correct features during prediction. In principle, we could accept matrices without colnames and just expect the same feature order for prediction.

@SamGG
Copy link

SamGG commented Nov 22, 2023

Thanks for your feedback.

IMHO, ranger would benefit for setting colnames when it's NULL.

As the code of the OP shows it, when no name is provided to columns, there is an error and the code stops.

x <- matrix(rnorm(30*2), ncol=2); y <- rnorm(30)
ranger(x=x,y=y)
Error in ranger(x = x, y = y) : Error: No covariates found.

So, there is no result at all and I don't understand

[we] just expect the same feature order for prediction.

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

No branches or pull requests

3 participants