[−][src]Struct xgboost::Booster
Core model in XGBoost, containing functions for training, evaluating and predicting.
Usually created through the train
function, which
creates and trains a Booster in a single call.
For more fine grained usage, can be created using new
or
new_with_cached_dmats
, then trained by calling
update
or update_custom
in a loop.
Methods
impl Booster
[src]
pub fn new(params: &BoosterParameters) -> XGBResult<Self>
[src]
Create a new Booster model with given parameters.
This model can then be trained using calls to update/boost as appropriate.
The train
function is often a more convenient way of constructing,
training and evaluating a Booster in a single call.
pub fn new_with_cached_dmats(
params: &BoosterParameters,
dmats: &[&DMatrix]
) -> XGBResult<Self>
[src]
params: &BoosterParameters,
dmats: &[&DMatrix]
) -> XGBResult<Self>
Create a new Booster model with given parameters and list of DMatrix to cache.
Cached DMatrix can sometimes be used internally by XGBoost to speed up certain operations.
pub fn save<P: AsRef<Path>>(&self, path: P) -> XGBResult<()>
[src]
Save this Booster as a binary file at given path.
pub fn load<P: AsRef<Path>>(path: P) -> XGBResult<Self>
[src]
Load a Booster from a binary file at given path.
pub fn load_buffer(bytes: &[u8]) -> XGBResult<Self>
[src]
Load a Booster directly from a buffer.
pub fn train(params: &TrainingParameters) -> XGBResult<Self>
[src]
Convenience function for creating/training a new Booster.
This does the following:
-
create a new Booster model with given parameters
-
train the model with given DMatrix
-
print out evaluation results for each training round
-
return trained Booster
params
- training parametersdtrain
- matrix to train Booster withnum_boost_round
- number of training iterationseval_sets
- list of datasets to evaluate after each boosting round
pub fn set_params(&mut self, p: &BoosterParameters) -> XGBResult<()>
[src]
Update this Booster's parameters.
pub fn update(&mut self, dtrain: &DMatrix, iteration: i32) -> XGBResult<()>
[src]
Update this model by training it for one round with given training matrix.
Uses XGBoost's objective function that was specificed in this Booster's learning objective parameters.
dtrain
- matrix to train the model with for a single iterationiteration
- current iteration number
pub fn update_custom(
&mut self,
dtrain: &DMatrix,
objective_fn: fn(_: &[f32], _: &DMatrix) -> (Vec<f32>, Vec<f32>)
) -> XGBResult<()>
[src]
&mut self,
dtrain: &DMatrix,
objective_fn: fn(_: &[f32], _: &DMatrix) -> (Vec<f32>, Vec<f32>)
) -> XGBResult<()>
Update this model by training it for one round with a custom objective function.
pub fn evaluate(&self, dmat: &DMatrix) -> XGBResult<HashMap<String, f32>>
[src]
Evaluate given matrix against this model using metrics defined in this model's parameters.
See parameter::learning::EvaluationMetric for a full list.
Returns a map of evaluation metric name to score.
pub fn get_attribute(&self, key: &str) -> XGBResult<Option<String>>
[src]
Get a string attribute that was previously set for this model.
pub fn set_attribute(&mut self, key: &str, value: &str) -> XGBResult<()>
[src]
Store a string attribute in this model with given key.
pub fn get_attribute_names(&self) -> XGBResult<Vec<String>>
[src]
Get names of all attributes stored in this model. Values can then be fetched with calls to get_attribute
.
pub fn predict(&self, dmat: &DMatrix) -> XGBResult<Vec<f32>>
[src]
Predict results for given data.
Returns an array containing one entry per row in the given data.
pub fn predict_margin(&self, dmat: &DMatrix) -> XGBResult<Vec<f32>>
[src]
Predict margin for given data.
Returns an array containing one entry per row in the given data.
pub fn predict_leaf(
&self,
dmat: &DMatrix
) -> XGBResult<(Vec<f32>, (usize, usize))>
[src]
&self,
dmat: &DMatrix
) -> XGBResult<(Vec<f32>, (usize, usize))>
Get predicted leaf index for each sample in given data.
Returns an array of shape (number of samples, number of trees) as tuple of (data, num_rows).
Note: the leaf index of a tree is unique per tree, so e.g. leaf 1 could be found in both tree 1 and tree 0.
pub fn predict_contributions(
&self,
dmat: &DMatrix
) -> XGBResult<(Vec<f32>, (usize, usize))>
[src]
&self,
dmat: &DMatrix
) -> XGBResult<(Vec<f32>, (usize, usize))>
Get feature contributions (SHAP values) for each prediction.
The sum of all feature contributions is equal to the run untransformed margin value of the prediction.
Returns an array of shape (number of samples, number of features + 1) as a tuple of (data, num_rows). The final column contains the bias term.
pub fn predict_interactions(
&self,
dmat: &DMatrix
) -> XGBResult<(Vec<f32>, (usize, usize, usize))>
[src]
&self,
dmat: &DMatrix
) -> XGBResult<(Vec<f32>, (usize, usize, usize))>
Get SHAP interaction values for each pair of features for each prediction.
The sum of each row (or column) of the interaction values equals the corresponding SHAP
value (from predict_contributions
), and the sum of the entire matrix equals the raw
untransformed margin value of the prediction.
Returns an array of shape (number of samples, number of features + 1, number of features + 1). The final row and column contain the bias terms.
pub fn dump_model(
&self,
with_statistics: bool,
feature_map: Option<&FeatureMap>
) -> XGBResult<String>
[src]
&self,
with_statistics: bool,
feature_map: Option<&FeatureMap>
) -> XGBResult<String>
Get a dump of this model as a string.
with_statistics
- whether to include statistics in output dumpfeature_map
- if given, map feature IDs to feature names from given map
Trait Implementations
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,