quantlab.model.predefined.xgb.ccc_objective#

quantlab.model.predefined.xgb.ccc_objective(predt, dtrain)[source]#

Gradient and hessian of the pooled CCC loss for xgb.train(obj=...).

With mse = mean((p - t)^2) and D = var_p + var_t + (mu_p - mu_t)^2 the loss is L = 1 - ccc = mse / D, whose derivative with respect to one prediction is 2 / (n * D) * ((p_i - t_i) - L * (p_i - mu_t)). Both gradient and hessian are multiplied by n, which leaves the optimum unchanged but keeps the Newton steps from being swamped by the L2 regularisation lambda. The exact hessian is dense and its diagonal turns negative when ccc < 0, so the positive constant 2 / D (the curvature of the numerator mse with D held fixed) is used instead.

Each label column is its own pooled loss, so a multi-label DMatrix trains every output on its own CCC. A column whose D is not a positive finite number (for example constant predictions and labels that are equal) gets a zero gradient and a unit hessian for that round.

Parameters:
predtnp.ndarray

The Booster’s current raw predictions for dtrain.

dtrainxgb.DMatrix

The training DMatrix, whose labels are read back. Rows with non-finite labels must already have been dropped.

Returns:
tuple[np.ndarray, np.ndarray]

(grad, hess), each shaped like predt.

Raises:
ValueError

If the label and prediction element counts differ.

Examples

>>> dm = xgb.DMatrix(np.zeros((3, 2)), label=np.array([1.0, 2.0, 3.0]))
>>> grad, hess = ccc_objective(np.array([1.0, 2.0, 3.0]), dm)
>>> grad
array([0., 0., 0.], dtype=float32)