DEV Community

Sam Fouad
Sam Fouad

Posted on

Python Pseudocode Critique

I would like to get some critical thoughts about a Psuedocode that I have created lately. Any thoughts?

`
DEFINE CLASS GBDTClassifier(GBDTEstimator):

DEFINE FUNCTION calc_grad(self, y_true: np.ndarray, y_pred: np.ndarray) -> Tuple[np.ndarray, np.ndarray]:

    // (reference) regression_loss.h

    SET y_pred_prob TO 1.0 / (1.0 + np.exp(-y_pred))

    SET eps TO 1e-16

    SET grad TO y_pred_prob - y_true

    SET hess TO np.maximum(y_pred_prob * (1.0 - y_pred_prob), eps)

    RETURN grad, hess

DEFINE FUNCTION predict_proba(self, x: np.ndarray) -> np.ndarray:

    // apply sigmoid

    RETURN 1.0 / (1.0 + np.exp(-self.predict(x)))
Enter fullscreen mode Exit fullscreen mode

`

Top comments (0)