gbnet.models.ordinal_regression

Classes

GBOrd

Gradient Boosting Ordinal Regression model.

OrdinalLogisticLoss

Functions

loadModule(module)

Module Contents

gbnet.models.ordinal_regression.loadModule(module)[source]
class gbnet.models.ordinal_regression.GBOrd(num_classes, nrounds=None, params=None, module_type='LGBModule', min_hess=0.0)[source]

Bases: sklearn.base.BaseEstimator, sklearn.base.ClassifierMixin

Gradient Boosting Ordinal Regression model.

This model combines gradient boosting with ordinal regression to predict ordered categorical outcomes. It uses either XGBoost or LightGBM as the underlying boosting engine wrapped in a PyTorch module.

Parameters:
  • num_classes (int) – Number of ordinal classes to predict

  • nrounds (int, optional) – Number of boosting rounds. Defaults to 500 for XGBModule and 1000 for LGBModule.

  • params (dict, optional) – Additional parameters passed to the gradient boosting model.

  • module_type (str, optional) – Type of gradient boosting module to use, either “XGBModule” or “LGBModule”. Defaults to “LGBModule”.

  • min_hess (float, optional) – Minimum hessian value for numerical stability. Defaults to 0.0.

Variables:
  • model (XGBModule or LGBModule) – Trained gradient boosting module. Set after fitting.

  • losses (list) – List of loss values recorded at each training iteration.

  • min_targets (int) – Minimum value in training targets, used for label normalization.

fit(X, y)[source]

Trains the model using input features X and ordinal targets y.

predict(X)[source]

Predicts ordinal class labels for input features X.

Notes

The model uses an ordinal logistic loss function to handle ordered categorical outcomes. The gradient boosting model learns a single score which is transformed into class probabilities via learned thresholds.

nrounds = None[source]
params = None[source]
model_ = None[source]
losses_ = [][source]
module_type = 'LGBModule'[source]
Module[source]
loss_fn[source]
num_classes[source]
min_hess = 0.0[source]
fit(X, y=None)[source]
score(X, y)[source]

Return the negative log likelihood score for input X and targets y.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – Input features.

  • y (array-like of shape (n_samples,)) – Target values.

Returns:

Negative log likelihood score. Lower values indicate better fit.

Return type:

float

predict_proba(X)[source]

Predict class probabilities for input X.

Parameters:

X (array-like of shape (n_samples, n_features)) – Input features.

Returns:

Predicted class probabilities.

Return type:

array-like of shape (n_samples, n_classes)

predict(X, return_logits=True)[source]

Predict continuous output for input X.

class gbnet.models.ordinal_regression.OrdinalLogisticLoss(num_classes)[source]

Bases: torch.nn.Module

num_classes[source]
breakpoints[source]
_compute_probabilities(logits)[source]

Compute class probabilities

forward(logits, targets)[source]

Compute loss more efficiently but maintaining numerical equivalence.

get_pred_probs(logits)[source]

Predict most likely class.