Interpretable Models

Regression and classification model wrappers available in Modeva.

Regression

class modeva.models.MoElasticNet(name: str = None, feature_names=None, feature_types=None, *args, **kwargs)[source]

A lightweight wrapper of sklearn.linear_model.ElasticNet.

Note that categorical features are preprocessed by one-hot encoding in this wrapper.

Parameters:
namestr, default=None

Identifier for the model instance.

feature_nameslist or None, default=None

The list of feature names.

feature_typeslist or None, default=None

The list of feature types. Available types include “numerical” and “categorical”.

*args

Variable length argument list passed to the underlying ElasticNet model.

**kwargs

Arbitrary keyword arguments passed to the underlying ElasticNet model.

calibrate_interval(X, y, alpha=0.1, max_depth: int = 5)

Fit a conformal prediction model to the given data.

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

If the model is a regressor, splits the data with 50% for fitting lower (alpha / 5) and upper (1 - alpha / 2) gradient boosting trees-based quantile regression to the model’s residual; and 50% for calibration.

If the model is a binary classifiers, it computes the calibration quantile based on predicted probabilities for the positive class.

Parameters:
XXnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

yarray-like of shape (n_samples, )

Target values.

alphafloat, default=0.1

Expected miscoverage for the conformal prediction.

max_depthint, default=5

Maximum depth of the gradient boosting trees for regression tasks. Only used when task_type is REGRESSION.

Raises:
ValueError: If the model is neither a regressor nor a classifier.
fit(X, y, sample_weight=None)[source]

Fits the estimator to the provided data.

Parameters:
Xarray-like, shape (n_samples, n_features)

Training data.

yarray-like, shape (n_samples,) or (n_samples, n_outputs)

Target values.

sample_weightarray-like, shape (n_samples,), optional

Sample weights.

Returns:
selfobject

Fitted model instance.

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)[source]

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

load(file_name: str)

Load the model into memory from file system.

Parameters:
file_name: str

The path and name of the file.

Returns:
estimator object
predict(X)

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

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The (calibrated) final prediction
predict_interval(X)

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

It splits the data with 50% for fitting lower (alpha / 5) and upper (1 - alpha / 2) gradient boosting trees-based quantile regression to the model’s residual; and 50% for calibration.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The lower and upper bounds of the prediction intervals for each sample

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

Raises:
ValueError: If fit_conformal has not been called to fit the conformal prediction model

before calling this method.

save(file_name: str)

Save the model into file system.

Parameters:
file_name: str

The path and name of the file.

score(X, y, sample_weight=None)

Return the coefficient of determination of the prediction.

The coefficient of determination \(R^2\) is defined as \((1 - \frac{u}{v})\), where \(u\) is the residual sum of squares ((y_true - y_pred)** 2).sum() and \(v\) is the total sum of squares ((y_true - y_true.mean()) ** 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a \(R^2\) score of 0.0.

Parameters:
Xarray-like of shape (n_samples, n_features)

Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape (n_samples, n_samples_fitted), where n_samples_fitted is the number of samples used in the fitting for the estimator.

yarray-like of shape (n_samples,) or (n_samples, n_outputs)

True values for X.

sample_weightarray-like of shape (n_samples,), default=None

Sample weights.

Returns:
scorefloat

\(R^2\) of self.predict(X) w.r.t. y.

Notes

The \(R^2\) score used when calling score on a regressor uses multioutput='uniform_average' from version 0.23 to keep consistent with default value of r2_score(). This influences the score method of all the multioutput regressors (except for MultiOutputRegressor).

set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoElasticNet

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in fit.

Returns:
selfobject

The updated object.

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:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance
set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoElasticNet

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in score.

Returns:
selfobject

The updated object.

class modeva.models.MoDecisionTreeRegressor(name: str = None, *args, **kwargs)[source]

A lightweight wrapper of sklearn.tree.DecisionTreeRegressor.

Parameters:
namestr, default=None

Identifier for the model instance.

*args

Variable length argument list passed to the underlying DecisionTreeRegressor model.

**kwargs

Arbitrary keyword arguments passed to the underlying DecisionTreeRegressor model.

calibrate_interval(X, y, alpha=0.1, max_depth: int = 5)

Fit a conformal prediction model to the given data.

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

If the model is a regressor, splits the data with 50% for fitting lower (alpha / 5) and upper (1 - alpha / 2) gradient boosting trees-based quantile regression to the model’s residual; and 50% for calibration.

If the model is a binary classifiers, it computes the calibration quantile based on predicted probabilities for the positive class.

Parameters:
XXnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

yarray-like of shape (n_samples, )

Target values.

alphafloat, default=0.1

Expected miscoverage for the conformal prediction.

max_depthint, default=5

Maximum depth of the gradient boosting trees for regression tasks. Only used when task_type is REGRESSION.

Raises:
ValueError: If the model is neither a regressor nor a classifier.
fit(X, y, sample_weight=None, **kwargs)

Fits the estimator to the provided data.

Parameters:
Xarray-like, shape (n_samples, n_features)

Training data.

yarray-like, shape (n_samples,) or (n_samples, n_outputs)

Target values.

sample_weightarray-like, shape (n_samples,), default=None

Sample weights.

Returns:
selfobject

Fitted model instance.

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)[source]

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

interpret(dataset)[source]

Interpret the decision tree with given dataset.

Parameters:
datasetDataSet instance

The dataset for interpreting the model.

Returns:
An instance of InterpretDecisionTree
load(file_name: str)

Load the model into memory from file system.

Parameters:
file_name: str

The path and name of the file.

Returns:
estimator object
predict(X)

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

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The (calibrated) final prediction
predict_interval(X)

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

It splits the data with 50% for fitting lower (alpha / 5) and upper (1 - alpha / 2) gradient boosting trees-based quantile regression to the model’s residual; and 50% for calibration.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The lower and upper bounds of the prediction intervals for each sample

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

Raises:
ValueError: If fit_conformal has not been called to fit the conformal prediction model

before calling this method.

save(file_name: str)

Save the model into file system.

Parameters:
file_name: str

The path and name of the file.

score(X, y, sample_weight=None)

Return the coefficient of determination of the prediction.

The coefficient of determination \(R^2\) is defined as \((1 - \frac{u}{v})\), where \(u\) is the residual sum of squares ((y_true - y_pred)** 2).sum() and \(v\) is the total sum of squares ((y_true - y_true.mean()) ** 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a \(R^2\) score of 0.0.

Parameters:
Xarray-like of shape (n_samples, n_features)

Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape (n_samples, n_samples_fitted), where n_samples_fitted is the number of samples used in the fitting for the estimator.

yarray-like of shape (n_samples,) or (n_samples, n_outputs)

True values for X.

sample_weightarray-like of shape (n_samples,), default=None

Sample weights.

Returns:
scorefloat

\(R^2\) of self.predict(X) w.r.t. y.

Notes

The \(R^2\) score used when calling score on a regressor uses multioutput='uniform_average' from version 0.23 to keep consistent with default value of r2_score(). This influences the score method of all the multioutput regressors (except for MultiOutputRegressor).

set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoDecisionTreeRegressor

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in fit.

Returns:
selfobject

The updated object.

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:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance
set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoDecisionTreeRegressor

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in score.

Returns:
selfobject

The updated object.

class modeva.models.MoRandomForestRegressor(name: str = None, *args, **kwargs)[source]

A lightweight wrapper of sklearn.ensemble.RandomForestRegressor.

Parameters:
namestr, default=None

Identifier for the model instance.

*args

Variable length argument list passed to the underlying RandomForestRegressor model.

**kwargs

Arbitrary keyword arguments passed to the underlying RandomForestRegressor model.

calibrate_interval(X, y, alpha=0.1, max_depth: int = 5)

Fit a conformal prediction model to the given data.

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

If the model is a regressor, splits the data with 50% for fitting lower (alpha / 5) and upper (1 - alpha / 2) gradient boosting trees-based quantile regression to the model’s residual; and 50% for calibration.

If the model is a binary classifiers, it computes the calibration quantile based on predicted probabilities for the positive class.

Parameters:
XXnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

yarray-like of shape (n_samples, )

Target values.

alphafloat, default=0.1

Expected miscoverage for the conformal prediction.

max_depthint, default=5

Maximum depth of the gradient boosting trees for regression tasks. Only used when task_type is REGRESSION.

Raises:
ValueError: If the model is neither a regressor nor a classifier.
extract_model_info(X, feature_names, feature_types)

Extract the tree information as functional ANOVA format.

Parameters:
Xarray-like

Input features.

feature_names: list of str

The feature names.

feature_types: list of str

The feature types.

fit(X, y, sample_weight=None, **kwargs)

Fits the estimator to the provided data.

Parameters:
Xarray-like, shape (n_samples, n_features)

Training data.

yarray-like, shape (n_samples,) or (n_samples, n_outputs)

Target values.

sample_weightarray-like, shape (n_samples,), default=None

Sample weights.

Returns:
selfobject

Fitted model instance.

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)[source]

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

interpret(dataset)

Interpret the ensemble tree model with given dataset using functional ANOVA framework.

Parameters:
datasetDataSet instance

The dataset for interpreting the model.

Returns:
An instance of InterpretFANOVA
load(file_name: str)

Load the model into memory from file system.

Parameters:
file_name: str

The path and name of the file.

Returns:
estimator object
predict(X)

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

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The (calibrated) final prediction
predict_interval(X)

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

It splits the data with 50% for fitting lower (alpha / 5) and upper (1 - alpha / 2) gradient boosting trees-based quantile regression to the model’s residual; and 50% for calibration.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The lower and upper bounds of the prediction intervals for each sample

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

Raises:
ValueError: If fit_conformal has not been called to fit the conformal prediction model

before calling this method.

save(file_name: str)

Save the model into file system.

Parameters:
file_name: str

The path and name of the file.

score(X, y, sample_weight=None)

Return the coefficient of determination of the prediction.

The coefficient of determination \(R^2\) is defined as \((1 - \frac{u}{v})\), where \(u\) is the residual sum of squares ((y_true - y_pred)** 2).sum() and \(v\) is the total sum of squares ((y_true - y_true.mean()) ** 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a \(R^2\) score of 0.0.

Parameters:
Xarray-like of shape (n_samples, n_features)

Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape (n_samples, n_samples_fitted), where n_samples_fitted is the number of samples used in the fitting for the estimator.

yarray-like of shape (n_samples,) or (n_samples, n_outputs)

True values for X.

sample_weightarray-like of shape (n_samples,), default=None

Sample weights.

Returns:
scorefloat

\(R^2\) of self.predict(X) w.r.t. y.

Notes

The \(R^2\) score used when calling score on a regressor uses multioutput='uniform_average' from version 0.23 to keep consistent with default value of r2_score(). This influences the score method of all the multioutput regressors (except for MultiOutputRegressor).

set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoRandomForestRegressor

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in fit.

Returns:
selfobject

The updated object.

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:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance
set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoRandomForestRegressor

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in score.

Returns:
selfobject

The updated object.

class modeva.models.MoGradientBoostingRegressor(name: str = None, *args, **kwargs)[source]

A lightweight wrapper of sklearn.ensemble.GradientBoostingRegressor.

Parameters:
namestr, default=None

Identifier for the model instance.

*args

Variable length argument list passed to the underlying GradientBoostingRegressor model.

**kwargs

Arbitrary keyword arguments passed to the underlying GradientBoostingRegressor model.

calibrate_interval(X, y, alpha=0.1, max_depth: int = 5)

Fit a conformal prediction model to the given data.

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

If the model is a regressor, splits the data with 50% for fitting lower (alpha / 5) and upper (1 - alpha / 2) gradient boosting trees-based quantile regression to the model’s residual; and 50% for calibration.

If the model is a binary classifiers, it computes the calibration quantile based on predicted probabilities for the positive class.

Parameters:
XXnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

yarray-like of shape (n_samples, )

Target values.

alphafloat, default=0.1

Expected miscoverage for the conformal prediction.

max_depthint, default=5

Maximum depth of the gradient boosting trees for regression tasks. Only used when task_type is REGRESSION.

Raises:
ValueError: If the model is neither a regressor nor a classifier.
extract_model_info(X, feature_names, feature_types)

Extract the tree information as functional ANOVA format.

Parameters:
Xarray-like

Input features.

feature_names: list of str

The feature names.

feature_types: list of str

The feature types.

fit(X, y, sample_weight=None, **kwargs)

Fits the estimator to the provided data.

Parameters:
Xarray-like, shape (n_samples, n_features)

Training data.

yarray-like, shape (n_samples,) or (n_samples, n_outputs)

Target values.

sample_weightarray-like, shape (n_samples,), default=None

Sample weights.

Returns:
selfobject

Fitted model instance.

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)[source]

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

interpret(dataset)

Interpret the ensemble tree model with given dataset using functional ANOVA framework.

Parameters:
datasetDataSet instance

The dataset for interpreting the model.

Returns:
An instance of InterpretFANOVA
load(file_name: str)

Load the model into memory from file system.

Parameters:
file_name: str

The path and name of the file.

Returns:
estimator object
predict(X)

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

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The (calibrated) final prediction
predict_interval(X)

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

It splits the data with 50% for fitting lower (alpha / 5) and upper (1 - alpha / 2) gradient boosting trees-based quantile regression to the model’s residual; and 50% for calibration.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The lower and upper bounds of the prediction intervals for each sample

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

Raises:
ValueError: If fit_conformal has not been called to fit the conformal prediction model

before calling this method.

save(file_name: str)

Save the model into file system.

Parameters:
file_name: str

The path and name of the file.

score(X, y, sample_weight=None)

Return the coefficient of determination of the prediction.

The coefficient of determination \(R^2\) is defined as \((1 - \frac{u}{v})\), where \(u\) is the residual sum of squares ((y_true - y_pred)** 2).sum() and \(v\) is the total sum of squares ((y_true - y_true.mean()) ** 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a \(R^2\) score of 0.0.

Parameters:
Xarray-like of shape (n_samples, n_features)

Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape (n_samples, n_samples_fitted), where n_samples_fitted is the number of samples used in the fitting for the estimator.

yarray-like of shape (n_samples,) or (n_samples, n_outputs)

True values for X.

sample_weightarray-like of shape (n_samples,), default=None

Sample weights.

Returns:
scorefloat

\(R^2\) of self.predict(X) w.r.t. y.

Notes

The \(R^2\) score used when calling score on a regressor uses multioutput='uniform_average' from version 0.23 to keep consistent with default value of r2_score(). This influences the score method of all the multioutput regressors (except for MultiOutputRegressor).

set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoGradientBoostingRegressor

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in fit.

Returns:
selfobject

The updated object.

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:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance
set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoGradientBoostingRegressor

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in score.

Returns:
selfobject

The updated object.

class modeva.models.MoXGBRegressor(name: str = None, *args, **kwargs)[source]

A lightweight wrapper of xgboost.XGBRegressor.

Parameters:
namestr, default=None

Identifier for the model instance.

*args

Variable length argument list passed to the underlying XGBRegressor model.

**kwargs

Arbitrary keyword arguments passed to the underlying XGBRegressor model.

calibrate_interval(X, y, alpha=0.1, max_depth: int = 5)

Fit a conformal prediction model to the given data.

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

If the model is a regressor, splits the data with 50% for fitting lower (alpha / 5) and upper (1 - alpha / 2) gradient boosting trees-based quantile regression to the model’s residual; and 50% for calibration.

If the model is a binary classifiers, it computes the calibration quantile based on predicted probabilities for the positive class.

Parameters:
XXnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

yarray-like of shape (n_samples, )

Target values.

alphafloat, default=0.1

Expected miscoverage for the conformal prediction.

max_depthint, default=5

Maximum depth of the gradient boosting trees for regression tasks. Only used when task_type is REGRESSION.

Raises:
ValueError: If the model is neither a regressor nor a classifier.
extract_model_info(X, feature_names, feature_types)

Extract the tree information as functional ANOVA format.

Parameters:
Xarray-like

Input features.

feature_names: list of str

The feature names.

feature_types: list of str

The feature types.

fit(X, y, sample_weight=None, **kwargs)

Fits the estimator to the provided data.

Parameters:
Xarray-like, shape (n_samples, n_features)

Training data.

yarray-like, shape (n_samples,) or (n_samples, n_outputs)

Target values.

sample_weightarray-like, shape (n_samples,), default=None

Sample weights.

Returns:
selfobject

Fitted model instance.

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)[source]

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

