Code Monkey home page Code Monkey logo

Comments (4)

david-cortes avatar david-cortes commented on May 20, 2024

Additionally:

  • If the end of the slice (which is not included in the output) goes past the number of rounds in the model, regardless of what's the last number that the sequence would involve, it will throw an out-of-bounds error.

Here it has 20 rounds, but cannot slice like this:

import numpy as np, xgboost as xgb
rng = np.random.default_rng(seed=123)
y = rng.standard_normal(size=100)
X = rng.standard_normal(size=(100,10))
dm = xgb.DMatrix(X, y)
model = xgb.train(
    dtrain=dm,
    params={},
    num_boost_round=20
)
model[0:21:3]

Note that this slice would stop at 18, which is within the range of the model's rounds:

np.arange(20)[0:21:3]
array([ 0,  3,  6,  9, 12, 15, 18])
  • When the underlying C function XGBoosterSlice returns code -2 (index out of bound), it will not set a message in XGBGetLastError(). The case above has an error message, but that error is thrown from the python wrapper, not from C++.

from xgboost.

trivialfis avatar trivialfis commented on May 20, 2024

The slicing is not as rich as Python or numpy. We at the time thought this might be a bit over-engineering for a booster class. It seems we should implement the full slicing just for less confusion. The easiest way to do it is just to convert a booster into a list of boosters and then let Python do the rest of the indexing. However, the conversion can be expensive.

from xgboost.

david-cortes avatar david-cortes commented on May 20, 2024

The slicing is not as rich as Python or numpy. We at the time thought this might be a bit over-engineering for a booster class. It seems we should implement the full slicing just for less confusion. The easiest way to do it is just to convert a booster into a list of boosters and then let Python do the rest of the indexing. However, the conversion can be expensive.

I don't think that'd be necessary, since it's possible to e.g. create a sequence with np.arange, slice it using the user' input, and pass those integers as an array instead.

Or, since this functionality is only used in the early stopping callback, could also be possible to remove the 'step' part altogether.

from xgboost.

trivialfis avatar trivialfis commented on May 20, 2024

It's used inside xgboost for early stopping, but outside of xgboost, it's also used for people to explore the individual trees' impact on the final output. There are some quirks in gradient boosting, like the first few trees are usually shallower than the latter trees, sometimes people customize their models for exploratory purposes, sometimes used for extracting a submodel then stacking with other models.

from xgboost.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.