def _update_leaf_value(leaf_val, tree_index, n_class, initial_guess):
    """
    Subtract initial guess from initial tree (tree_index == 0) or first k (no. classes)
        trees for multiclass to be consistent with other modern GBDT implementations.

    Input
        leaf_val: float, non-updated leaf value.
        tree_index: int, boosting iteration.
        n_class: int, no. classes (0 - regression, 2 - binary, >2 - multiclass).
        initial_guess: float or 1d array (mean - regression, class prior - classification).

    Returns leaf value with initial guess subtracted from its value if it is initial tree.
    """

    if n_class <= 2 and tree_index == 0:  # regression or binary
        leaf_val -= initial_guess

    elif n_class > 2 and tree_index < n_class:  # multiclass
        leaf_val -= initial_guess[tree_index]

    return leaf_val