interpret(dataset)

Interpret the ensemble tree model with given dataset using functional ANOVA framework.

Parameters:
datasetDataSet instance

The dataset for interpreting the model.

Returns:
An instance of InterpretFANOVA
load(file_name: str)

Load the model into memory from file system.

Parameters:
file_name: str

The path and name of the file.

Returns:
estimator object
predict(X)

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

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The (calibrated) final prediction
predict_interval(X)

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

It splits the data with 50% for fitting lower (alpha / 5) and upper (1 - alpha / 2) gradient boosting trees-based quantile regression to the model’s residual; and 50% for calibration.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The lower and upper bounds of the prediction intervals for each sample

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

Raises:
ValueError: If fit_conformal has not been called to fit the conformal prediction model

before calling this method.

save(file_name: str)

Save the model into file system.

Parameters:
file_name: str

The path and name of the file.

score(X, y, sample_weight=None)

Return the coefficient of determination of the prediction.

The coefficient of determination \(R^2\) is defined as \((1 - \frac{u}{v})\), where \(u\) is the residual sum of squares ((y_true - y_pred)** 2).sum() and \(v\) is the total sum of squares ((y_true - y_true.mean()) ** 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a \(R^2\) score of 0.0.

Parameters:
Xarray-like of shape (n_samples, n_features)

Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape (n_samples, n_samples_fitted), where n_samples_fitted is the number of samples used in the fitting for the estimator.

yarray-like of shape (n_samples,) or (n_samples, n_outputs)

True values for X.

sample_weightarray-like of shape (n_samples,), default=None

Sample weights.

Returns:
scorefloat

\(R^2\) of self.predict(X) w.r.t. y.

Notes

The \(R^2\) score used when calling score on a regressor uses multioutput='uniform_average' from version 0.23 to keep consistent with default value of r2_score(). This influences the score method of all the multioutput regressors (except for MultiOutputRegressor).

set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoXGBRegressor

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in fit.

Returns:
selfobject

The updated object.

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:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance
set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoXGBRegressor

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in score.

Returns:
selfobject

The updated object.

class modeva.models.MoLGBMRegressor(name: str = None, *args, **kwargs)[source]

A lightweight wrapper of lightgbm.LGBMRegressor.

Parameters:
namestr, default=None

Identifier for the model instance.

*args

Variable length argument list passed to the underlying LGBMRegressor model.

**kwargs

Arbitrary keyword arguments passed to the underlying LGBMRegressor model.

calibrate_interval(X, y, alpha=0.1, max_depth: int = 5)

Fit a conformal prediction model to the given data.

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

If the model is a regressor, splits the data with 50% for fitting lower (alpha / 5) and upper (1 - alpha / 2) gradient boosting trees-based quantile regression to the model’s residual; and 50% for calibration.

If the model is a binary classifiers, it computes the calibration quantile based on predicted probabilities for the positive class.

Parameters:
XXnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

yarray-like of shape (n_samples, )

Target values.

alphafloat, default=0.1

Expected miscoverage for the conformal prediction.

max_depthint, default=5

Maximum depth of the gradient boosting trees for regression tasks. Only used when task_type is REGRESSION.

Raises:
ValueError: If the model is neither a regressor nor a classifier.
extract_model_info(X, feature_names, feature_types)

Extract the tree information as functional ANOVA format.

Parameters:
Xarray-like

Input features.

feature_names: list of str

The feature names.

feature_types: list of str

The feature types.

fit(X, y, sample_weight=None, **kwargs)

Fits the estimator to the provided data.

Parameters:
Xarray-like, shape (n_samples, n_features)

Training data.

yarray-like, shape (n_samples,) or (n_samples, n_outputs)

Target values.

sample_weightarray-like, shape (n_samples,), default=None

Sample weights.

Returns:
selfobject

Fitted model instance.

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)[source]

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

interpret(dataset)

Interpret the ensemble tree model with given dataset using functional ANOVA framework.

Parameters:
datasetDataSet instance

The dataset for interpreting the model.

Returns:
An instance of InterpretFANOVA
load(file_name: str)

Load the model into memory from file system.

Parameters:
file_name: str

The path and name of the file.

Returns:
estimator object
predict(X)

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

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The (calibrated) final prediction
predict_interval(X)

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

It splits the data with 50% for fitting lower (alpha / 5) and upper (1 - alpha / 2) gradient boosting trees-based quantile regression to the model’s residual; and 50% for calibration.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The lower and upper bounds of the prediction intervals for each sample

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

Raises:
ValueError: If fit_conformal has not been called to fit the conformal prediction model

before calling this method.

save(file_name: str)

Save the model into file system.

Parameters:
file_name: str

The path and name of the file.

score(X, y, sample_weight=None)

Return the coefficient of determination of the prediction.

The coefficient of determination \(R^2\) is defined as \((1 - \frac{u}{v})\), where \(u\) is the residual sum of squares ((y_true - y_pred)** 2).sum() and \(v\) is the total sum of squares ((y_true - y_true.mean()) ** 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a \(R^2\) score of 0.0.

Parameters:
Xarray-like of shape (n_samples, n_features)

Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape (n_samples, n_samples_fitted), where n_samples_fitted is the number of samples used in the fitting for the estimator.

yarray-like of shape (n_samples,) or (n_samples, n_outputs)

True values for X.

sample_weightarray-like of shape (n_samples,), default=None

Sample weights.

Returns:
scorefloat

\(R^2\) of self.predict(X) w.r.t. y.

Notes

The \(R^2\) score used when calling score on a regressor uses multioutput='uniform_average' from version 0.23 to keep consistent with default value of r2_score(). This influences the score method of all the multioutput regressors (except for MultiOutputRegressor).

set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoLGBMRegressor

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in fit.

Returns:
selfobject

The updated object.

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:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance
set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoLGBMRegressor

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in score.

Returns:
selfobject

The updated object.

class modeva.models.MoCatBoostRegressor(name: str = None, *args, **kwargs)[source]

A lightweight wrapper of catboost.CatBoostRegressor.

Parameters:
namestr, default=None

Identifier for the model instance.

*args

Variable length argument list passed to the underlying CatBoostRegressor model.

**kwargs

Arbitrary keyword arguments passed to the underlying CatBoostRegressor model.

calibrate_interval(X, y, alpha=0.1, max_depth: int = 5)

Fit a conformal prediction model to the given data.

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

If the model is a regressor, splits the data with 50% for fitting lower (alpha / 5) and upper (1 - alpha / 2) gradient boosting trees-based quantile regression to the model’s residual; and 50% for calibration.

If the model is a binary classifiers, it computes the calibration quantile based on predicted probabilities for the positive class.

Parameters:
XXnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

yarray-like of shape (n_samples, )

Target values.

alphafloat, default=0.1

Expected miscoverage for the conformal prediction.

max_depthint, default=5

Maximum depth of the gradient boosting trees for regression tasks. Only used when task_type is REGRESSION.

Raises:
ValueError: If the model is neither a regressor nor a classifier.
extract_model_info(X, feature_names, feature_types)

Extract the tree information as functional ANOVA format.

Parameters:
Xarray-like

Input features.

feature_names: list of str

The feature names.

feature_types: list of str

The feature types.

fit(X, y, sample_weight=None, **kwargs)

Fits the estimator to the provided data.

Parameters:
Xarray-like, shape (n_samples, n_features)

Training data.

yarray-like, shape (n_samples,) or (n_samples, n_outputs)

Target values.

sample_weightarray-like, shape (n_samples,), default=None

Sample weights.

Returns:
selfobject

Fitted model instance.

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)[source]

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

interpret(dataset)

Interpret the ensemble tree model with given dataset using functional ANOVA framework.

Parameters:
datasetDataSet instance

The dataset for interpreting the model.

Returns:
An instance of InterpretFANOVA
load(file_name: str)

Load the model into memory from file system.

Parameters:
file_name: str

The path and name of the file.

Returns:
estimator object
predict(X)

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

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The (calibrated) final prediction
predict_interval(X)

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

It splits the data with 50% for fitting lower (alpha / 5) and upper (1 - alpha / 2) gradient boosting trees-based quantile regression to the model’s residual; and 50% for calibration.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The lower and upper bounds of the prediction intervals for each sample

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

Raises:
ValueError: If fit_conformal has not been called to fit the conformal prediction model

before calling this method.

save(file_name: str)

Save the model into file system.

Parameters:
file_name: str

The path and name of the file.

score(X, y, sample_weight=None)

Return the coefficient of determination of the prediction.

