Skip to content

Conversation

KonstantinBurkin
Copy link

@KonstantinBurkin KonstantinBurkin commented Sep 19, 2025

This PR adds documentation to clarify how to use custom objective. Current example of custom objective is implemented using xgb.DMatrix and xgb.train (low-level version). That is not a popular way to use xgboost models. I suggest adding documentation with an example where:

  • objective function is defined with numpy arrays only
  • objective function is used with XGBRegressor model
  • It is stated that objective for XGBRegressor usually accepts vectors in such order: (true_values, predicted_values). Whereas objective for xgb.train expects vectors in such order: (predicted_values, true_values).

@KonstantinBurkin KonstantinBurkin marked this pull request as draft September 19, 2025 14:16
@KonstantinBurkin KonstantinBurkin marked this pull request as ready for review September 19, 2025 15:42
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.

Hi, the dtrain has type DMatrix, it contains the labels, along with other things like weight and qid, feature matrix. It's not the "true value", as it's a container for all data XGBoost consumes. Also, there's a section for the scikit-learn interface along with a demo custom_softmax.py.

@KonstantinBurkin
Copy link
Author

I agree with your statement concerning dtrain type. But I could not find examples with scikit-learn interface. I want to add these examples and mention that the order of arguments is different for this case (predictions, y_test), not (dtrain, predictions).

@trivialfis
Copy link
Member

But I could not find examples with scikit-learn interface.

https://xgboost.readthedocs.io/en/stable/tutorials/custom_metric_obj.html#scikit-learn-interface Next to the section you are modifying. Not elaborate enough, but there's a section. ;-)

order of arguments is different for this case

There shouldn't be an ordering for these parameters. They are different parameters, with different types, there's no ordering for things that are different.

@KonstantinBurkin
Copy link
Author

I found it, thanks! Then I close my PR.

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