modeva.models.MoNeuralTreeClassifier#

class modeva.models.MoNeuralTreeClassifier(name: str = None, estimator: MoGLMTreeBoostClassifier = None, feature_names=None, val_ratio=0.2, verbose=False, device=None, random_state=0, nn_temperature=0.0001, nn_lr=0.0001, nn_max_epochs=200, nn_n_epoch_no_change=10, nn_batch_size=200, reg_mono=0.1, mono_sample_size=1000, mono_increasing_list=(), mono_decreasing_list=(), **kwargs)#

A neural network-based classification model that combines GLM trees with monotonicity constraints.

This model first fits a depth-1 boosted GLMTree, converts it to an equivalent neural network, and then fine-tunes the network parameters. It supports monotonicity constraints and provides interpretability through feature effects analysis.

Parameters:
  • name (str, default=None) – Custom identifier for the model instance.

  • estimator (MoGLMTreeBoostRegressor, default=None) – Pre-fitted or unfitted GLMTree regressor for initialization. If None, creates a new instance.

  • feature_names (list of str, default=None) – Names of input features for interpretability.

  • val_ratio (float, default=0.2) – Proportion of data used for validation during training (0 to 1).

  • device (str, default=None) – Computing device for training (‘cpu’, ‘cuda’, etc.).

  • verbose (bool, default=False) – If True, prints training progress and statistics.

  • random_state (int, default=0) – Seed for reproducible random operations.

  • nn_temperature (float, default=0.0001) – Smoothing parameter for neural network activation.

  • nn_lr (float, default=0.001) – Learning rate for neural network optimization.

  • nn_max_epochs (int, default=200) – Maximum number of training epochs.

  • nn_batch_size (int, default=200) – Number of samples per training batch.

  • nn_n_epoch_no_change (int, default=10) – Early stopping patience - number of epochs without improvement.

  • reg_mono (float, default=0.1) – Strength of monotonicity regularization.

  • mono_sample_size (int, default=1000) – Number of random samples for monotonicity regularization.

  • mono_increasing_list (tuple of str, default=()) – Features that should have monotonically increasing relationships.

  • mono_decreasing_list (tuple of str, default=()) – Features that should have monotonically decreasing relationships.

  • **kwargs – Additional parameters passed to MoGLMTreeBoostRegressor.

net_#

The internal Pytorch network object.

Type:

object

calibrate_interval(X, y, alpha=0.1)#

Fit a conformal prediction model to the given data.

This method computes the model’s prediction interval calibrated to the given data.

It computes the calibration quantile based on predicted probabilities for the positive class.

Parameters:
  • X (X : np.ndarray of shape (n_samples, n_features)) – Feature matrix for prediction.

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

  • alpha (float, default=0.1) – Expected miscoverage for the conformal prediction.

Raises:

ValueError – If the model is neither a regressor nor a classifier.:

calibrate_proba(X, y, sample_weight=None, method='sigmoid')#

Fit the calibration method on the model’s predictions.

Parameters:
  • X (np.ndarray of shape (n_samples, n_features)) – Feature matrix for prediction.

  • y (np.ndarray of shape (n_samples, )) – Ground truth labels.

  • sample_weight (array-like, shape (n_samples,), default=None) – Sample weights.

  • method ({'sigmoid', 'isotonic'}, default='sigmoid') –

    The calibration method.

    • ’sigmoid’: Platt’s method, i.e., fit a logistic regression on predicted probabilities and y

    • ’isotonic’: Fit an isotonic regression on predicted probabilities and y.

Returns:

self

Return type:

Calibrated estimator

decision_function(X, calibration: bool = True)#

Computes the decision function for the given input data.

Parameters:
  • X (np.ndarray of shape (n_samples, n_features)) – Feature matrix for prediction.

  • calibration (bool, default=True) – If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.

Returns:

logit_prediction – Array of (calibrated) logit predictions.

Return type:

array, shape (n_samples,) or (n_samples, n_classes)

get_params(deep=True)#

Get parameters for this estimator. :param deep: If True, will return the parameters for this estimator and

contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

mapping of string to any

load(file_name: str)#

Load the model into memory from file system.

Parameters:

file_name (str) – The path and name of the file.

Return type:

estimator object

predict(X, calibration: bool = True)#

Model predictions, calling the child class’s ‘_predict’ method.

Parameters:
  • X (np.ndarray of shape (n_samples, n_features)) – Feature matrix for prediction.

  • calibration (bool, default=True) – If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.

Returns:

np.ndarray

Return type:

The (calibrated) final prediction

predict_interval(X)#

Predict the prediction set for the given data based on the conformal prediction model.

This method computes the model prediction interval (regression) or prediction sets (classification) using conformal prediction.

Parameters:

X (np.ndarray of shape (n_samples, n_features)) – Feature matrix for prediction.

Returns:

np.ndarray – in the format [n_samples, 2] for regressors or a flattened array for classifiers.

Return type:

The lower and upper bounds of the prediction intervals for each sample

Raises:

ValueError – If fit_conformal has not been called to fit the conformal prediction model: before calling this method.

predict_proba(X, calibration: bool = True)#

Predict (calibrated) probabilities for X.

Parameters:
  • X (np.ndarray of shape (n_samples, n_features)) – Feature matrix for prediction.

  • calibration (bool, default=True) – If True, will return calibrated probability if calibration is done. Otherwise, will return raw probability.

Returns:

np.ndarray

Return type:

The (calibrated) predicted probabilities

save(file_name: str)#

Save the model into file system.

Parameters:

file_name (str) – The path and name of the file.

set_params(**params)#

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters:

**params (dict) – Estimator parameters.

Returns:

self – Estimator instance.

Return type:

estimator instance