The coefficient of determination \(R^2\) is defined as \((1 - \frac{u}{v})\), where \(u\) is the residual sum of squares ((y_true - y_pred)** 2).sum() and \(v\) is the total sum of squares ((y_true - y_true.mean()) ** 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a \(R^2\) score of 0.0.

Parameters:
Xarray-like of shape (n_samples, n_features)

Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape (n_samples, n_samples_fitted), where n_samples_fitted is the number of samples used in the fitting for the estimator.

yarray-like of shape (n_samples,) or (n_samples, n_outputs)

True values for X.

sample_weightarray-like of shape (n_samples,), default=None

Sample weights.

Returns:
scorefloat

\(R^2\) of self.predict(X) w.r.t. y.

Notes

The \(R^2\) score used when calling score on a regressor uses multioutput='uniform_average' from version 0.23 to keep consistent with default value of r2_score(). This influences the score method of all the multioutput regressors (except for MultiOutputRegressor).

set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoCatBoostRegressor

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in fit.

Returns:
selfobject

The updated object.

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:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance
set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoCatBoostRegressor

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in score.

Returns:
selfobject

The updated object.

class modeva.models.MoGLMTreeRegressor(name: str = None, max_depth=3, min_samples_leaf=50, min_impurity_decrease=0, split_custom=None, n_screen_grid=1, n_feature_search=10, n_split_grid=20, clip_predict=False, reg_lambda=0.1, simplified=True, random_state=0)[source]

A tree-based model that fits linear regression models in the leaves.

This model recursively partitions the feature space and fits linear regression models in each leaf node. It combines the interpretability of decision trees with the flexibility of linear regression.

Parameters:
namestr, default=None

The name of the model.

max_depthint, default=3

The max number of depth.

min_impurity_decreasefloat, default=0

Minimum impurity decrease when splitting a node.

min_samples_leafint, default=50

Minimum number of samples for constructing a leaf node.

split_customdict, default=None

The custom split points for each feature.

n_screen_gridint, default=1

The number of candidate split points for rough screening.

n_feature_searchint, default=10

The number of candidate features selected by rough screening.

n_split_gridint, default=20

The number of candidate split points for fine-grained search.

reg_lambdafloat, default=0.1

The level of L1 regularization strength.

clip_predictbool, default=False

Whether to clip the prediction results if it is outside the training data prediction.

simplifiedbool, default=True

Whether to use partial linear regression for search the split feature and points.

random_stateint, default=0

Determines random number generation for weights and bias initialization.

Attributes:
tree_object

The internal tree structure.

calibrate_interval(X, y, alpha=0.1, max_depth: int = 5)

Fit a conformal prediction model to the given data.

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

If the model is a regressor, splits the data with 50% for fitting lower (alpha / 5) and upper (1 - alpha / 2) gradient boosting trees-based quantile regression to the model’s residual; and 50% for calibration.

If the model is a binary classifiers, it computes the calibration quantile based on predicted probabilities for the positive class.

Parameters:
XXnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

yarray-like of shape (n_samples, )

Target values.

alphafloat, default=0.1

Expected miscoverage for the conformal prediction.

max_depthint, default=5

Maximum depth of the gradient boosting trees for regression tasks. Only used when task_type is REGRESSION.

Raises:
ValueError: If the model is neither a regressor nor a classifier.
get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

get_raw_output(x)

output

Parameters

xarray-like of shape (n_samples, n_features)

containing the input dataset

Returns

np.ndarray of shape (n_samples,),

load(file_name: str)

Load the model into memory from file system.

Parameters:
file_name: str

The path and name of the file.

Returns:
estimator object
predict(X)

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

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The (calibrated) final prediction
predict_interval(X)

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

It splits the data with 50% for fitting lower (alpha / 5) and upper (1 - alpha / 2) gradient boosting trees-based quantile regression to the model’s residual; and 50% for calibration.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The lower and upper bounds of the prediction intervals for each sample

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

Raises:
ValueError: If fit_conformal has not been called to fit the conformal prediction model

before calling this method.

save(file_name: str)

Save the model into file system.

Parameters:
file_name: str

The path and name of the file.

score(X, y, sample_weight=None)

Return the coefficient of determination of the prediction.

The coefficient of determination \(R^2\) is defined as \((1 - \frac{u}{v})\), where \(u\) is the residual sum of squares ((y_true - y_pred)** 2).sum() and \(v\) is the total sum of squares ((y_true - y_true.mean()) ** 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a \(R^2\) score of 0.0.

Parameters:
Xarray-like of shape (n_samples, n_features)

Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape (n_samples, n_samples_fitted), where n_samples_fitted is the number of samples used in the fitting for the estimator.

yarray-like of shape (n_samples,) or (n_samples, n_outputs)

True values for X.

sample_weightarray-like of shape (n_samples,), default=None

Sample weights.

Returns:
scorefloat

\(R^2\) of self.predict(X) w.r.t. y.

Notes

The \(R^2\) score used when calling score on a regressor uses multioutput='uniform_average' from version 0.23 to keep consistent with default value of r2_score(). This influences the score method of all the multioutput regressors (except for MultiOutputRegressor).

set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoGLMTreeRegressor

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in fit.

Returns:
selfobject

The updated object.

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:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance

Estimator instance.

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoGLMTreeRegressor

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in score.

Returns:
selfobject

The updated object.

class modeva.models.MoGLMTreeBoostRegressor(name: str = None, n_estimators=100, max_depth=1, learning_rate=1.0, n_epoch_no_change=5, min_samples_leaf=50, min_impurity_decrease=0, split_custom=None, n_screen_grid=1, n_feature_search=5, n_split_grid=20, reg_lambda=0.1, clip_predict=False, simplified=True, verbose=False, val_ratio=0.2, random_state=0)[source]

GLMTree Boosting regressor using residual-based boosting.

A gradient boosting regressor that uses GLMTree base models to iteratively fit residuals. Each tree has both linear and non-linear components to capture complex relationships while maintaining interpretability.

Parameters:
namestr, default=None

Model identifier name for reference.

n_estimatorsint, default=100

Number of boosting rounds (trees) to fit.

max_depthint, default=1

Maximum tree depth. Model is most interpretable when depth=1.

learning_ratefloat, default=1.0

Shrinkage rate applied to each tree’s contribution.

n_epoch_no_changeint, default=5

Early stopping rounds - training stops if validation loss doesn’t improve.

min_samples_leafint, default=50

Minimum samples required in a leaf node.

min_impurity_decreasefloat, default=0

Minimum required decrease in impurity to split a node.

split_customdict, default=None

Custom split points specified per feature.

n_screen_gridint, default=1

Grid size for initial split point screening.

n_feature_searchint, default=5

Number of features to consider after screening.

n_split_gridint, default=20

Grid size for fine-grained split point search.

reg_lambdafloat, default=0.1

L1 regularization strength parameter.

clip_predictbool, default=False

Whether to clip predictions to training data range.

simplifiedbool, default=True

Use simplified partial linear regression for splits.

val_ratiofloat, default=0.2

Proportion of data used for validation.

verbosebool, default=False

Whether to print training progress.

random_stateint, default=0

Random seed for reproducibility.

Attributes:
estimators_list

Fitted GLMTree models.

n_features_in_int

Number of input features.

calibrate_interval(X, y, alpha=0.1, max_depth: int = 5)

Fit a conformal prediction model to the given data.

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

If the model is a regressor, splits the data with 50% for fitting lower (alpha / 5) and upper (1 - alpha / 2) gradient boosting trees-based quantile regression to the model’s residual; and 50% for calibration.

If the model is a binary classifiers, it computes the calibration quantile based on predicted probabilities for the positive class.

Parameters:
XXnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

yarray-like of shape (n_samples, )

Target values.

alphafloat, default=0.1

Expected miscoverage for the conformal prediction.

max_depthint, default=5

Maximum depth of the gradient boosting trees for regression tasks. Only used when task_type is REGRESSION.

Raises:
ValueError: If the model is neither a regressor nor a classifier.
fit(X, y, sample_weight=None)

fit the GLMTree Boosting model

Parameters

Xarray-like of shape (n_samples, n_features)

containing the input dataset

yarray-like of shape (n_samples,)

containing target values

sample_weightarray-like of shape (n_samples,)

containing the weight of each sample

Returns

object

self : Estimator instance.

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

get_raw_output(x)

output

Parameters

xarray-like of shape (n_samples, n_features)

containing the input dataset

Returns

np.ndarray of shape (n_samples,),

load(file_name: str)

Load the model into memory from file system.

Parameters:
file_name: str

The path and name of the file.

Returns:
estimator object
predict(X)

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

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The (calibrated) final prediction
predict_interval(X)

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

It splits the data with 50% for fitting lower (alpha / 5) and upper (1 - alpha / 2) gradient boosting trees-based quantile regression to the model’s residual; and 50% for calibration.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The lower and upper bounds of the prediction intervals for each sample

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

Raises:
ValueError: If fit_conformal has not been called to fit the conformal prediction model

before calling this method.

save(file_name: str)

Save the model into file system.

Parameters:
file_name: str

The path and name of the file.

score(X, y, sample_weight=None)

Return the coefficient of determination of the prediction.

The coefficient of determination \(R^2\) is defined as \((1 - \frac{u}{v})\), where \(u\) is the residual sum of squares ((y_true - y_pred)** 2).sum() and \(v\) is the total sum of squares ((y_true - y_true.mean()) ** 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a \(R^2\) score of 0.0.

Parameters:
Xarray-like of shape (n_samples, n_features)

Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape (n_samples, n_samples_fitted), where n_samples_fitted is the number of samples used in the fitting for the estimator.

yarray-like of shape (n_samples,) or (n_samples, n_outputs)

True values for X.

sample_weightarray-like of shape (n_samples,), default=None

Sample weights.

Returns:
scorefloat

\(R^2\) of self.predict(X) w.r.t. y.

Notes

The \(R^2\) score used when calling score on a regressor uses multioutput='uniform_average' from version 0.23 to keep consistent with default value of r2_score(). This influences the score method of all the multioutput regressors (except for MultiOutputRegressor).

set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoGLMTreeBoostRegressor

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in fit.

Returns:
selfobject

The updated object.

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:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance

Estimator instance.

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoGLMTreeBoostRegressor

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in score.

Returns:
selfobject

The updated object.

class modeva.models.MoNeuralTreeRegressor(name: str = None, estimator: MoGLMTreeBoostRegressor = None, val_ratio=0.2, verbose=False, device=None, random_state=0, feature_names=None, 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)[source]

A neural network-based regression 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:
namestr, default=None

Custom identifier for the model instance.

estimatorMoGLMTreeBoostRegressor, default=None

Pre-fitted or unfitted GLMTree regressor for initialization. If None, creates a new instance.

feature_nameslist of str, default=None

Names of input features for interpretability.

val_ratiofloat, default=0.2

Proportion of data used for validation during training (0 to 1).

devicestr, default=None

Computing device for training (‘cpu’, ‘cuda’, etc.).

verbosebool, default=False

If True, prints training progress and statistics.

random_stateint, default=0

Seed for reproducible random operations.

nn_temperaturefloat, default=0.0001

Smoothing parameter for neural network activation.

nn_lrfloat, default=0.001

Learning rate for neural network optimization.

nn_max_epochsint, default=200

Maximum number of training epochs.

nn_batch_sizeint, default=200

Number of samples per training batch.

nn_n_epoch_no_changeint, default=10

Early stopping patience - number of epochs without improvement.

reg_monofloat, default=0.1

Strength of monotonicity regularization.

mono_sample_sizeint, default=1000

Number of random samples for monotonicity regularization.

mono_increasing_listtuple of str, default=()

Features that should have monotonically increasing relationships.

mono_decreasing_listtuple of str, default=()

Features that should have monotonically decreasing relationships.

**kwargs

Additional parameters passed to MoGLMTreeBoostRegressor.

Attributes:
net_object

The internal Pytorch network object.

calibrate_interval(X, y, alpha=0.1, max_depth: int = 5)

Fit a conformal prediction model to the given data.

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

If the model is a regressor, splits the data with 50% for fitting lower (alpha / 5) and upper (1 - alpha / 2) gradient boosting trees-based quantile regression to the model’s residual; and 50% for calibration.

If the model is a binary classifiers, it computes the calibration quantile based on predicted probabilities for the positive class.

Parameters:
XXnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

yarray-like of shape (n_samples, )

Target values.

alphafloat, default=0.1

Expected miscoverage for the conformal prediction.

max_depthint, default=5

Maximum depth of the gradient boosting trees for regression tasks. Only used when task_type is REGRESSION.

Raises:
ValueError: If the model is neither a regressor nor a classifier.
certify_mono(n_samples=10000)

Verify if the model satisfies specified monotonicity constraints.

Generates random samples within the feature space and checks if the model’s predictions respect the monotonicity constraints specified during training.

Parameters:
n_samplesint, default=10000

Number of random samples to use for verification.

Returns:
mono_statusbool

True if monotonicity constraints are satisfied, False otherwise.

get_aggregate_output(X)

Returns numpy array of raw prediction.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Data features.

Returns:
prednp.ndarray of shape (n_samples, 1)

numpy array of raw prediction.

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_mono_loss(x, sample_weight=None)

Returns monotonicity loss of given samples.

Parameters:
xnp.ndarray of shape (n_samples, n_features)

Data features.

sample_weightnp.ndarray of shape (n_samples, ), default=None

Sample weight.

Returns:
mono_lossfloat

monotonicity loss.

get_params(deep=True)[source]

Get parameters for this estimator. Parameters ———- deep : bool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns

paramsmapping of string to any

Parameter names mapped to their values.

load(file_name: str)

Load the model into memory from file system.

Parameters:
file_name: str

The path and name of the file.

Returns:
estimator object
predict(X)

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

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The (calibrated) final prediction
predict_interval(X)

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

It splits the data with 50% for fitting lower (alpha / 5) and upper (1 - alpha / 2) gradient boosting trees-based quantile regression to the model’s residual; and 50% for calibration.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The lower and upper bounds of the prediction intervals for each sample

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

Raises:
ValueError: If fit_conformal has not been called to fit the conformal prediction model

before calling this method.

save(file_name: str)

Save the model into file system.

Parameters:
file_name: str

The path and name of the file.

score(X, y, sample_weight=None)

Return the coefficient of determination of the prediction.

The coefficient of determination \(R^2\) is defined as \((1 - \frac{u}{v})\), where \(u\) is the residual sum of squares ((y_true - y_pred)** 2).sum() and \(v\) is the total sum of squares ((y_true - y_true.mean()) ** 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a \(R^2\) score of 0.0.

Parameters:
Xarray-like of shape (n_samples, n_features)

Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape (n_samples, n_samples_fitted), where n_samples_fitted is the number of samples used in the fitting for the estimator.

yarray-like of shape (n_samples,) or (n_samples, n_outputs)

True values for X.

sample_weightarray-like of shape (n_samples,), default=None

Sample weights.

Returns:
scorefloat

\(R^2\) of self.predict(X) w.r.t. y.

Notes

The \(R^2\) score used when calling score on a regressor uses multioutput='uniform_average' from version 0.23 to keep consistent with default value of r2_score(). This influences the score method of all the multioutput regressors (except for MultiOutputRegressor).

set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoNeuralTreeRegressor

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in fit.

Returns:
selfobject

The updated object.

set_params(**params)[source]

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:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance

Estimator instance.

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoNeuralTreeRegressor

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in score.

Returns:
selfobject

The updated object.

class modeva.models.MoGAMINetRegressor(name: str = None, feature_names=None, feature_types=None, interact_num=10, subnet_size_main_effect=(20,), subnet_size_interaction=(20, 20), activation_func='ReLU', max_epochs=(1000, 1000, 1000), learning_rates=(0.001, 0.001, 0.0001), early_stop_thres=('auto', 'auto', 'auto'), batch_size=1000, batch_size_inference=10000, max_iter_per_epoch=100, val_ratio=0.2, warm_start=True, gam_sample_size=5000, mlp_sample_size=1000, heredity=True, reg_clarity=0.1, loss_threshold=0.01, reg_mono=0.1, mono_increasing_list=(), mono_decreasing_list=(), mono_sample_size=1000, include_interaction_list=(), boundary_clip=True, normalize=True, verbose=False, n_jobs=10, device=None, random_state=0)[source]

Generalized additive model with pairwise interaction regressor.

Parameters:
namestr, default=None

The name of the model.

feature_nameslist or None, default=None

The list of feature names. If None, will use “X0”, “X1”, “X2”, etc.

feature_typeslist or None, default=None

The list of feature types. Available types include “numerical” and “categorical”. If None, will use numerical for all features.

interact_numint, default=10

The max number of interactions to be included in the second stage training.

subnet_size_main_effecttuple of int, default=(20, )

The hidden layer architecture of each subnetwork in the main effect block.

subnet_size_interactiontuple of int, default=(20, 20)

The hidden layer architecture of each subnetwork in the interaction block.

activation_func{“ReLU”, “Sigmoid”, “Tanh”}, default=”ReLU”

The name of the activation function.

max_epochstuple of THREE int, default=(1000, 1000, 1000)

The max number of epochs in the first (main effect training), second (interaction training), and third (fine-tuning) stages, respectively.

learning_ratestuple of THREE float, default=(1e-3, 1e-3, 1e-4)

The initial learning rates of Adam optimizer in the first (main effect training), second (interaction training), and third (fine-tuning) stages, respectively.

early_stop_threstuple of THREE int or “auto”, default=[“auto”, “auto”, “auto”]

The early stopping threshold in the first (main effect training), second (interaction training), and third (fine-tuning) stages, respectively. In auto mode, the value is set to max(5, min(5000 * n_features / (max_iter_per_epoch * batch_size), 100)).

batch_sizeint, default=1000

The batch size. Note that it should not be larger than the training size * (1 - validation ratio).

batch_size_inferenceint, default=10000

The batch size used in the inference stage. It is imposed to avoid out-of-memory issue when dealing very large dataset.

max_iter_per_epochint, default=100

The max number of iterations per epoch. In the init stage of model fit, its value will be clipped by min(max_iter_per_epoch, int(sample_size / batch_size)). For each epoch, the data would be reshuffled and only the first “max_iter_per_epoch” batches would be used for training. It is imposed to make the training scalable for very large dataset.

val_ratiofloat, default=0.2

The validation ratio, should be greater than 0 and smaller than 1.

warm_startbool, default=True

Initialize the network by fitting a rough LGBM model. The initialization is performed by, 1) fit a LGBM model as teacher model, 2) generate random samples from the teacher model, 3) fit each subnetwork using the generated samples. And it is used for both main effect and interaction subnetwork initialization.

gam_sample_sizeint, default=5000

The sub-sample size for GAM fitting as warm_start=True.

mlp_sample_sizeint, default=1000

The generated sample size for individual subnetwork fitting as warm_start=True.

hereditybool, default=True

Whether to perform interaction screening subject to heredity constraint.

loss_thresholdfloat, default=0.01

The loss tolerance threshold for selecting fewer main effects or interactions, according to the validation performance. For instance, assume the best validation performance is achieved when using 10 main effects; if only use the top 5 main effects also gives similar validation performance, we could prune the last 5 by setting this parameter to be positive.

reg_clarityfloat, default=0.1

The regularization strength of marginal clarity constraint.

reg_monofloat, default=0.1

The regularization strength of monotonicity constraint.

mono_sample_sizeint, default=1000

As monotonicity constraint is used, we would generate some data points uniformly within the feature space per epoch, to impose the monotonicity regularization in addition to original training samples.

mono_increasing_listtuple of str, default=()

The feature name tuple subject to monotonic increasing constraint.

mono_decreasing_listtuple of str, default=()

The feature name tuple subject to monotonic decreasing constraint.

include_interaction_listtuple of (str, str), default=()

The tuple of interaction to be included for fitting, each interaction is expressed by (feature_name1, feature_name2).

boundary_clipbool, default=True

In the inference stage, whether to clip the feature values by their min and max values in the training data.

normalizebool, default=True

Whether to normalize the data before inputting to the network.

verbosebool, default=False

Whether to output the training logs.

n_jobsint, default=10

The number of cpu cores for parallel computing. -1 means all the available cpus will be used.

devicestring, default=None

The hardware device name used for training.

random_stateint, default=0

The random seed.

Attributes:
net_torch network object

The fitted GAMI-Net module.

interaction_list_list of tuples

The list of feature index pairs (tuple) for each fitted interaction.

active_main_effect_index_list of int

The selected main effect index.

active_interaction_index_list of int

The selected interaction index.

main_effect_val_loss_list of float

The validation loss as the most important main effects are sequentially added.

interaction_val_loss_list of float

The validation loss as the most important interactions are sequentially added.

time_cost_list of tuple

The time cost of each stage.

n_interactions_int

The actual number of interactions used in the fitting stage. It is greater or equal to the number of active interactions.

calibrate_interval(X, y, alpha=0.1, max_depth: int = 5)

Fit a conformal prediction model to the given data.

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

If the model is a regressor, splits the data with 50% for fitting lower (alpha / 5) and upper (1 - alpha / 2) gradient boosting trees-based quantile regression to the model’s residual; and 50% for calibration.

If the model is a binary classifiers, it computes the calibration quantile based on predicted probabilities for the positive class.

Parameters:
XXnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

yarray-like of shape (n_samples, )

Target values.

alphafloat, default=0.1

Expected miscoverage for the conformal prediction.

max_depthint, default=5

Maximum depth of the gradient boosting trees for regression tasks. Only used when task_type is REGRESSION.

Raises:
ValueError: If the model is neither a regressor nor a classifier.
certify_mono(n_samples=10000)

Certify whether monotonicity constraint is satisfied.

Parameters:
n_samplesint, default=10000

Size of random samples for certifying the monotonicity constraint.

Returns:
mono_statusbool

True means monotonicity constraint is satisfied.

fit(X, y, sample_weight=None)[source]

Fits a GAMINet regression model to the training data.

This method trains the model in three stages: main effects training, interaction training, and fine-tuning. It handles data preprocessing, model initialization, and the complete training pipeline.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Training data features.

ynp.ndarray of shape (n_samples,)

Target values for regression.

sample_weightnp.ndarray of shape (n_samples,), default=None

Individual weights for each sample. If None, all samples are weighted equally.

Returns:
selfobject

Returns the fitted estimator.

get_clarity_loss(x, sample_weight=None)

Returns clarity loss of given samples.

Parameters:
xnp.ndarray of shape (n_samples, n_features)

Data features

sample_weightnp.ndarray of shape (n_samples, )

Sample weight.

Returns:
clarity_lossfloat

clarity loss.

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_mono_loss(x, sample_weight=None)

Returns monotonicity loss of given samples.

Parameters:
xnp.ndarray of shape (n_samples, n_features)

Data features.

sample_weightnp.ndarray of shape (n_samples, ), default=None

Sample weight.

Returns:
mono_lossfloat

monotonicity loss.

get_params(deep=True)

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

get_raw_output(x, main_effect=True, interaction=True)

Returns numpy array of raw prediction.

Parameters:
xnp.ndarray of shape (n_samples, n_features)

Data features.

main_effectbool, default=True

Whether to include main effects.

interactionbool, default=True

Whether to include interactions.

Returns:
prednp.ndarray of shape (n_samples, 1)

numpy array of raw prediction.

load(file_name: str)

Load the model into memory from file system.

Parameters:
file_name: str

The path and name of the file.

Returns:
estimator object
predict(X)

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

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The (calibrated) final prediction
predict_effect(fidx, X)

Get the raw prediction of given feature idx.

Parameters:
fidx: tuple of int

The index of features

X: np.ndarray

The input data.

predict_interaction(x)

Returns numpy array of interactions’ raw prediction.

Parameters:
xnp.ndarray of shape (n_samples, n_features)

Data features.

Returns:
prednp.ndarray of shape (n_samples, n_interactions)

numpy array of interactions’ raw prediction.

predict_interval(X)

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

It splits the data with 50% for fitting lower (alpha / 5) and upper (1 - alpha / 2) gradient boosting trees-based quantile regression to the model’s residual; and 50% for calibration.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The lower and upper bounds of the prediction intervals for each sample

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

Raises:
ValueError: If fit_conformal has not been called to fit the conformal prediction model

before calling this method.

predict_main_effect(x)

Returns numpy array of main effects’ raw prediction.

Parameters:
xnp.ndarray of shape (n_samples, n_features)

Data features.

Returns:
prednp.ndarray of shape (n_samples, n_features)

numpy array of main effects’ raw prediction.

save(file_name: str)

Save the model into file system.

Parameters:
file_name: str

The path and name of the file.

score(X, y, sample_weight=None)

Return the coefficient of determination of the prediction.

The coefficient of determination \(R^2\) is defined as \((1 - \frac{u}{v})\), where \(u\) is the residual sum of squares ((y_true - y_pred)** 2).sum() and \(v\) is the total sum of squares ((y_true - y_true.mean()) ** 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a \(R^2\) score of 0.0.

Parameters:
Xarray-like of shape (n_samples, n_features)

Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape (n_samples, n_samples_fitted), where n_samples_fitted is the number of samples used in the fitting for the estimator.

yarray-like of shape (n_samples,) or (n_samples, n_outputs)

True values for X.

sample_weightarray-like of shape (n_samples,), default=None

Sample weights.

Returns:
scorefloat

\(R^2\) of self.predict(X) w.r.t. y.

Notes

The \(R^2\) score used when calling score on a regressor uses multioutput='uniform_average' from version 0.23 to keep consistent with default value of r2_score(). This influences the score method of all the multioutput regressors (except for MultiOutputRegressor).

set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoGAMINetRegressor

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in fit.

Returns:
selfobject

The updated object.

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:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance

Estimator instance.

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoGAMINetRegressor

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in score.

Returns:
selfobject

The updated object.

class modeva.models.MoReLUDNNRegressor(name: str = None, hidden_layer_sizes=(40, 40), max_epochs=1000, learning_rate=0.001, batch_size=500, l1_reg=1e-05, val_ratio=0.2, n_epoch_no_change=20, device=None, n_jobs=10, verbose=False, random_state=0)[source]

A deep neural network regressor using ReLU activation functions.

This model implements a multi-layer neural network for regression tasks, using ReLU activation functions and supporting early stopping, L1 regularization, and batch training.

Parameters:
namestr, default=None

Optional identifier for the model instance.

hidden_layer_sizestuple of int, default=(40, 40)

Architecture of the neural network specified as a tuple of integers, where each integer represents the number of neurons in a hidden layer.

max_epochsint, default=1000

Maximum number of complete passes through the training dataset.

learning_ratefloat, default=0.001

Step size used for gradient updates during optimization.

batch_sizeint, default=500

Number of training samples used in each gradient update.

l1_regfloat, default=1e-5

Strength of L1 regularization applied to model weights.

val_ratiofloat, default=0.2

Proportion of training data to use for validation in early stopping.

n_epoch_no_changeint, default=20

Number of epochs with no improvement after which training will be stopped.

devicestring, default=None

Computing device to use for training (‘cpu’, ‘cuda’, etc.).

n_jobsint, default=10

Number of parallel processes for computation (-1 for using all available cores).

verbosebool, default=False

If True, prints training progress and statistics.

random_stateint, default=0

Seed for reproducible random number generation.

Attributes:
net_torch.nn.Module

Trained neural network model.

train_epoch_loss_list of float

History of training loss values for each epoch.

validation_epoch_loss_list of float

History of validation loss values for each epoch.

calibrate_interval(X, y, alpha=0.1, max_depth: int = 5)

Fit a conformal prediction model to the given data.

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

If the model is a regressor, splits the data with 50% for fitting lower (alpha / 5) and upper (1 - alpha / 2) gradient boosting trees-based quantile regression to the model’s residual; and 50% for calibration.

If the model is a binary classifiers, it computes the calibration quantile based on predicted probabilities for the positive class.

Parameters:
XXnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

yarray-like of shape (n_samples, )

Target values.

alphafloat, default=0.1

Expected miscoverage for the conformal prediction.

max_depthint, default=5

Maximum depth of the gradient boosting trees for regression tasks. Only used when task_type is REGRESSION.

Raises:
ValueError: If the model is neither a regressor nor a classifier.
fit(X, y, sample_weight=None)

Fit ReLuDNN model.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Data features.

ynp.ndarray of shape (n_samples, )

Target response.

sample_weightnp.ndarray of shape (n_samples, ), default=None

Sample weight.

Returns:
selfobject

Fitted Estimator.

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

get_raw_output(X, last_hidden_layer=False)

Returns numpy array of raw predicted value before softmax.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Data features.

last_hidden_layerboolean, default=False

Whether to output last hidden layer results.

Returns:
prednp.ndarray of shape (n_samples, )

The raw predicted value.

load(file_name: str)

Load the model into memory from file system.

Parameters:
file_name: str

The path and name of the file.

Returns:
estimator object
predict(X)

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

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The (calibrated) final prediction
predict_interval(X)

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

It splits the data with 50% for fitting lower (alpha / 5) and upper (1 - alpha / 2) gradient boosting trees-based quantile regression to the model’s residual; and 50% for calibration.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The lower and upper bounds of the prediction intervals for each sample

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

Raises:
ValueError: If fit_conformal has not been called to fit the conformal prediction model

before calling this method.

predict_last_hidden_layer(X)

Generate regression predictions for input samples.

Processes input features through the trained neural network to produce continuous-valued predictions.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Input samples for which to generate predictions.

Returns:
prednp.ndarray of shape (n_samples, n_last_hidden_layer_units)

Last hidden layer outputs for each input sample.

save(file_name: str)

Save the model into file system.

Parameters:
file_name: str

The path and name of the file.

score(X, y, sample_weight=None)

Return the coefficient of determination of the prediction.

The coefficient of determination \(R^2\) is defined as \((1 - \frac{u}{v})\), where \(u\) is the residual sum of squares ((y_true - y_pred)** 2).sum() and \(v\) is the total sum of squares ((y_true - y_true.mean()) ** 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a \(R^2\) score of 0.0.

Parameters:
Xarray-like of shape (n_samples, n_features)

Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape (n_samples, n_samples_fitted), where n_samples_fitted is the number of samples used in the fitting for the estimator.

yarray-like of shape (n_samples,) or (n_samples, n_outputs)

True values for X.

sample_weightarray-like of shape (n_samples,), default=None

Sample weights.

Returns:
scorefloat

\(R^2\) of self.predict(X) w.r.t. y.

Notes

The \(R^2\) score used when calling score on a regressor uses multioutput='uniform_average' from version 0.23 to keep consistent with default value of r2_score(). This influences the score method of all the multioutput regressors (except for MultiOutputRegressor).

set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoReLUDNNRegressor

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in fit.

Returns:
selfobject

The updated object.

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:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance

Estimator instance.

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoReLUDNNRegressor

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in score.

Returns:
selfobject

The updated object.

class modeva.models.MoMoERegressor(name: str = None, n_clusters: int = 10, cluster_method: str = 'kmeans', centroids: ndarray = None, calibration: bool = True, cv=3, feature_names: list = None, cluster_features: list = None, gating_features: list = None, ltc_baseline_n_estimators: int = 300, ltc_baseline_max_depth: int = 2, ltc_n_estimators: int = 100, ltc_max_depth: int = 5, expert: str = 'xgboost', *args, **kwargs)[source]

A Mixture of Experts (MoE) regressor that combines multiple expert models for regression tasks.

This regressor creates a weighted ensemble of expert models, where each expert specializes in different regions of the input space. The final prediction is computed as a weighted sum of expert predictions, where weights are determined by a gating network based on the input features.

Parameters:
namestr, default=None

Identifier for the model instance.

n_clustersint, default=10

Number of expert models (clusters) to create.

cluster_method{‘ltc’, ‘kmeans’}, default=’kmeans’

Which algorithm to use.

  • ‘kmeans’: Use KMeans clustering algorithm directly.

  • ‘ltc’: This method (Learning Trajectory Cluster; LTC) first fits a baseline xgboost model and calculates its absolute residuals; then fits a gradient boosting models between predictors and the absolute residuals. It extracts prediction trajectories during training, applies optional weighting schemes, performs PCA dimensionality reduction, and clusters samples based on their learning patterns.

centroidsnp.ndarray, default=None

Pre-defined cluster centers of shape (n_clusters, n_features). If provided, skips the clustering step and uses these centers directly.

calibrationbool, default=True

Whether to calibrate the gating network’s probability estimates using cross-validation.

cvint, cross-validation generator or iterable, default=3

Cross-validation strategy for probability calibration. Can be: - int: number of folds for K-Fold cross-validation - cross-validation generator: custom splitting strategy - iterable: yields (train, test) splits as indices

feature_nameslist or None, default=None

The list of feature names. If None, will use “X0”, “X1”, “X2”, etc.

cluster_featureslist or None, default=None

The list of feature names used for clustering. If None, will use all features.

gating_featureslist or None, default=None

The list of feature names used for gating model fitting. If None, will use all features.

ltc_baseline_n_estimatorsint, default=300

The number of estimators used for fitting the baseline Xgboost, used when cluster_method=”ltc” only.

ltc_baseline_max_depthint, default=2

The max depth used for fitting the baseline Xgboost, used when cluster_method=”ltc” only.

ltc_n_estimatorsint, default=300

The number of estimators used for fitting the gradient boosting models in trajectory analysis, used when cluster_method=”ltc” only.

ltc_max_depthint, default=2

The max depth used for fitting the gradient boosting models in trajectory analysis, used when cluster_method=”ltc” only.

expert{“xgboost”, “lightgbm”, “catboost”}, default=”xgboost”

The backend estimator used for each cluster.

*args

Variable length argument list passed to the underlying expert model.

**kwargs

Arbitrary keyword arguments passed to the underlying expert model.

calibrate_interval(X, y, alpha=0.1, max_depth: int = 5)

Fit a conformal prediction model to the given data.

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

If the model is a regressor, splits the data with 50% for fitting lower (alpha / 5) and upper (1 - alpha / 2) gradient boosting trees-based quantile regression to the model’s residual; and 50% for calibration.

If the model is a binary classifiers, it computes the calibration quantile based on predicted probabilities for the positive class.

Parameters:
XXnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

yarray-like of shape (n_samples, )

Target values.

alphafloat, default=0.1

Expected miscoverage for the conformal prediction.

max_depthint, default=5

Maximum depth of the gradient boosting trees for regression tasks. Only used when task_type is REGRESSION.

Raises:
ValueError: If the model is neither a regressor nor a classifier.
fit_cluster(cluster_id, cluster_labels, X, y, sample_weight, **kwargs)

Fit a model for a single cluster. This function is designed for parallelization.

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsmapping of string to any

Parameter names mapped to their values.

get_pr_weight(X)

Return the weight of each expert.

get_raw_output(X)

Return the raw prediction outputs.

load(file_name: str)

Load the model into memory from file system.

Parameters:
file_name: str

The path and name of the file.

Returns:
estimator object
predict(X)

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

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The (calibrated) final prediction
predict_interval(X)

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

It splits the data with 50% for fitting lower (alpha / 5) and upper (1 - alpha / 2) gradient boosting trees-based quantile regression to the model’s residual; and 50% for calibration.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The lower and upper bounds of the prediction intervals for each sample

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

Raises:
ValueError: If fit_conformal has not been called to fit the conformal prediction model

before calling this method.

save(file_name: str)

Save the model into file system.

Parameters:
file_name: str

The path and name of the file.

score(X, y, sample_weight=None)

Return the coefficient of determination of the prediction.

The coefficient of determination \(R^2\) is defined as \((1 - \frac{u}{v})\), where \(u\) is the residual sum of squares ((y_true - y_pred)** 2).sum() and \(v\) is the total sum of squares ((y_true - y_true.mean()) ** 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a \(R^2\) score of 0.0.

Parameters:
Xarray-like of shape (n_samples, n_features)

Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape (n_samples, n_samples_fitted), where n_samples_fitted is the number of samples used in the fitting for the estimator.

yarray-like of shape (n_samples,) or (n_samples, n_outputs)

True values for X.

sample_weightarray-like of shape (n_samples,), default=None

Sample weights.

Returns:
scorefloat

\(R^2\) of self.predict(X) w.r.t. y.

Notes

The \(R^2\) score used when calling score on a regressor uses multioutput='uniform_average' from version 0.23 to keep consistent with default value of r2_score(). This influences the score method of all the multioutput regressors (except for MultiOutputRegressor).

set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoMoERegressor

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in fit.

Returns:
selfobject

The updated object.

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:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance

Estimator instance.

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoMoERegressor

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in score.

Returns:
selfobject

The updated object.

class modeva.models.ModelBaseRegressor[source]

Base Class for Modeva Regressors.

calibrate_interval(X, y, alpha=0.1, max_depth: int = 5)[source]

Fit a conformal prediction model to the given data.

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

If the model is a regressor, splits the data with 50% for fitting lower (alpha / 5) and upper (1 - alpha / 2) gradient boosting trees-based quantile regression to the model’s residual; and 50% for calibration.

If the model is a binary classifiers, it computes the calibration quantile based on predicted probabilities for the positive class.

Parameters:
XXnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

yarray-like of shape (n_samples, )

Target values.

alphafloat, default=0.1

Expected miscoverage for the conformal prediction.

max_depthint, default=5

Maximum depth of the gradient boosting trees for regression tasks. Only used when task_type is REGRESSION.

Raises:
ValueError: If the model is neither a regressor nor a classifier.
get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

load(file_name: str)

Load the model into memory from file system.

Parameters:
file_name: str

The path and name of the file.

Returns:
estimator object
predict(X)[source]

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

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The (calibrated) final prediction
predict_interval(X)[source]

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

It splits the data with 50% for fitting lower (alpha / 5) and upper (1 - alpha / 2) gradient boosting trees-based quantile regression to the model’s residual; and 50% for calibration.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The lower and upper bounds of the prediction intervals for each sample

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

Raises:
ValueError: If fit_conformal has not been called to fit the conformal prediction model

before calling this method.

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:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance

Estimator instance.

Classification

class modeva.models.MoLogisticRegression(name: str = None, feature_names=None, feature_types=None, *args, **kwargs)[source]

A lightweight wrapper of sklearn.linear_model.LogisticRegression.

Note that categorical features are preprocessed by one-hot encoding in this wrapper.

Parameters:
namestr, default=None

Identifier for the model instance.

feature_nameslist or None, default=None

The list of feature names.

feature_typeslist or None, default=None

The list of feature types. Available types include “numerical” and “categorical”.

*args

Variable length argument list passed to the underlying LogisticRegression model.

**kwargs

Arbitrary keyword arguments passed to the underlying LogisticRegression model.

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:
XXnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

yarray-like of shape (n_samples, )

Target values.

alphafloat, 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:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

ynp.ndarray of shape (n_samples, )

Ground truth labels.

sample_weightarray-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: Calibrated estimator
decision_function(X, calibration: bool = True)

Computes the decision function for the given input data.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.

Returns:
logit_predictionarray, shape (n_samples,) or (n_samples, n_classes)

Array of (calibrated) logit predictions.

fit(X, y, sample_weight=None)[source]

Fits the estimator to the provided data.

Parameters:
Xarray-like, shape (n_samples, n_features)

Training data.

yarray-like, shape (n_samples,) or (n_samples, n_outputs)

Target values.

sample_weightarray-like, shape (n_samples,), optional

Sample weights.

Returns:
selfobject

Fitted model instance.

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)[source]

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

load(file_name: str)

Load the model into memory from file system.

Parameters:
file_name: str

The path and name of the file.

Returns:
estimator object
predict(X, calibration: bool = True)

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

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.

Returns:
np.ndarray: 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:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The lower and upper bounds of the prediction intervals for each sample

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

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:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will return calibrated probability if calibration is done. Otherwise, will return raw probability.

Returns:
np.ndarray: 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.

score(X, y, sample_weight=None)

Return the mean accuracy on the given test data and labels.

In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.

Parameters:
Xarray-like of shape (n_samples, n_features)

Test samples.

yarray-like of shape (n_samples,) or (n_samples, n_outputs)

True labels for X.

sample_weightarray-like of shape (n_samples,), default=None

Sample weights.

Returns:
scorefloat

Mean accuracy of self.predict(X) w.r.t. y.

set_decision_function_request(*, calibration: bool | None | str = '$UNCHANGED$') MoLogisticRegression

Request metadata passed to the decision_function method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to decision_function if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to decision_function.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in decision_function.

Returns:
selfobject

The updated object.

set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoLogisticRegression

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in fit.

Returns:
selfobject

The updated object.

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:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance
set_predict_proba_request(*, calibration: bool | None | str = '$UNCHANGED$') MoLogisticRegression

Request metadata passed to the predict_proba method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict_proba if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict_proba.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in predict_proba.

Returns:
selfobject

The updated object.

set_predict_request(*, calibration: bool | None | str = '$UNCHANGED$') MoLogisticRegression

Request metadata passed to the predict method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in predict.

Returns:
selfobject

The updated object.

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoLogisticRegression

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in score.

Returns:
selfobject

The updated object.

class modeva.models.MoDecisionTreeClassifier(name: str = None, *args, **kwargs)[source]

A lightweight wrapper of sklearn.tree.DecisionTreeClassifier.

Parameters:
namestr, default=None

Identifier for the model instance.

*args

Variable length argument list passed to the underlying DecisionTreeClassifier model.

**kwargs

Arbitrary keyword arguments passed to the underlying DecisionTreeClassifier model.

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:
XXnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

yarray-like of shape (n_samples, )

Target values.

alphafloat, 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:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

ynp.ndarray of shape (n_samples, )

Ground truth labels.

sample_weightarray-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: Calibrated estimator
decision_function(X, calibration: bool = True)

Computes the decision function for the given input data.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.

Returns:
logit_predictionarray, shape (n_samples,) or (n_samples, n_classes)

Array of (calibrated) logit predictions.

fit(X, y, sample_weight=None, **kwargs)

Fits the estimator to the provided data.

Parameters:
Xarray-like, shape (n_samples, n_features)

Training data.

yarray-like, shape (n_samples,) or (n_samples, n_outputs)

Target values.

sample_weightarray-like, shape (n_samples,), default=None

Sample weights.

Returns:
selfobject

Fitted model instance.

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)[source]

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

interpret(dataset)[source]

Interpret the decision tree with given dataset.

Parameters:
datasetDataSet instance

The dataset for interpreting the model.

Returns:
An instance of InterpretDecisionTree
load(file_name: str)

Load the model into memory from file system.

Parameters:
file_name: str

The path and name of the file.

Returns:
estimator object
predict(X, calibration: bool = True)

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

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.

Returns:
np.ndarray: 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:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The lower and upper bounds of the prediction intervals for each sample

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

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:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will return calibrated probability if calibration is done. Otherwise, will return raw probability.

Returns:
np.ndarray: 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.

score(X, y, sample_weight=None)

Return the mean accuracy on the given test data and labels.

In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.

Parameters:
Xarray-like of shape (n_samples, n_features)

Test samples.

yarray-like of shape (n_samples,) or (n_samples, n_outputs)

True labels for X.

sample_weightarray-like of shape (n_samples,), default=None

Sample weights.

Returns:
scorefloat

Mean accuracy of self.predict(X) w.r.t. y.

set_decision_function_request(*, calibration: bool | None | str = '$UNCHANGED$') MoDecisionTreeClassifier

Request metadata passed to the decision_function method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to decision_function if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to decision_function.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in decision_function.

Returns:
selfobject

The updated object.

set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoDecisionTreeClassifier

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in fit.

Returns:
selfobject

The updated object.

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:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance
set_predict_proba_request(*, calibration: bool | None | str = '$UNCHANGED$') MoDecisionTreeClassifier

Request metadata passed to the predict_proba method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict_proba if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict_proba.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in predict_proba.

Returns:
selfobject

The updated object.

set_predict_request(*, calibration: bool | None | str = '$UNCHANGED$') MoDecisionTreeClassifier

Request metadata passed to the predict method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in predict.

Returns:
selfobject

The updated object.

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoDecisionTreeClassifier

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in score.

Returns:
selfobject

The updated object.

class modeva.models.MoRandomForestClassifier(name: str = None, *args, **kwargs)[source]

A lightweight wrapper of sklearn.ensemble.RandomForestClassifier.

Parameters:
namestr, default=None

Identifier for the model instance.

*args

Variable length argument list passed to the underlying RandomForestClassifier model.

**kwargs

Arbitrary keyword arguments passed to the underlying RandomForestClassifier model.

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:
XXnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

yarray-like of shape (n_samples, )

Target values.

alphafloat, 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:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

ynp.ndarray of shape (n_samples, )

Ground truth labels.

sample_weightarray-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: Calibrated estimator
decision_function(X, calibration: bool = True)

Computes the decision function for the given input data.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.

Returns:
logit_predictionarray, shape (n_samples,) or (n_samples, n_classes)

Array of (calibrated) logit predictions.

extract_model_info(X, feature_names, feature_types)

Extract the tree information as functional ANOVA format.

Parameters:
Xarray-like

Input features.

feature_names: list of str

The feature names.

feature_types: list of str

The feature types.

fit(X, y, sample_weight=None, **kwargs)

Fits the estimator to the provided data.

Parameters:
Xarray-like, shape (n_samples, n_features)

Training data.

yarray-like, shape (n_samples,) or (n_samples, n_outputs)

Target values.

sample_weightarray-like, shape (n_samples,), default=None

Sample weights.

Returns:
selfobject

Fitted model instance.

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)[source]

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

interpret(dataset)

Interpret the ensemble tree model with given dataset using functional ANOVA framework.

Parameters:
datasetDataSet instance

The dataset for interpreting the model.

Returns:
An instance of InterpretFANOVA
load(file_name: str)

Load the model into memory from file system.

Parameters:
file_name: str

The path and name of the file.

Returns:
estimator object
predict(X, calibration: bool = True)

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

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.

Returns:
np.ndarray: 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:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The lower and upper bounds of the prediction intervals for each sample

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

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:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will return calibrated probability if calibration is done. Otherwise, will return raw probability.

Returns:
np.ndarray: 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.

score(X, y, sample_weight=None)

Return the mean accuracy on the given test data and labels.

In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.

Parameters:
Xarray-like of shape (n_samples, n_features)

Test samples.

yarray-like of shape (n_samples,) or (n_samples, n_outputs)

True labels for X.

sample_weightarray-like of shape (n_samples,), default=None

Sample weights.

Returns:
scorefloat

Mean accuracy of self.predict(X) w.r.t. y.

set_decision_function_request(*, calibration: bool | None | str = '$UNCHANGED$') MoRandomForestClassifier

Request metadata passed to the decision_function method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to decision_function if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to decision_function.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in decision_function.

Returns:
selfobject

The updated object.

set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoRandomForestClassifier

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in fit.

Returns:
selfobject

The updated object.

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:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance
set_predict_proba_request(*, calibration: bool | None | str = '$UNCHANGED$') MoRandomForestClassifier

Request metadata passed to the predict_proba method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict_proba if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict_proba.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in predict_proba.

Returns:
selfobject

The updated object.

set_predict_request(*, calibration: bool | None | str = '$UNCHANGED$') MoRandomForestClassifier

Request metadata passed to the predict method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in predict.

Returns:
selfobject

The updated object.

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoRandomForestClassifier

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in score.

Returns:
selfobject

The updated object.

class modeva.models.MoGradientBoostingClassifier(name: str = None, *args, **kwargs)[source]

A lightweight wrapper of sklearn.ensemble.GradientBoostingClassifier.

Parameters:
namestr, default=None

Identifier for the model instance.

*args

Variable length argument list passed to the underlying GradientBoostingClassifier model.

**kwargs

Arbitrary keyword arguments passed to the underlying GradientBoostingClassifier model.

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:
XXnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

yarray-like of shape (n_samples, )

Target values.

alphafloat, 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:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

ynp.ndarray of shape (n_samples, )

Ground truth labels.

sample_weightarray-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: Calibrated estimator
decision_function(X, calibration: bool = True)

Computes the decision function for the given input data.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.

Returns:
logit_predictionarray, shape (n_samples,) or (n_samples, n_classes)

Array of (calibrated) logit predictions.

extract_model_info(X, feature_names, feature_types)

Extract the tree information as functional ANOVA format.

Parameters:
Xarray-like

Input features.

feature_names: list of str

The feature names.

feature_types: list of str

The feature types.

fit(X, y, sample_weight=None, **kwargs)

Fits the estimator to the provided data.

Parameters:
Xarray-like, shape (n_samples, n_features)

Training data.

yarray-like, shape (n_samples,) or (n_samples, n_outputs)

Target values.

sample_weightarray-like, shape (n_samples,), default=None

Sample weights.

Returns:
selfobject

Fitted model instance.

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)[source]

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

