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

Allow 'mtry' #22

Closed
tslumley opened this issue Mar 16, 2021 · 2 comments
Closed

Allow 'mtry' #22

tslumley opened this issue Mar 16, 2021 · 2 comments
Assignees

Comments

@tslumley
Copy link

Would you be interested in a patch to allow users to adjust mtry? It's a major tuning parameter for random forests, so I think it would help. What I have done is to add a mtry_rule argument, which is a function taking an vector of variable names as input and returning a value of mtry, called with union(v,completed). The current rule is roughly

function(x) floor(sqrt(length(x)-1)))

and I've tried others such as

function(x) min(5, length(x)-1)
@mayer79
Copy link
Owner

mayer79 commented Mar 17, 2021

Your approach is very good. ranger actually already allows mtry to be a function of the number of covariables, so we only have to stick to this one.

E.g.

ranger(Sepal.Length ~ ., data = iris, mtry = function(x) x%/%2) 

gives mtry = 2.

Interestingly, the default passed to the internal C++ interface is mtry=0 and is internally set to something like floor(sqrt(m)). However, an mtry function is not allowed to return 0.

Suggestion 1: We add the argument mtry = NULL and allow only the "function" interface of ranger otherwise.

Suggestion 2: Same but we allow also numeric values for mtry, e.g. 1. When calling ranger, the value is capped from above with the number of covariables. We could mention in the argument description something like "since the number of covariables might change during the process, consider passing a single argument function of the number of covariables, e.g. function(m) = m %/% 3.

@mayer79 mayer79 self-assigned this Mar 19, 2021
@mayer79 mayer79 mentioned this issue Mar 20, 2021
@mayer79
Copy link
Owner

mayer79 commented Mar 20, 2021

Now in master branch.

@mayer79 mayer79 closed this as completed Mar 20, 2021
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

2 participants