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] Document handling of indexes #10019

Merged
merged 5 commits into from
Feb 1, 2024

Conversation

david-cortes
Copy link
Contributor

ref #9810

This PR adds some notes about handling of index numbers in R, as requested in previous comment.

Copy link
Member

@trivialfis trivialfis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for writing the document, I think this would be useful to users as well instead of being contributors only.

doc/contrib/coding_guide.rst Outdated Show resolved Hide resolved
- Categorical features are defined in R as a ``factor`` type which encodes with base-1 indexing. When categorical features are passed as R ``factor`` types, the conversion is done automatically to base-0 indexing, but if the user whishes to manually supply categorical features as already-encoded integers, then those integers need to already be in base-0 encoding.
- Categorical labels for DMatrices do not undergo any extra processing - the user must supply base-0 encoded labels.
- A function to retrieve class-specific coefficients when using the linear coefficients history callback takes a class index parameter, which also does not undergo any conversion (i.e. user must pass a base-0 index), in order to match with the label logic - that is, the same class index will refer to the class encoded with that number in the DMatrix ``label`` field.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about evaluation output:

[0]: rmse ...
[1]: rmse ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

- Categorical labels for DMatrices do not undergo any extra processing - the user must supply base-0 encoded labels.
- A function to retrieve class-specific coefficients when using the linear coefficients history callback takes a class index parameter, which also does not undergo any conversion (i.e. user must pass a base-0 index), in order to match with the label logic - that is, the same class index will refer to the class encoded with that number in the DMatrix ``label`` field.

New additions to the R interface that take on indexable elements should be mindful of these conventions and try to mimic R's behavior as much as possible.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about the feature index from the tree plot and JSON model? I think for the JSON model, the output will continue to be 0-based, not sure about what to do with the plot. In addition, the categorical features in tree dump and plot.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added, alongside with other cases that were missing.

david-cortes and others added 2 commits January 31, 2024 19:51
Co-authored-by: Jiaming Yuan <jm.yuan@outlook.com>
@david-cortes
Copy link
Contributor Author

david-cortes commented Jan 31, 2024

Thank you for writing the document, I think this would be useful to users as well instead of being contributors only.

Do you suggest to move this to some other file?

@trivialfis
Copy link
Member

Yes, perhaps somewhere as part of the R document like a vignette since it's quite R-specific; otherwise, creating a new file like doc/index-base. rst also works.

@david-cortes
Copy link
Contributor Author

Yes, perhaps somewhere as part of the R document like a vignette since it's quite R-specific; otherwise, creating a new file like doc/index-base. rst also works.

Moved it to a new file under R-package, but I'm not sure that I specified the RST format correctly.

Also added a few notes about base-0 encodings in the DMatrix docs.

@trivialfis trivialfis merged commit 662854c into dmlc:master Feb 1, 2024
24 of 28 checks passed
@david-cortes
Copy link
Contributor Author

@trivialfis @hcho3 Looks like the docs didn't render correctly, and didn't include this page in the index. I am not familiar with RST format. Could you look into it?
image
image

@trivialfis
Copy link
Member

I will look into it tomorrow night.

@hcho3
Copy link
Collaborator

hcho3 commented Feb 2, 2024

@trivialfis I am looking at this now.

@hcho3
Copy link
Collaborator

hcho3 commented Feb 2, 2024

@david-cortes #10030 should fix the doc.

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

Successfully merging this pull request may close these issues.

3 participants