interpret(dataset)

Interpret the ensemble tree model with given dataset using functional ANOVA framework.

Parameters:
datasetDataSet instance

The dataset for interpreting the model.

Returns:
An instance of InterpretFANOVA
load(file_name: str)

Load the model into memory from file system.

Parameters:
file_name: str

The path and name of the file.

Returns:
estimator object
predict(X, calibration: bool = True)

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

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.

Returns:
np.ndarray: 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:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The lower and upper bounds of the prediction intervals for each sample

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

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:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will return calibrated probability if calibration is done. Otherwise, will return raw probability.

Returns:
np.ndarray: 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.

score(X, y, sample_weight=None)

Return the mean accuracy on the given test data and labels.

In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.

Parameters:
Xarray-like of shape (n_samples, n_features)

Test samples.

yarray-like of shape (n_samples,) or (n_samples, n_outputs)

True labels for X.

sample_weightarray-like of shape (n_samples,), default=None

Sample weights.

Returns:
scorefloat

Mean accuracy of self.predict(X) w.r.t. y.

set_decision_function_request(*, calibration: bool | None | str = '$UNCHANGED$') MoGradientBoostingClassifier

Request metadata passed to the decision_function method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to decision_function if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to decision_function.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in decision_function.

Returns:
selfobject

The updated object.

