ordinalgbt.loss =============== .. py:module:: ordinalgbt.loss Functions --------- .. autoapisummary:: ordinalgbt.loss.dec_clip_y_pred ordinalgbt.loss.stack_zeros_ones ordinalgbt.loss.sigmoid ordinalgbt.loss.grad_sigmoid ordinalgbt.loss.hess_sigmoid ordinalgbt.loss.alpha2theta ordinalgbt.loss.theta2alpha ordinalgbt.loss.probas_from_y_pred ordinalgbt.loss.ordinal_logistic_nll ordinalgbt.loss.gradient_ordinal_logistic_nll ordinalgbt.loss.hessian_ordinal_logistic_nll ordinalgbt.loss.lgb_ordinal_loss Module Contents --------------- .. py:function:: dec_clip_y_pred(fun) .. py:function:: stack_zeros_ones(a: numpy.ndarray, only_zeros=False) -> numpy.ndarray Stacks zeroes and ones on the left and rights part of the array Stacks horizontally zeros and ones on the left and right hand side of the array respectively. If only_zeros is true then it only stacks zeros. This is for the gradient which is zero at both ends of the sigmoid. e.g.:: a = [[1,2], [3,4], [5,6]] returns [[0,1,2,1], [0,3,4,1], [0,5,6,1]] :param a: A 2D array to pad with zeroes and ones :type a: np.ndarray :param only_zeros: If true, then it pads with only zeroes :type only_zeros: bool, default False :rtype: np.ndarray .. py:function:: sigmoid(z) -> numpy.ndarray Sigmoid Sigmoid implementation in numpy :param z: :type z: np.ndarray :returns: Sigmoid :rtype: np.ndarray .. py:function:: grad_sigmoid(z) -> numpy.ndarray Gradient Gradient of the sigmoid :param z: :type z: np.ndarray :returns: Gradient of Sigmoid :rtype: np.ndarray .. py:function:: hess_sigmoid(z) -> numpy.ndarray Hessian Hessian of the sigmoid Sigmoid implementation in numpy :param z: :type z: np.ndarray :returns: Hessian of sigmoid :rtype: np.ndarray .. py:function:: alpha2theta(alpha) .. py:function:: theta2alpha(theta) .. py:function:: probas_from_y_pred(y_preds, theta) convers y_preds to probabilities .. py:function:: ordinal_logistic_nll(y_true: numpy.ndarray, y_preds: numpy.ndarray, theta: numpy.ndarray) Ordinal Negative log lilelihood :param y_true: 1-D array with correct labels, starts from 0 and goes up to the number of unique classes minus one (so unique values are 0,1,2 when dealing with three classes) :type y_true: np.ndarray :param y_preds: 1-D array with predictions in latent space :type y_preds: np.ndarray :param theta: thresholds, 1-D array, size is the number of classes minus one. :type theta: np.ndarray :returns: logistic ordinal negative log likelihood :rtype: np.ndarray .. py:function:: gradient_ordinal_logistic_nll(y_true: numpy.ndarray, y_preds: numpy.ndarray, theta: numpy.ndarray) -> numpy.ndarray Gradient of ordinal nll Gradient of the ordinal logistic regression with respect to the predictions :param y_true: 1-D array with correct labels, starts from 0 and goes up to the number of unique classes minus one (so unique values are 0,1,2 when dealing with three classes) :type y_true: np.ndarray :param y_preds: 1-D array with predictions in latent space :type y_preds: np.ndarray :param theta: thresholds, 1-D array, size is the number of classes minus one. :type theta: np.ndarray :returns: Gradient of logistic ordinal negative log likelihood :rtype: np.ndarray .. py:function:: hessian_ordinal_logistic_nll(y_true: numpy.ndarray, y_preds: numpy.ndarray, theta: numpy.ndarray) -> numpy.ndarray Hessian of ordinal nll Hessian of the ordinal logistic regression with respect to the predictions :param y_true: 1-D array with correct labels, starts from 0 and goes up to the number of unique classes minus one (so unique values are 0,1,2 when dealing with three classes) :type y_true: np.ndarray :param y_preds: 1-D array with predictions in latent space :type y_preds: np.ndarray :param theta: thresholds, 1-D array, size is the number of classes minus one. :type theta: np.ndarray :returns: Hessian of logistic ordinal negative log likelihood :rtype: np.ndarray .. py:function:: lgb_ordinal_loss(y_true: numpy.ndarray, y_pred: numpy.ndarray, theta: numpy.ndarray) Ordinal loss for lightgbm use The ordinal loss used in the lightgbm framework. Returns the gradient and hessian of the loss. :param y_true: 1-D array with correct labels, starts from 0 and goes up to the number of unique classes minus one (so unique values are 0,1,2 when dealing with three classes) :type y_true: np.ndarray :param y_preds: 1-D array with predictions in latent space :type y_preds: np.ndarray :param theta: thresholds, 1-D array, size is the number of classes minus one. :type theta: np.ndarray :returns: Gradient and Hessian of logistic ordinal negative log likelihood :rtype: (np.ndarray, np.ndarray)