tf2xgb
- tf2xgb.tf2xgb.xgb_tf_loss(ragged_nested_index_lists, target)
Decorator of custom TensorFlow pooling&loss function
tf_loss_fn. It produces the custom objective function, which is input to XGBoost.Decorated function: TensorFlow function with two numpy array inputs: 1D target with shape (#groups) and multidimensional predictions with the first dimension of length #groups. This function internally performs pooling of predictions to the 1D shape (#groups), compares them with target and returns a scalar loss value. This output reflects MEAN of losses, which is the output of e.g.
tf.keras.losses.mean_squared_error(). The MEAN is translated to SUM later in this function because of the compatibility with XGB custom objective function.IMPORTANT: Missing values in the multidimensional predictions are denoted by np.nan and have to be taken care of by tf_loss_fn function body. They occur simply because the multidimensional predictions tensor has typically much more elements that the original flat predictions vector from XGBoost.
- Parameters
ragged_nested_index_lists – the nested list of indices to XGB predictions vector; in the example of 2D ragged_nested_index_lists, consider
ragged_nested_index_lists[i, j] = k; this means thatxgb_predictions[k] = predictions_input_to_tf_pooling_and_loss[i, j]target – tensor with group-level targets
- Returns
decorated function
- tf2xgb.tf2xgb.xgb_tf_metric(ragged_nested_index_lists, target)
Decorator of custom pooling metric function. It produces the custom metric function, which measures performance on the aggregate (group) level and can be used as a callback funcition during XGBoost training (e.g. for early stopping).
Decorated function: Function with two numpy array inputs: 1D target with shape (#groups) and multidimensional predictions with the first dimension of length #groups. This function internally performs pooling of predictions to the 1D shape (#groups) and computes a score.
IMPORTANT: Missing values in the multidimensional predictions are denoted by np.nan and have to be taken care of by
xgb_metric_fnfunction body. They occur simply because the multidimensional predictions tensor has typically much more elements that the original flat predictions vector from XGBoost.- Parameters
ragged_nested_index_lists – the nested list of indices to XGB predictions vector; in the example of 2D ragged_nested_index_lists, consider
ragged_nested_index_lists[i, j] = k; this means thatxgb_predictions[k] = predictions_input_to_tf_metric[i, j]target – tensor with group-level targets
- Returns
decorated function