set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoGradientBoostingClassifier

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in fit.

Returns:
selfobject

The updated object.

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:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance
set_predict_proba_request(*, calibration: bool | None | str = '$UNCHANGED$') MoGradientBoostingClassifier

Request metadata passed to the predict_proba method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict_proba if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict_proba.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in predict_proba.

Returns:
selfobject

The updated object.

set_predict_request(*, calibration: bool | None | str = '$UNCHANGED$') MoGradientBoostingClassifier

Request metadata passed to the predict method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in predict.

Returns:
selfobject

The updated object.

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoGradientBoostingClassifier

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in score.

Returns:
selfobject

The updated object.

class modeva.models.MoXGBClassifier(name: str = None, *args, **kwargs)[source]

A lightweight wrapper of xgboost.XGBClassifier.

Parameters:
namestr, default=None

Identifier for the model instance.

*args

Variable length argument list passed to the underlying XGBClassifier model.

**kwargs

Arbitrary keyword arguments passed to the underlying XGBClassifier model.

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:
XXnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

yarray-like of shape (n_samples, )

Target values.

alphafloat, 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:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

ynp.ndarray of shape (n_samples, )

Ground truth labels.

sample_weightarray-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: Calibrated estimator
decision_function(X, calibration: bool = True)

Computes the decision function for the given input data.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.

Returns:
logit_predictionarray, shape (n_samples,) or (n_samples, n_classes)

Array of (calibrated) logit predictions.

extract_model_info(X, feature_names, feature_types)

Extract the tree information as functional ANOVA format.

Parameters:
Xarray-like

Input features.

feature_names: list of str

The feature names.

feature_types: list of str

The feature types.

fit(X, y, sample_weight=None, **kwargs)

Fits the estimator to the provided data.

Parameters:
Xarray-like, shape (n_samples, n_features)

Training data.

yarray-like, shape (n_samples,) or (n_samples, n_outputs)

Target values.

sample_weightarray-like, shape (n_samples,), default=None

Sample weights.

Returns:
selfobject

Fitted model instance.

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)[source]

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

interpret(dataset)

Interpret the ensemble tree model with given dataset using functional ANOVA framework.

Parameters:
datasetDataSet instance

The dataset for interpreting the model.

Returns:
An instance of InterpretFANOVA
load(file_name: str)

Load the model into memory from file system.

Parameters:
file_name: str

The path and name of the file.

Returns:
estimator object
predict(X, calibration: bool = True)

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

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.

Returns:
np.ndarray: 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:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The lower and upper bounds of the prediction intervals for each sample

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

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:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will return calibrated probability if calibration is done. Otherwise, will return raw probability.

Returns:
np.ndarray: 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.

score(X, y, sample_weight=None)

Return the mean accuracy on the given test data and labels.

In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.

Parameters:
Xarray-like of shape (n_samples, n_features)

Test samples.

yarray-like of shape (n_samples,) or (n_samples, n_outputs)

True labels for X.

sample_weightarray-like of shape (n_samples,), default=None

Sample weights.

Returns:
scorefloat

Mean accuracy of self.predict(X) w.r.t. y.

set_decision_function_request(*, calibration: bool | None | str = '$UNCHANGED$') MoXGBClassifier

Request metadata passed to the decision_function method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to decision_function if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to decision_function.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in decision_function.

Returns:
selfobject

The updated object.

set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoXGBClassifier

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in fit.

Returns:
selfobject

The updated object.

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:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance
set_predict_proba_request(*, calibration: bool | None | str = '$UNCHANGED$') MoXGBClassifier

Request metadata passed to the predict_proba method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict_proba if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict_proba.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in predict_proba.

Returns:
selfobject

The updated object.

set_predict_request(*, calibration: bool | None | str = '$UNCHANGED$') MoXGBClassifier

Request metadata passed to the predict method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in predict.

Returns:
selfobject

The updated object.

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoXGBClassifier

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in score.

Returns:
selfobject

The updated object.

class modeva.models.MoLGBMClassifier(name: str = None, *args, **kwargs)[source]

A lightweight wrapper of lightgbm.LGBMClassifier.

Parameters:
namestr, default=None

Identifier for the model instance.

*args

Variable length argument list passed to the underlying LGBMClassifier model.

**kwargs

Arbitrary keyword arguments passed to the underlying LGBMClassifier model.

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:
XXnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

yarray-like of shape (n_samples, )

Target values.

alphafloat, 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:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

ynp.ndarray of shape (n_samples, )

Ground truth labels.

sample_weightarray-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: Calibrated estimator
decision_function(X, calibration: bool = True)

Computes the decision function for the given input data.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.

Returns:
logit_predictionarray, shape (n_samples,) or (n_samples, n_classes)

Array of (calibrated) logit predictions.

extract_model_info(X, feature_names, feature_types)

Extract the tree information as functional ANOVA format.

Parameters:
Xarray-like

Input features.

feature_names: list of str

The feature names.

feature_types: list of str

The feature types.

fit(X, y, sample_weight=None, **kwargs)

Fits the estimator to the provided data.

Parameters:
Xarray-like, shape (n_samples, n_features)

Training data.

yarray-like, shape (n_samples,) or (n_samples, n_outputs)

Target values.

sample_weightarray-like, shape (n_samples,), default=None

Sample weights.

Returns:
selfobject

Fitted model instance.

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)[source]

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

interpret(dataset)

Interpret the ensemble tree model with given dataset using functional ANOVA framework.

Parameters:
datasetDataSet instance

The dataset for interpreting the model.

Returns:
An instance of InterpretFANOVA
load(file_name: str)

Load the model into memory from file system.

Parameters:
file_name: str

The path and name of the file.

Returns:
estimator object
predict(X, calibration: bool = True)

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

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.

Returns:
np.ndarray: 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:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The lower and upper bounds of the prediction intervals for each sample

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

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:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will return calibrated probability if calibration is done. Otherwise, will return raw probability.

Returns:
np.ndarray: 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.

score(X, y, sample_weight=None)

Return the mean accuracy on the given test data and labels.

In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.

Parameters:
Xarray-like of shape (n_samples, n_features)

Test samples.

yarray-like of shape (n_samples,) or (n_samples, n_outputs)

True labels for X.

sample_weightarray-like of shape (n_samples,), default=None

Sample weights.

Returns:
scorefloat

Mean accuracy of self.predict(X) w.r.t. y.

set_decision_function_request(*, calibration: bool | None | str = '$UNCHANGED$') MoLGBMClassifier

Request metadata passed to the decision_function method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to decision_function if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to decision_function.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in decision_function.

Returns:
selfobject

The updated object.

set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoLGBMClassifier

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in fit.

Returns:
selfobject

The updated object.

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:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance
set_predict_proba_request(*, calibration: bool | None | str = '$UNCHANGED$') MoLGBMClassifier

Request metadata passed to the predict_proba method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict_proba if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict_proba.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in predict_proba.

Returns:
selfobject

The updated object.

set_predict_request(*, calibration: bool | None | str = '$UNCHANGED$') MoLGBMClassifier

Request metadata passed to the predict method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in predict.

Returns:
selfobject

The updated object.

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoLGBMClassifier

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in score.

Returns:
selfobject

The updated object.

class modeva.models.MoCatBoostClassifier(name: str = None, *args, **kwargs)[source]

A lightweight wrapper of catboost.CatBoostClassifier.

Parameters:
namestr, default=None

Identifier for the model instance.

*args

Variable length argument list passed to the underlying CatBoostClassifier model.

**kwargs

Arbitrary keyword arguments passed to the underlying CatBoostClassifier model.

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:
XXnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

yarray-like of shape (n_samples, )

Target values.

alphafloat, 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:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

ynp.ndarray of shape (n_samples, )

Ground truth labels.

sample_weightarray-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: Calibrated estimator
decision_function(X, calibration: bool = True)

Computes the decision function for the given input data.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.

Returns:
logit_predictionarray, shape (n_samples,) or (n_samples, n_classes)

Array of (calibrated) logit predictions.

extract_model_info(X, feature_names, feature_types)

Extract the tree information as functional ANOVA format.

Parameters:
Xarray-like

Input features.

feature_names: list of str

The feature names.

feature_types: list of str

The feature types.

fit(X, y, sample_weight=None, **kwargs)

Fits the estimator to the provided data.

Parameters:
Xarray-like, shape (n_samples, n_features)

Training data.

yarray-like, shape (n_samples,) or (n_samples, n_outputs)

Target values.

sample_weightarray-like, shape (n_samples,), default=None

Sample weights.

Returns:
selfobject

Fitted model instance.

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)[source]

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

interpret(dataset)

Interpret the ensemble tree model with given dataset using functional ANOVA framework.

Parameters:
datasetDataSet instance

The dataset for interpreting the model.

Returns:
An instance of InterpretFANOVA
load(file_name: str)

Load the model into memory from file system.

Parameters:
file_name: str

The path and name of the file.

Returns:
estimator object
predict(X, calibration: bool = True)

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

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.

Returns:
np.ndarray: 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:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The lower and upper bounds of the prediction intervals for each sample

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

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:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will return calibrated probability if calibration is done. Otherwise, will return raw probability.

Returns:
np.ndarray: 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.

score(X, y, sample_weight=None)

Return the mean accuracy on the given test data and labels.

In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.

Parameters:
Xarray-like of shape (n_samples, n_features)

Test samples.

yarray-like of shape (n_samples,) or (n_samples, n_outputs)

True labels for X.

sample_weightarray-like of shape (n_samples,), default=None

Sample weights.

Returns:
scorefloat

Mean accuracy of self.predict(X) w.r.t. y.

set_decision_function_request(*, calibration: bool | None | str = '$UNCHANGED$') MoCatBoostClassifier

Request metadata passed to the decision_function method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to decision_function if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to decision_function.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in decision_function.

Returns:
selfobject

The updated object.

set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoCatBoostClassifier

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in fit.

Returns:
selfobject

The updated object.

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:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance
set_predict_proba_request(*, calibration: bool | None | str = '$UNCHANGED$') MoCatBoostClassifier

Request metadata passed to the predict_proba method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict_proba if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict_proba.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in predict_proba.

Returns:
selfobject

The updated object.

set_predict_request(*, calibration: bool | None | str = '$UNCHANGED$') MoCatBoostClassifier

Request metadata passed to the predict method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in predict.

Returns:
selfobject

The updated object.

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoCatBoostClassifier

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in score.

Returns:
selfobject

The updated object.

class modeva.models.MoGLMTreeClassifier(name: str = None, max_depth=3, min_samples_leaf=50, min_impurity_decrease=0, split_custom=None, n_screen_grid=1, n_feature_search=10, n_split_grid=20, clip_predict=False, reg_lambda=0.1, random_state=0)[source]

A tree-based model that fits logistic regression models in the leaves for binary classification.

This model recursively partitions the feature space and fits logistic regression models in each leaf node. It combines the interpretability of decision trees with the flexibility of logistic regression.

Parameters:
namestr, default=None

Identifier name for the model instance.

max_depthint, default=3

Maximum depth of the tree. Controls model complexity.

min_samples_leafint, default=50

Minimum number of samples required in a leaf node.

min_impurity_decreasefloat, default=0

Minimum required decrease in impurity to split a node.

split_customdict, default=None

Dictionary mapping feature indices to custom split points.

n_screen_gridint, default=1

Number of grid points used in initial feature screening.

n_feature_searchint, default=10

Number of top features to consider after screening.

n_split_gridint, default=20

Number of grid points to evaluate for splitting.

reg_lambdafloat, default=0.1

L1 regularization strength for leaf models.

clip_predictbool, default=False

Whether to clip predictions to training data range.

random_stateint, default=0

Random seed for reproducibility.

Attributes:
tree_dict

The fitted tree structure containing nodes and their parameters.

leaf_estimators_dict

Dictionary mapping leaf node IDs to their fitted logistic regression models.

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:
XXnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

yarray-like of shape (n_samples, )

Target values.

alphafloat, 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:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

ynp.ndarray of shape (n_samples, )

Ground truth labels.

sample_weightarray-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: Calibrated estimator
decision_function(X, calibration: bool = True)

Computes the decision function for the given input data.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.

Returns:
logit_predictionarray, shape (n_samples,) or (n_samples, n_classes)

Array of (calibrated) logit predictions.

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

get_raw_output(x)

output

Parameters

xarray-like of shape (n_samples, n_features)

containing the input dataset

Returns

np.ndarray of shape (n_samples,),

load(file_name: str)

Load the model into memory from file system.

Parameters:
file_name: str

The path and name of the file.

Returns:
estimator object
predict(X, calibration: bool = True)

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

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.

Returns:
np.ndarray: 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:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The lower and upper bounds of the prediction intervals for each sample

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

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:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will return calibrated probability if calibration is done. Otherwise, will return raw probability.

Returns:
np.ndarray: 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.

score(X, y, sample_weight=None)

Return the mean accuracy on the given test data and labels.

In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.

Parameters:
Xarray-like of shape (n_samples, n_features)

Test samples.

yarray-like of shape (n_samples,) or (n_samples, n_outputs)

True labels for X.

sample_weightarray-like of shape (n_samples,), default=None

Sample weights.

Returns:
scorefloat

Mean accuracy of self.predict(X) w.r.t. y.

set_decision_function_request(*, calibration: bool | None | str = '$UNCHANGED$') MoGLMTreeClassifier

Request metadata passed to the decision_function method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to decision_function if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to decision_function.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in decision_function.

Returns:
selfobject

The updated object.

set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoGLMTreeClassifier

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in fit.

Returns:
selfobject

The updated object.

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:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance

Estimator instance.

set_predict_proba_request(*, calibration: bool | None | str = '$UNCHANGED$') MoGLMTreeClassifier

Request metadata passed to the predict_proba method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict_proba if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict_proba.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in predict_proba.

Returns:
selfobject

The updated object.

set_predict_request(*, calibration: bool | None | str = '$UNCHANGED$') MoGLMTreeClassifier

Request metadata passed to the predict method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in predict.

Returns:
selfobject

The updated object.

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoGLMTreeClassifier

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in score.

Returns:
selfobject

The updated object.

class modeva.models.MoGLMTreeBoostClassifier(name: str = None, n_estimators=100, learning_rate=1.0, n_epoch_no_change=5, max_depth=1, min_samples_leaf=50, min_impurity_decrease=0, split_custom=None, n_screen_grid=1, n_feature_search=5, n_split_grid=20, reg_lambda=0.1, clip_predict=False, simplified=True, verbose=False, val_ratio=0.2, random_state=0)[source]

GLMTree Boosting classifier using residual-based boosting.

A gradient boosting classifier that uses GLMTree base models to iteratively fit residuals. Each tree has both linear and non-linear components to capture complex relationships while maintaining interpretability.

Parameters:
namestr, default=None

Model identifier name for reference.

n_estimatorsint, default=100

Number of boosting rounds (trees) to fit.

max_depthint, default=1

Maximum tree depth. Model is most interpretable when depth=1.

learning_ratefloat, default=1.0

Shrinkage rate applied to each tree’s contribution.

n_epoch_no_changeint, default=5

Early stopping rounds - training stops if validation loss doesn’t improve.

min_samples_leafint, default=50

Minimum samples required in a leaf node.

min_impurity_decreasefloat, default=0

Minimum required decrease in impurity to split a node.

split_customdict, default=None

Custom split points specified per feature.

n_screen_gridint, default=1

Grid size for initial split point screening.

n_feature_searchint, default=5

Number of features to consider after screening.

n_split_gridint, default=20

Grid size for fine-grained split point search.

reg_lambdafloat, default=0.1

L1 regularization strength parameter.

clip_predictbool, default=False

Whether to clip predictions to training data range.

simplifiedbool, default=True

Use simplified partial linear regression for splits.

val_ratiofloat, default=0.2

Proportion of data used for validation.

verbosebool, default=False

Whether to print training progress.

random_stateint, default=0

Random seed for reproducibility.

Attributes:
estimators_list

Fitted GLMTree models.

n_features_in_int

Number of input features.

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:
XXnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

yarray-like of shape (n_samples, )

Target values.

alphafloat, 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:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

ynp.ndarray of shape (n_samples, )

Ground truth labels.

sample_weightarray-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: Calibrated estimator
decision_function(X, calibration: bool = True)

Computes the decision function for the given input data.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.

Returns:
logit_predictionarray, shape (n_samples,) or (n_samples, n_classes)

Array of (calibrated) logit predictions.

fit(X, y, sample_weight=None)

fit the GLMTree Boosting model

Parameters

Xarray-like of shape (n_samples, n_features)

containing the input dataset

yarray-like of shape (n_samples,)

containing target values

sample_weightarray-like of shape (n_samples,)

containing the weight of each sample

Returns

object

self : Estimator instance.

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

get_raw_output(x)

output

Parameters

xarray-like of shape (n_samples, n_features)

containing the input dataset

Returns

np.ndarray of shape (n_samples,),

load(file_name: str)

Load the model into memory from file system.

Parameters:
file_name: str

The path and name of the file.

Returns:
estimator object
predict(X, calibration: bool = True)

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

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.

Returns:
np.ndarray: 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:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The lower and upper bounds of the prediction intervals for each sample

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

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:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will return calibrated probability if calibration is done. Otherwise, will return raw probability.

Returns:
np.ndarray: 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.

score(X, y, sample_weight=None)

Return the mean accuracy on the given test data and labels.

In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.

Parameters:
Xarray-like of shape (n_samples, n_features)

Test samples.

yarray-like of shape (n_samples,) or (n_samples, n_outputs)

True labels for X.

sample_weightarray-like of shape (n_samples,), default=None

Sample weights.

Returns:
scorefloat

Mean accuracy of self.predict(X) w.r.t. y.

set_decision_function_request(*, calibration: bool | None | str = '$UNCHANGED$') MoGLMTreeBoostClassifier

Request metadata passed to the decision_function method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to decision_function if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to decision_function.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in decision_function.

Returns:
selfobject

The updated object.

set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoGLMTreeBoostClassifier

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in fit.

Returns:
selfobject

The updated object.

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:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance

Estimator instance.

set_predict_proba_request(*, calibration: bool | None | str = '$UNCHANGED$') MoGLMTreeBoostClassifier

Request metadata passed to the predict_proba method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict_proba if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict_proba.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in predict_proba.

Returns:
selfobject

The updated object.

set_predict_request(*, calibration: bool | None | str = '$UNCHANGED$') MoGLMTreeBoostClassifier

Request metadata passed to the predict method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in predict.

Returns:
selfobject

The updated object.

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoGLMTreeBoostClassifier

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in score.

Returns:
selfobject

The updated object.

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)[source]

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:
namestr, default=None

Custom identifier for the model instance.

estimatorMoGLMTreeBoostRegressor, default=None

Pre-fitted or unfitted GLMTree regressor for initialization. If None, creates a new instance.

feature_nameslist of str, default=None

Names of input features for interpretability.

val_ratiofloat, default=0.2

Proportion of data used for validation during training (0 to 1).

devicestr, default=None

Computing device for training (‘cpu’, ‘cuda’, etc.).

verbosebool, default=False

If True, prints training progress and statistics.

random_stateint, default=0

Seed for reproducible random operations.

nn_temperaturefloat, default=0.0001

Smoothing parameter for neural network activation.

nn_lrfloat, default=0.001

Learning rate for neural network optimization.

nn_max_epochsint, default=200

Maximum number of training epochs.

nn_batch_sizeint, default=200

Number of samples per training batch.

nn_n_epoch_no_changeint, default=10

Early stopping patience - number of epochs without improvement.

reg_monofloat, default=0.1

Strength of monotonicity regularization.

mono_sample_sizeint, default=1000

Number of random samples for monotonicity regularization.

mono_increasing_listtuple of str, default=()

Features that should have monotonically increasing relationships.

mono_decreasing_listtuple of str, default=()

Features that should have monotonically decreasing relationships.

**kwargs

Additional parameters passed to MoGLMTreeBoostRegressor.

Attributes:
net_object

The internal Pytorch network 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:
XXnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

yarray-like of shape (n_samples, )

Target values.

alphafloat, 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:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

ynp.ndarray of shape (n_samples, )

Ground truth labels.

sample_weightarray-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: Calibrated estimator
certify_mono(n_samples=10000)

Verify if the model satisfies specified monotonicity constraints.

Generates random samples within the feature space and checks if the model’s predictions respect the monotonicity constraints specified during training.

Parameters:
n_samplesint, default=10000

Number of random samples to use for verification.

Returns:
mono_statusbool

True if monotonicity constraints are satisfied, False otherwise.

decision_function(X, calibration: bool = True)

Computes the decision function for the given input data.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.

Returns:
logit_predictionarray, shape (n_samples,) or (n_samples, n_classes)

Array of (calibrated) logit predictions.

get_aggregate_output(X)

Returns numpy array of raw prediction.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Data features.

Returns:
prednp.ndarray of shape (n_samples, 1)

numpy array of raw prediction.

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_mono_loss(x, sample_weight=None)

Returns monotonicity loss of given samples.

Parameters:
xnp.ndarray of shape (n_samples, n_features)

Data features.

sample_weightnp.ndarray of shape (n_samples, ), default=None

Sample weight.

Returns:
mono_lossfloat

monotonicity loss.

get_params(deep=True)[source]

Get parameters for this estimator. Parameters ———- deep : bool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns

paramsmapping of string to any

Parameter names mapped to their values.

load(file_name: str)

Load the model into memory from file system.

Parameters:
file_name: str

The path and name of the file.

Returns:
estimator object
predict(X, calibration: bool = True)

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

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.

Returns:
np.ndarray: 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:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The lower and upper bounds of the prediction intervals for each sample

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

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:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will return calibrated probability if calibration is done. Otherwise, will return raw probability.

Returns:
np.ndarray: 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.

score(X, y, sample_weight=None)

Return the mean accuracy on the given test data and labels.

In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.

Parameters:
Xarray-like of shape (n_samples, n_features)

Test samples.

yarray-like of shape (n_samples,) or (n_samples, n_outputs)

True labels for X.

sample_weightarray-like of shape (n_samples,), default=None

Sample weights.

Returns:
scorefloat

Mean accuracy of self.predict(X) w.r.t. y.

set_decision_function_request(*, calibration: bool | None | str = '$UNCHANGED$') MoNeuralTreeClassifier

Request metadata passed to the decision_function method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to decision_function if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to decision_function.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in decision_function.

Returns:
selfobject

The updated object.

set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoNeuralTreeClassifier

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in fit.

Returns:
selfobject

The updated object.

set_params(**params)[source]

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:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance

Estimator instance.

set_predict_proba_request(*, calibration: bool | None | str = '$UNCHANGED$') MoNeuralTreeClassifier

Request metadata passed to the predict_proba method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict_proba if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict_proba.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in predict_proba.

Returns:
selfobject

The updated object.

set_predict_request(*, calibration: bool | None | str = '$UNCHANGED$') MoNeuralTreeClassifier

Request metadata passed to the predict method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in predict.

Returns:
selfobject

The updated object.

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoNeuralTreeClassifier

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in score.

Returns:
selfobject

The updated object.

class modeva.models.MoGAMINetClassifier(name: str = None, feature_names=None, feature_types=None, interact_num=10, subnet_size_main_effect=(20,), subnet_size_interaction=(20, 20), activation_func='ReLU', max_epochs=(1000, 1000, 1000), learning_rates=(0.001, 0.001, 0.0001), early_stop_thres=('auto', 'auto', 'auto'), batch_size=1000, batch_size_inference=10000, max_iter_per_epoch=100, val_ratio=0.2, warm_start=True, gam_sample_size=5000, mlp_sample_size=1000, heredity=True, reg_clarity=0.1, loss_threshold=0.01, reg_mono=0.1, mono_increasing_list=(), mono_decreasing_list=(), mono_sample_size=1000, include_interaction_list=(), boundary_clip=True, normalize=True, verbose=False, n_jobs=10, device=None, random_state=0)[source]

Generalized additive model with pairwise interaction classifier.

Parameters:
namestr, default=None

The name of the model.

feature_nameslist or None, default=None

The list of feature names. If None, will use “X0”, “X1”, “X2”, etc.

feature_typeslist or None, default=None

The list of feature types. Available types include “numerical” and “categorical”. If None, will use numerical for all features.

interact_numint, default=10

The max number of interactions to be included in the second stage training.

subnet_size_main_effecttuple of int, default=(20, )

The hidden layer architecture of each subnetwork in the main effect block.

subnet_size_interactiontuple of int, default=(20, 20)

The hidden layer architecture of each subnetwork in the interaction block.

activation_func{“ReLU”, “Sigmoid”, “Tanh”}, default=”ReLU”

The name of the activation function.

max_epochstuple of THREE int, default=(1000, 1000, 1000)

The max number of epochs in the first (main effect training), second (interaction training), and third (fine-tuning) stages, respectively.

learning_ratestuple of THREE float, default=(1e-3, 1e-3, 1e-4)

The initial learning rates of Adam optimizer in the first (main effect training), second (interaction training), and third (fine-tuning) stages, respectively.

early_stop_threstuple of THREE int or “auto”, default=[“auto”, “auto”, “auto”]

The early stopping threshold in the first (main effect training), second (interaction training), and third (fine-tuning) stages, respectively. In auto mode, the value is set to max(5, min(5000 * n_features / (max_iter_per_epoch * batch_size), 100)).

batch_sizeint, default=1000

The batch size. Note that it should not be larger than the training size * (1 - validation ratio).

batch_size_inferenceint, default=10000

The batch size used in the inference stage. It is imposed to avoid out-of-memory issue when dealing very large dataset.

max_iter_per_epochint, default=100

The max number of iterations per epoch. In the init stage of model fit, its value will be clipped by min(max_iter_per_epoch, int(sample_size / batch_size)). For each epoch, the data would be reshuffled and only the first “max_iter_per_epoch” batches would be used for training. It is imposed to make the training scalable for very large dataset.

val_ratiofloat, default=0.2

The validation ratio, should be greater than 0 and smaller than 1.

warm_startbool, default=True

Initialize the network by fitting a rough LGBM model. The initialization is performed by, 1) fit a LGBM model as teacher model, 2) generate random samples from the teacher model, 3) fit each subnetwork using the generated samples. And it is used for both main effect and interaction subnetwork initialization.

gam_sample_sizeint, default=5000

The sub-sample size for GAM fitting as warm_start=True.

mlp_sample_sizeint, default=1000

The generated sample size for individual subnetwork fitting as warm_start=True.

hereditybool, default=True

Whether to perform interaction screening subject to heredity constraint.

loss_thresholdfloat, default=0.01

The loss tolerance threshold for selecting fewer main effects or interactions, according to the validation performance. For instance, assume the best validation performance is achieved when using 10 main effects; if only use the top 5 main effects also gives similar validation performance, we could prune the last 5 by setting this parameter to be positive.

reg_clarityfloat, default=0.1

The regularization strength of marginal clarity constraint.

reg_monofloat, default=0.1

The regularization strength of monotonicity constraint.

mono_sample_sizeint, default=1000

As monotonicity constraint is used, we would generate some data points uniformly within the feature space per epoch, to impose the monotonicity regularization in addition to original training samples.

mono_increasing_listtuple of str, default=()

The feature name tuple subject to monotonic increasing constraint.

mono_decreasing_listtuple of str, default=()

The feature name tuple subject to monotonic decreasing constraint.

include_interaction_listtuple of (str, str), default=()

The tuple of interaction to be included for fitting, each interaction is expressed by (feature_name1, feature_name2).

boundary_clipbool, default=True

In the inference stage, whether to clip the feature values by their min and max values in the training data.

normalizebool, default=True

Whether to normalize the data before inputting to the network.

verbosebool, default=False

Whether to output the training logs.

n_jobsint, default=10

The number of cpu cores for parallel computing. -1 means all the available cpus will be used.

devicestring, default=None

The hardware device name used for training.

random_stateint, default=0

The random seed.

Attributes:
net_torch network object

The fitted GAMI-Net module.

interaction_list_list of tuples

The list of feature index pairs (tuple) for each fitted interaction.

active_main_effect_index_list of int

The selected main effect index.

active_interaction_index_list of int

The selected interaction index.

main_effect_val_loss_list of float

The validation loss as the most important main effects are sequentially added.

interaction_val_loss_list of float

The validation loss as the most important interactions are sequentially added.

time_cost_list of tuple

The time cost of each stage.

n_interactions_int

The actual number of interactions used in the fitting stage. It is greater or equal to the number of active interactions.

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:
XXnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

yarray-like of shape (n_samples, )

Target values.

alphafloat, 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:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

ynp.ndarray of shape (n_samples, )

Ground truth labels.

sample_weightarray-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: Calibrated estimator
certify_mono(n_samples=10000)

Certify whether monotonicity constraint is satisfied.

Parameters:
n_samplesint, default=10000

Size of random samples for certifying the monotonicity constraint.

Returns:
mono_statusbool

True means monotonicity constraint is satisfied.

decision_function(X, calibration: bool = True)

Computes the decision function for the given input data.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.

Returns:
logit_predictionarray, shape (n_samples,) or (n_samples, n_classes)

Array of (calibrated) logit predictions.

fit(X, y, sample_weight=None)[source]

Fit GAMINetClassifier model.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Data features.

ynp.ndarray of shape (n_samples, )

Target response.

sample_weightnp.ndarray of shape (n_samples, )

Sample weight.

Returns:
selfobject

Fitted Estimator.

get_clarity_loss(x, sample_weight=None)

Returns clarity loss of given samples.

Parameters:
xnp.ndarray of shape (n_samples, n_features)

Data features

sample_weightnp.ndarray of shape (n_samples, )

Sample weight.

Returns:
clarity_lossfloat

clarity loss.

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_mono_loss(x, sample_weight=None)

Returns monotonicity loss of given samples.

Parameters:
xnp.ndarray of shape (n_samples, n_features)

Data features.

sample_weightnp.ndarray of shape (n_samples, ), default=None

Sample weight.

Returns:
mono_lossfloat

monotonicity loss.

get_params(deep=True)

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

get_raw_output(x, main_effect=True, interaction=True)

Returns numpy array of raw prediction.

Parameters:
xnp.ndarray of shape (n_samples, n_features)

Data features.

main_effectbool, default=True

Whether to include main effects.

interactionbool, default=True

Whether to include interactions.

Returns:
prednp.ndarray of shape (n_samples, 1)

numpy array of raw prediction.

load(file_name: str)

Load the model into memory from file system.

Parameters:
file_name: str

The path and name of the file.

Returns:
estimator object
predict(X, calibration: bool = True)

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

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.

Returns:
np.ndarray: The (calibrated) final prediction
predict_effect(fidx, X)

Get the raw prediction of given feature idx.

Parameters:
fidx: tuple of int

The index of features

X: np.ndarray

The input data.

predict_interaction(x)

Returns numpy array of interactions’ raw prediction.

Parameters:
xnp.ndarray of shape (n_samples, n_features)

Data features.

Returns:
prednp.ndarray of shape (n_samples, n_interactions)

numpy array of interactions’ raw 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:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The lower and upper bounds of the prediction intervals for each sample

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

Raises:
ValueError: If fit_conformal has not been called to fit the conformal prediction model

before calling this method.

predict_main_effect(x)

Returns numpy array of main effects’ raw prediction.

Parameters:
xnp.ndarray of shape (n_samples, n_features)

Data features.

Returns:
prednp.ndarray of shape (n_samples, n_features)

numpy array of main effects’ raw prediction.

predict_proba(X, calibration: bool = True)

Predict (calibrated) probabilities for X.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will return calibrated probability if calibration is done. Otherwise, will return raw probability.

Returns:
np.ndarray: 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.

score(X, y, sample_weight=None)

Return the mean accuracy on the given test data and labels.

In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.

Parameters:
Xarray-like of shape (n_samples, n_features)

Test samples.

yarray-like of shape (n_samples,) or (n_samples, n_outputs)

True labels for X.

sample_weightarray-like of shape (n_samples,), default=None

Sample weights.

Returns:
scorefloat

Mean accuracy of self.predict(X) w.r.t. y.

set_decision_function_request(*, calibration: bool | None | str = '$UNCHANGED$') MoGAMINetClassifier

Request metadata passed to the decision_function method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to decision_function if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to decision_function.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in decision_function.

Returns:
selfobject

The updated object.

set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoGAMINetClassifier

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in fit.

Returns:
selfobject

The updated object.

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:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance

Estimator instance.

set_predict_proba_request(*, calibration: bool | None | str = '$UNCHANGED$') MoGAMINetClassifier

Request metadata passed to the predict_proba method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict_proba if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict_proba.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in predict_proba.

Returns:
selfobject

The updated object.

set_predict_request(*, calibration: bool | None | str = '$UNCHANGED$') MoGAMINetClassifier

Request metadata passed to the predict method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in predict.

Returns:
selfobject

The updated object.

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoGAMINetClassifier

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in score.

Returns:
selfobject

The updated object.

class modeva.models.MoReLUDNNClassifier(name: str = None, hidden_layer_sizes=(40, 40), max_epochs=1000, learning_rate=0.001, batch_size=500, l1_reg=1e-05, val_ratio=0.2, n_epoch_no_change=20, device=None, n_jobs=10, verbose=False, random_state=0)[source]

A deep neural network classifier using ReLU activation functions.

This model implements a multi-layer neural network for binary classification tasks, using ReLU activation functions and supporting early stopping, L1 regularization, and batch training.

Parameters:
namestr, default=None

Optional identifier for the model instance.

hidden_layer_sizestuple of int, default=(40, 40)

Architecture of the neural network specified as a tuple of integers, where each integer represents the number of neurons in a hidden layer.

max_epochsint, default=1000

Maximum number of complete passes through the training dataset.

learning_ratefloat, default=0.001

Step size used for gradient updates during optimization.

batch_sizeint, default=500

Number of training samples used in each gradient update.

l1_regfloat, default=1e-5

Strength of L1 regularization applied to model weights.

val_ratiofloat, default=0.2

Proportion of training data to use for validation in early stopping.

n_epoch_no_changeint, default=20

Number of epochs with no improvement after which training will be stopped.

devicestring, default=None

Computing device to use for training (‘cpu’, ‘cuda’, etc.).

n_jobsint, default=10

Number of parallel processes for computation (-1 for using all available cores).

verbosebool, default=False

If True, prints training progress and statistics.

random_stateint, default=0

Seed for reproducible random number generation.

Attributes:
net_torch.nn.Module

Trained neural network model.

train_epoch_loss_list of float

History of training loss values for each epoch.

validation_epoch_loss_list of float

History of validation loss values for each epoch.

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:
XXnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

yarray-like of shape (n_samples, )

Target values.

alphafloat, 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:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

ynp.ndarray of shape (n_samples, )

Ground truth labels.

sample_weightarray-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: Calibrated estimator
decision_function(X, calibration: bool = True)

Computes the decision function for the given input data.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.

Returns:
logit_predictionarray, shape (n_samples,) or (n_samples, n_classes)

Array of (calibrated) logit predictions.

fit(X, y, sample_weight=None)

Fit ReLuDNN model.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Data features.

ynp.ndarray of shape (n_samples, )

Target response.

sample_weightnp.ndarray of shape (n_samples, ), default=None

Sample weight.

Returns:
selfobject

Fitted Estimator.

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

get_raw_output(X, last_hidden_layer=False)

Returns numpy array of raw predicted value before softmax.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Data features.

last_hidden_layerboolean, default=False

Whether to output last hidden layer results.

Returns:
prednp.ndarray of shape (n_samples, )

The raw predicted value.

load(file_name: str)

Load the model into memory from file system.

Parameters:
file_name: str

The path and name of the file.

Returns:
estimator object
predict(X, calibration: bool = True)

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

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.

Returns:
np.ndarray: 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:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The lower and upper bounds of the prediction intervals for each sample

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

Raises:
ValueError: If fit_conformal has not been called to fit the conformal prediction model

before calling this method.

predict_last_hidden_layer(X)

Generate regression predictions for input samples.

Processes input features through the trained neural network to produce continuous-valued predictions.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Input samples for which to generate predictions.

Returns:
prednp.ndarray of shape (n_samples, n_last_hidden_layer_units)

Last hidden layer outputs for each input sample.

predict_proba(X, calibration: bool = True)

Predict (calibrated) probabilities for X.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will return calibrated probability if calibration is done. Otherwise, will return raw probability.

Returns:
np.ndarray: 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.

score(X, y, sample_weight=None)

Return the mean accuracy on the given test data and labels.

In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.

Parameters:
Xarray-like of shape (n_samples, n_features)

Test samples.

yarray-like of shape (n_samples,) or (n_samples, n_outputs)

True labels for X.

sample_weightarray-like of shape (n_samples,), default=None

Sample weights.

Returns:
scorefloat

Mean accuracy of self.predict(X) w.r.t. y.

set_decision_function_request(*, calibration: bool | None | str = '$UNCHANGED$') MoReLUDNNClassifier

Request metadata passed to the decision_function method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to decision_function if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to decision_function.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in decision_function.

Returns:
selfobject

The updated object.

set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoReLUDNNClassifier

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in fit.

Returns:
selfobject

The updated object.

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:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance

Estimator instance.

set_predict_proba_request(*, calibration: bool | None | str = '$UNCHANGED$') MoReLUDNNClassifier

Request metadata passed to the predict_proba method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict_proba if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict_proba.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in predict_proba.

Returns:
selfobject

The updated object.

set_predict_request(*, calibration: bool | None | str = '$UNCHANGED$') MoReLUDNNClassifier

Request metadata passed to the predict method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in predict.

Returns:
selfobject

The updated object.

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoReLUDNNClassifier

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in score.

Returns:
selfobject

The updated object.

class modeva.models.MoMoEClassifier(name: str = None, n_clusters: int = 10, cluster_method: str = 'kmeans', centroids: ndarray = None, calibration: bool = True, cv=3, feature_names: list = None, cluster_features: list = None, gating_features: list = None, ltc_baseline_n_estimators: int = 300, ltc_baseline_max_depth: int = 2, ltc_n_estimators: int = 100, ltc_max_depth: int = 5, expert: str = 'xgboost', *args, **kwargs)[source]

A Mixture of Experts (MoE) classifier that combines multiple expert models for classification tasks.

This classifier creates a weighted ensemble of expert models, where each expert specializes in different regions of the input space. The final prediction is computed by combining expert predictions weighted by the gating network’s outputs.

Parameters:
namestr, default=None

Identifier for the model instance.

n_clustersint, default=10

Number of expert models (clusters) to create.

cluster_method{‘ltc’, ‘kmeans’}, default=’kmeans’

Which algorithm to use.

  • ‘kmeans’: Use KMeans clustering algorithm directly.

  • ‘ltc’: This method (Learning Trajectory Cluster; LTC) first fits a baseline xgboost model and calculates its absolute residuals; then fits a gradient boosting models between predictors and the absolute residuals. It extracts prediction trajectories during training, applies optional weighting schemes, performs PCA dimensionality reduction, and clusters samples based on their learning patterns.

centroidsnp.ndarray, default=None

Pre-defined cluster centers of shape (n_clusters, n_features). If provided, skips the clustering step and uses these centers directly.

calibrationbool, default=True

Whether to calibrate the gating network’s probability estimates using cross-validation.

cvint, cross-validation generator or iterable, default=3

Cross-validation strategy for probability calibration. Can be: - int: number of folds for K-Fold cross-validation - cross-validation generator: custom splitting strategy - iterable: yields (train, test) splits as indices

feature_nameslist or None, default=None

The list of feature names. If None, will use “X0”, “X1”, “X2”, etc.

cluster_featureslist or None, default=None

The list of feature names used for clustering. If None, will use all features.

gating_featureslist or None, default=None

The list of feature names used for gating model fitting. If None, will use all features.

ltc_baseline_n_estimatorsint, default=300

The number of estimators used for fitting the baseline Xgboost, used when cluster_method=”ltc” only.

ltc_baseline_max_depthint, default=2

The max depth used for fitting the baseline Xgboost, used when cluster_method=”ltc” only.

ltc_n_estimatorsint, default=300

The number of estimators used for fitting the gradient boosting models in trajectory analysis, used when cluster_method=”ltc” only.

ltc_max_depthint, default=2

The max depth used for fitting the gradient boosting models in trajectory analysis, used when cluster_method=”ltc” only.

expert{“xgboost”, “lightgbm”, “catboost”}, default=”xgboost”

The backend estimator used for each cluster.

*args

Variable length argument list passed to the underlying expert model.

**kwargs

Arbitrary keyword arguments passed to the underlying expert model.

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:
XXnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

yarray-like of shape (n_samples, )

Target values.

alphafloat, 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:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

ynp.ndarray of shape (n_samples, )

Ground truth labels.

sample_weightarray-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: Calibrated estimator
decision_function(X, calibration: bool = True)

Computes the decision function for the given input data.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.

Returns:
logit_predictionarray, shape (n_samples,) or (n_samples, n_classes)

Array of (calibrated) logit predictions.

fit_cluster(cluster_id, cluster_labels, X, y, sample_weight, **kwargs)

Fit a model for a single cluster. This function is designed for parallelization.

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsmapping of string to any

Parameter names mapped to their values.

get_pr_weight(X)

Return the weight of each expert.

get_raw_output(X)

Return the raw prediction outputs.

load(file_name: str)

Load the model into memory from file system.

Parameters:
file_name: str

The path and name of the file.

Returns:
estimator object
predict(X, calibration: bool = True)

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

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.

Returns:
np.ndarray: 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:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The lower and upper bounds of the prediction intervals for each sample

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

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:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will return calibrated probability if calibration is done. Otherwise, will return raw probability.

Returns:
np.ndarray: 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.

score(X, y, sample_weight=None)

Return the mean accuracy on the given test data and labels.

In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.

Parameters:
Xarray-like of shape (n_samples, n_features)

Test samples.

yarray-like of shape (n_samples,) or (n_samples, n_outputs)

True labels for X.

sample_weightarray-like of shape (n_samples,), default=None

Sample weights.

Returns:
scorefloat

Mean accuracy of self.predict(X) w.r.t. y.

set_decision_function_request(*, calibration: bool | None | str = '$UNCHANGED$') MoMoEClassifier

Request metadata passed to the decision_function method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to decision_function if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to decision_function.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in decision_function.

Returns:
selfobject

The updated object.

set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoMoEClassifier

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in fit.

Returns:
selfobject

The updated object.

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:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance

Estimator instance.

set_predict_proba_request(*, calibration: bool | None | str = '$UNCHANGED$') MoMoEClassifier

Request metadata passed to the predict_proba method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict_proba if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict_proba.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in predict_proba.

Returns:
selfobject

The updated object.

set_predict_request(*, calibration: bool | None | str = '$UNCHANGED$') MoMoEClassifier

Request metadata passed to the predict method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in predict.

Returns:
selfobject

The updated object.

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoMoEClassifier

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in score.

Returns:
selfobject

The updated object.

class modeva.models.ModelBaseClassifier[source]

Base Class for Modeva Classifiers.

calibrate_interval(X, y, alpha=0.1)[source]

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:
XXnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

yarray-like of shape (n_samples, )

Target values.

alphafloat, 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')[source]

Fit the calibration method on the model’s predictions.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

ynp.ndarray of shape (n_samples, )

Ground truth labels.

sample_weightarray-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: Calibrated estimator
decision_function(X, calibration: bool = True)[source]

Computes the decision function for the given input data.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.

Returns:
logit_predictionarray, shape (n_samples,) or (n_samples, n_classes)

Array of (calibrated) logit predictions.

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

load(file_name: str)

Load the model into memory from file system.

Parameters:
file_name: str

The path and name of the file.

Returns:
estimator object
predict(X, calibration: bool = True)[source]

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

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.

Returns:
np.ndarray: The (calibrated) final prediction
predict_interval(X)[source]

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:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

Returns:
np.ndarray: The lower and upper bounds of the prediction intervals for each sample

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

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)[source]

Predict (calibrated) probabilities for X.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)

Feature matrix for prediction.

calibrationbool, default=True

If True, will return calibrated probability if calibration is done. Otherwise, will return raw probability.

Returns:
np.ndarray: 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_decision_function_request(*, calibration: bool | None | str = '$UNCHANGED$') ModelBaseClassifier

Request metadata passed to the decision_function method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to decision_function if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to decision_function.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in decision_function.

Returns:
selfobject

The updated object.

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:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance

Estimator instance.

set_predict_proba_request(*, calibration: bool | None | str = '$UNCHANGED$') ModelBaseClassifier

Request metadata passed to the predict_proba method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict_proba if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict_proba.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in predict_proba.

Returns:
selfobject

The updated object.

set_predict_request(*, calibration: bool | None | str = '$UNCHANGED$') ModelBaseClassifier

Request metadata passed to the predict method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in predict.

Returns:
selfobject

The updated object.