Interpretable Models
Regression and classification model wrappers available in Modeva.
Regression
MoElasticNet
A lightweight wrapper of sklearn.linear_model.ElasticNet.
Note that categorical features are preprocessed by one-hot encoding in this wrapper.
Parameters
name : str, default=None
Identifier for the model instance.
feature_names : list or None, default=None
The list of feature names.
feature_types : list 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.
__init__(name: str=None, feature_names=None, feature_types=None, *args, **kwargs)
get_params(deep=True)
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
params : dict
Parameter names mapped to their values.
fit(X, y, sample_weight=None)
Fits the estimator to the provided data.
Parameters
X : array-like, shape (n_samples, n_features)
Training data.
y : array-like, shape (n_samples,) or (n_samples, n_outputs)
Target values.
sample_weight : array-like, shape (n_samples,), optional
Sample weights.
Returns
self : object
Fitted model instance.
set_params(**params)
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as ~sklearn.pipeline.Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Parameters
**params : dict
Estimator parameters.
Returns
self : estimator instance
reset_calibrate_interval()
reset_calibrate_proba()
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
X : X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : array-like of shape (n_samples, )
Target values.
alpha : float, default=0.1
Expected miscoverage for the conformal prediction.
max_depth : int, 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.
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
X : np.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(X)
Model predictions, calling the child class’s ‘_predict’ method.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
Returns
np.ndarray: The (calibrated) final prediction
name()
version()
save(file_name: str)
Save the model into file system.
Parameters
file_name: str
The path and name of the file.
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_effect(fidx, X)
extract_model_info(X)
interpret(dataset)
MoDecisionTreeRegressor
A lightweight wrapper of sklearn.tree.DecisionTreeRegressor.
Parameters
name : str, 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.
__init__(name: str=None, *args, **kwargs)
get_params(deep=True)
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
params : dict
Parameter names mapped to their values.
interpret(dataset)
Interpret the decision tree with given dataset.
Parameters
dataset : DataSet instance
The dataset for interpreting the model.
Returns
An instance of InterpretDecisionTree
set_params(**params)
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as ~sklearn.pipeline.Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Parameters
**params : dict
Estimator parameters.
Returns
self : estimator instance
fit(X, y, sample_weight=None, **kwargs)
Fits the estimator to the provided data.
Parameters
X : array-like, shape (n_samples, n_features)
Training data.
y : array-like, shape (n_samples,) or (n_samples, n_outputs)
Target values.
sample_weight : array-like, shape (n_samples,), default=None
Sample weights.
Returns
self : object
Fitted model instance.
reset_calibrate_interval()
reset_calibrate_proba()
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
X : X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : array-like of shape (n_samples, )
Target values.
alpha : float, default=0.1
Expected miscoverage for the conformal prediction.
max_depth : int, 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.
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
X : np.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(X)
Model predictions, calling the child class’s ‘_predict’ method.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
Returns
np.ndarray: The (calibrated) final prediction
name()
version()
save(file_name: str)
Save the model into file system.
Parameters
file_name: str
The path and name of the file.
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
MoRandomForestRegressor
A lightweight wrapper of sklearn.ensemble.RandomForestRegressor.
Parameters
name : str, 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.
__init__(name: str=None, *args, **kwargs)
get_params(deep=True)
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
params : dict
Parameter names mapped to their values.
set_params(**params)
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as ~sklearn.pipeline.Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Parameters
**params : dict
Estimator parameters.
Returns
self : estimator instance
fit(X, y, sample_weight=None, **kwargs)
Fits the estimator to the provided data.
Parameters
X : array-like, shape (n_samples, n_features)
Training data.
y : array-like, shape (n_samples,) or (n_samples, n_outputs)
Target values.
sample_weight : array-like, shape (n_samples,), default=None
Sample weights.
Returns
self : object
Fitted model instance.
reset_calibrate_interval()
reset_calibrate_proba()
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
X : X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : array-like of shape (n_samples, )
Target values.
alpha : float, default=0.1
Expected miscoverage for the conformal prediction.
max_depth : int, 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.
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
X : np.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(X)
Model predictions, calling the child class’s ‘_predict’ method.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
Returns
np.ndarray: The (calibrated) final prediction
name()
version()
save(file_name: str)
Save the model into file system.
Parameters
file_name: str
The path and name of the file.
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
extract_model_info(X, feature_names, feature_types)
Extract the tree information as functional ANOVA format.
Parameters
X : array-like
Input features.
feature_names: list of str
The feature names.
feature_types: list of str
The feature types.
interpret(dataset)
Interpret the ensemble tree model with given dataset using functional ANOVA framework.
Parameters
dataset : DataSet instance
The dataset for interpreting the model.
Returns
An instance of InterpretFANOVA
MoGradientBoostingRegressor
A lightweight wrapper of sklearn.ensemble.GradientBoostingRegressor.
Parameters
name : str, 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.
__init__(name: str=None, *args, **kwargs)
get_params(deep=True)
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
params : dict
Parameter names mapped to their values.
set_params(**params)
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as ~sklearn.pipeline.Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Parameters
**params : dict
Estimator parameters.
Returns
self : estimator instance
fit(X, y, sample_weight=None, **kwargs)
Fits the estimator to the provided data.
Parameters
X : array-like, shape (n_samples, n_features)
Training data.
y : array-like, shape (n_samples,) or (n_samples, n_outputs)
Target values.
sample_weight : array-like, shape (n_samples,), default=None
Sample weights.
Returns
self : object
Fitted model instance.
reset_calibrate_interval()
reset_calibrate_proba()
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
X : X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : array-like of shape (n_samples, )
Target values.
alpha : float, default=0.1
Expected miscoverage for the conformal prediction.
max_depth : int, 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.
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
X : np.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(X)
Model predictions, calling the child class’s ‘_predict’ method.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
Returns
np.ndarray: The (calibrated) final prediction
name()
version()
save(file_name: str)
Save the model into file system.
Parameters
file_name: str
The path and name of the file.
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
extract_model_info(X, feature_names, feature_types)
Extract the tree information as functional ANOVA format.
Parameters
X : array-like
Input features.
feature_names: list of str
The feature names.
feature_types: list of str
The feature types.
interpret(dataset)
Interpret the ensemble tree model with given dataset using functional ANOVA framework.
Parameters
dataset : DataSet instance
The dataset for interpreting the model.
Returns
An instance of InterpretFANOVA
MoXGBRegressor
A lightweight wrapper of xgboost.XGBRegressor.
Parameters
name : str, 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.
__init__(name: str=None, *args, **kwargs)
get_params(deep=True)
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
params : dict
Parameter names mapped to their values.
set_params(**params)
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as ~sklearn.pipeline.Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Parameters
**params : dict
Estimator parameters.
Returns
self : estimator instance
fit(X, y, sample_weight=None, **kwargs)
Fits the estimator to the provided data.
Parameters
X : array-like, shape (n_samples, n_features)
Training data.
y : array-like, shape (n_samples,) or (n_samples, n_outputs)
Target values.
sample_weight : array-like, shape (n_samples,), default=None
Sample weights.
Returns
self : object
Fitted model instance.
reset_calibrate_interval()
reset_calibrate_proba()
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
X : X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : array-like of shape (n_samples, )
Target values.
alpha : float, default=0.1
Expected miscoverage for the conformal prediction.
max_depth : int, 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.
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
X : np.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(X)
Model predictions, calling the child class’s ‘_predict’ method.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
Returns
np.ndarray: The (calibrated) final prediction
name()
version()
save(file_name: str)
Save the model into file system.
Parameters
file_name: str
The path and name of the file.
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
extract_model_info(X, feature_names, feature_types)
Extract the tree information as functional ANOVA format.
Parameters
X : array-like
Input features.
feature_names: list of str
The feature names.
feature_types: list of str
The feature types.
interpret(dataset)
Interpret the ensemble tree model with given dataset using functional ANOVA framework.
Parameters
dataset : DataSet instance
The dataset for interpreting the model.
Returns
An instance of InterpretFANOVA
MoLGBMRegressor
A lightweight wrapper of lightgbm.LGBMRegressor.
Parameters
name : str, 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.
__init__(name: str=None, *args, **kwargs)
get_params(deep=True)
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
params : dict
Parameter names mapped to their values.
set_params(**params)
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as ~sklearn.pipeline.Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Parameters
**params : dict
Estimator parameters.
Returns
self : estimator instance
fit(X, y, sample_weight=None, **kwargs)
Fits the estimator to the provided data.
Parameters
X : array-like, shape (n_samples, n_features)
Training data.
y : array-like, shape (n_samples,) or (n_samples, n_outputs)
Target values.
sample_weight : array-like, shape (n_samples,), default=None
Sample weights.
Returns
self : object
Fitted model instance.
reset_calibrate_interval()
reset_calibrate_proba()
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
X : X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : array-like of shape (n_samples, )
Target values.
alpha : float, default=0.1
Expected miscoverage for the conformal prediction.
max_depth : int, 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.
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
X : np.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(X)
Model predictions, calling the child class’s ‘_predict’ method.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
Returns
np.ndarray: The (calibrated) final prediction
name()
version()
save(file_name: str)
Save the model into file system.
Parameters
file_name: str
The path and name of the file.
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
extract_model_info(X, feature_names, feature_types)
Extract the tree information as functional ANOVA format.
Parameters
X : array-like
Input features.
feature_names: list of str
The feature names.
feature_types: list of str
The feature types.
interpret(dataset)
Interpret the ensemble tree model with given dataset using functional ANOVA framework.
Parameters
dataset : DataSet instance
The dataset for interpreting the model.
Returns
An instance of InterpretFANOVA
MoCatBoostRegressor
A lightweight wrapper of catboost.CatBoostRegressor.
Parameters
name : str, 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.
__init__(name: str=None, *args, **kwargs)
get_params(deep=True)
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
params : dict
Parameter names mapped to their values.
set_params(**params)
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as ~sklearn.pipeline.Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Parameters
**params : dict
Estimator parameters.
Returns
self : estimator instance
fit(X, y, sample_weight=None, **kwargs)
Fits the estimator to the provided data.
Parameters
X : array-like, shape (n_samples, n_features)
Training data.
y : array-like, shape (n_samples,) or (n_samples, n_outputs)
Target values.
sample_weight : array-like, shape (n_samples,), default=None
Sample weights.
Returns
self : object
Fitted model instance.
reset_calibrate_interval()
reset_calibrate_proba()
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
X : X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : array-like of shape (n_samples, )
Target values.
alpha : float, default=0.1
Expected miscoverage for the conformal prediction.
max_depth : int, 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.
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
X : np.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(X)
Model predictions, calling the child class’s ‘_predict’ method.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
Returns
np.ndarray: The (calibrated) final prediction
name()
version()
save(file_name: str)
Save the model into file system.
Parameters
file_name: str
The path and name of the file.
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
extract_model_info(X, feature_names, feature_types)
Extract the tree information as functional ANOVA format.
Parameters
X : array-like
Input features.
feature_names: list of str
The feature names.
feature_types: list of str
The feature types.
interpret(dataset)
Interpret the ensemble tree model with given dataset using functional ANOVA framework.
Parameters
dataset : DataSet instance
The dataset for interpreting the model.
Returns
An instance of InterpretFANOVA
MoGLMTreeRegressor
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
name : str, default=None
The name of the model.
max_depth : int, default=3
The max number of depth.
min_impurity_decrease : float, default=0
Minimum impurity decrease when splitting a node.
min_samples_leaf : int, default=50
Minimum number of samples for constructing a leaf node.
split_custom : dict, default=None
The custom split points for each feature.
n_screen_grid : int, default=1
The number of candidate split points for rough screening.
n_feature_search : int, default=10
The number of candidate features selected by rough screening.
n_split_grid : int, default=20
The number of candidate split points for fine-grained search.
reg_lambda : float, default=0.1
The level of L1 regularization strength.
clip_predict : bool, default=False
Whether to clip the prediction results if it is outside the training data prediction.
simplified : bool, default=True
Whether to use partial linear regression for search the split feature and points.
random_state : int, default=0
Determines random number generation for weights and bias initialization.
Attributes
tree : object
The internal tree structure.
__init__(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)
fit(X, y, sample_weight=None)
decision_rule(node_id)
decision_path_indice(x, node_id)
decision_path(x)
get_raw_output(x)
output
Parameters ---------x : array-like of shape (n_samples, n_features) containing the input dataset Returns -------np.ndarray of shape (n_samples,),
extract_model_info(X, feature_names, feature_types)
interpret(dataset)
reset_calibrate_interval()
reset_calibrate_proba()
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
X : X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : array-like of shape (n_samples, )
Target values.
alpha : float, default=0.1
Expected miscoverage for the conformal prediction.
max_depth : int, 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.
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
X : np.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(X)
Model predictions, calling the child class’s ‘_predict’ method.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
Returns
np.ndarray: The (calibrated) final prediction
name()
version()
save(file_name: str)
Save the model into file system.
Parameters
file_name: str
The path and name of the file.
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
MoGLMTreeBoostRegressor
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
name : str, default=None
Model identifier name for reference.
n_estimators : int, default=100
Number of boosting rounds (trees) to fit.
max_depth : int, default=1
Maximum tree depth. Model is most interpretable when depth=1.
learning_rate : float, default=1.0
Shrinkage rate applied to each tree’s contribution.
n_epoch_no_change : int, default=5
Early stopping rounds - training stops if validation loss doesn’t improve.
min_samples_leaf : int, default=50
Minimum samples required in a leaf node.
min_impurity_decrease : float, default=0
Minimum required decrease in impurity to split a node.
split_custom : dict, default=None
Custom split points specified per feature.
n_screen_grid : int, default=1
Grid size for initial split point screening.
n_feature_search : int, default=5
Number of features to consider after screening.
n_split_grid : int, default=20
Grid size for fine-grained split point search.
reg_lambda : float, default=0.1
L1 regularization strength parameter.
clip_predict : bool, default=False
Whether to clip predictions to training data range.
simplified : bool, default=True
Use simplified partial linear regression for splits.
val_ratio : float, default=0.2
Proportion of data used for validation.
verbose : bool, default=False
Whether to print training progress.
random_state : int, default=0
Random seed for reproducibility.
Attributes
estimators : list
Fitted GLMTree models.
n_features_in : int
Number of input features.
__init__(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)
fit(X, y, sample_weight=None)
fit the GLMTree Boosting model
Parameters ---------X : array-like of shape (n_samples, n_features) containing the input dataset y : array-like of shape (n_samples,) containing target values sample_weight : array-like of shape (n_samples,) containing the weight of each sample Returns -------object self : Estimator instance.
get_raw_output(x)
output
Parameters ---------x : array-like of shape (n_samples, n_features) containing the input dataset Returns -------np.ndarray of shape (n_samples,),
extract_model_info(X, feature_names, feature_types)
interpret(dataset)
reset_calibrate_interval()
reset_calibrate_proba()
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
X : X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : array-like of shape (n_samples, )
Target values.
alpha : float, default=0.1
Expected miscoverage for the conformal prediction.
max_depth : int, 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.
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
X : np.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(X)
Model predictions, calling the child class’s ‘_predict’ method.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
Returns
np.ndarray: The (calibrated) final prediction
name()
version()
save(file_name: str)
Save the model into file system.
Parameters
file_name: str
The path and name of the file.
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
MoNeuralTreeRegressor
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
name : str, default=None
Custom identifier for the model instance.
estimator : MoGLMTreeBoostRegressor, default=None
Pre-fitted or unfitted GLMTree regressor for initialization. If None, creates a new instance.
feature_names : list of str, default=None
Names of input features for interpretability.
val_ratio : float, default=0.2
Proportion of data used for validation during training (0 to 1).
device : str, default=None
Computing device for training (‘cpu’, ‘cuda’, etc.).
verbose : bool, default=False
If True, prints training progress and statistics.
random_state : int, default=0
Seed for reproducible random operations.
nn_temperature : float, default=0.0001
Smoothing parameter for neural network activation.
nn_lr : float, default=0.001
Learning rate for neural network optimization.
nn_max_epochs : int, default=200
Maximum number of training epochs.
nn_batch_size : int, default=200
Number of samples per training batch.
nn_n_epoch_no_change : int, default=10
Early stopping patience - number of epochs without improvement.
reg_mono : float, default=0.1
Strength of monotonicity regularization.
mono_sample_size : int, default=1000
Number of random samples for monotonicity regularization.
mono_increasing_list : tuple of str, default=()
Features that should have monotonically increasing relationships.
mono_decreasing_list : tuple of str, default=()
Features that should have monotonically decreasing relationships.
**kwargs
Additional parameters passed to MoGLMTreeBoostRegressor.
Attributes
net : object
The internal Pytorch network object.
__init__(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)
set_params(**params)
get_params(deep=True)
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 -------params : mapping of string to any Parameter names mapped to their values.
get_mono_loss(x, sample_weight=None)
Returns monotonicity loss of given samples.
Parameters
x : np.ndarray of shape (n_samples, n_features)
Data features.
sample_weight : np.ndarray of shape (n_samples, ), default=None
Sample weight.
Returns
mono_loss : float
monotonicity loss.
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_samples : int, default=10000
Number of random samples to use for verification.
Returns
mono_status : bool
True if monotonicity constraints are satisfied, False otherwise.
fit(X, y, sample_weight=None)
get_aggregate_output(X)
Returns numpy array of raw prediction.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Data features.
Returns
pred : np.ndarray of shape (n_samples, 1)
numpy array of raw prediction.
get_sparsity(x)
extract_model_info(X, feature_names, feature_types)
interpret(dataset)
reset_calibrate_interval()
reset_calibrate_proba()
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
X : X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : array-like of shape (n_samples, )
Target values.
alpha : float, default=0.1
Expected miscoverage for the conformal prediction.
max_depth : int, 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.
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
X : np.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(X)
Model predictions, calling the child class’s ‘_predict’ method.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
Returns
np.ndarray: The (calibrated) final prediction
name()
version()
save(file_name: str)
Save the model into file system.
Parameters
file_name: str
The path and name of the file.
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
MoGAMINetRegressor
Generalized additive model with pairwise interaction regressor.
Parameters
name : str, default=None
The name of the model.
feature_names : list or None, default=None
The list of feature names. If None, will use “X0”, “X1”, “X2”, etc.
feature_types : list or None, default=None
The list of feature types. Available types include “numerical” and “categorical”. If None, will use numerical for all features.
interact_num : int, default=10
The max number of interactions to be included in the second stage training.
subnet_size_main_effect : tuple of int, default=(20, )
The hidden layer architecture of each subnetwork in the main effect block.
subnet_size_interaction : tuple 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_epochs : tuple 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_rates : tuple 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_thres : tuple 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_size : int, default=1000
The batch size. Note that it should not be larger than the training size * (1 - validation ratio).
batch_size_inference : int, 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_epoch : int, 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_ratio : float, default=0.2
The validation ratio, should be greater than 0 and smaller than 1.
warm_start : bool, 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_size : int, default=5000
The sub-sample size for GAM fitting as warm_start=True.
mlp_sample_size : int, default=1000
The generated sample size for individual subnetwork fitting as warm_start=True.
heredity : bool, default=True
Whether to perform interaction screening subject to heredity constraint.
loss_threshold : float, 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_clarity : float, default=0.1
The regularization strength of marginal clarity constraint.
reg_mono : float, default=0.1
The regularization strength of monotonicity constraint.
mono_sample_size : int, 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_list : tuple of str, default=()
The feature name tuple subject to monotonic increasing constraint.
mono_decreasing_list : tuple of str, default=()
The feature name tuple subject to monotonic decreasing constraint.
include_interaction_list : tuple of (str, str), default=()
The tuple of interaction to be included for fitting, each interaction is expressed by (feature_name1, feature_name2).
boundary_clip : bool, default=True
In the inference stage, whether to clip the feature values by their min and max values in the training data.
normalize : bool, default=True
Whether to normalize the data before inputting to the network.
verbose : bool, default=False
Whether to output the training logs.
n_jobs : int, default=10
The number of cpu cores for parallel computing. -1 means all the available cpus will be used.
device : string, default=None
The hardware device name used for training.
random_state : int, 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.
__init__(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)
fit(X, y, sample_weight=None)
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
X : np.ndarray of shape (n_samples, n_features)
Training data features.
y : np.ndarray of shape (n_samples,)
Target values for regression.
sample_weight : np.ndarray of shape (n_samples,), default=None
Individual weights for each sample. If None, all samples are weighted equally.
Returns
self : object
Returns the fitted estimator.
get_clarity_loss(x, sample_weight=None)
Returns clarity loss of given samples.
Parameters
x : np.ndarray of shape (n_samples, n_features)
Data features
sample_weight : np.ndarray of shape (n_samples, )
Sample weight.
Returns
clarity_loss : float
clarity loss.
get_mono_loss(x, sample_weight=None)
Returns monotonicity loss of given samples.
Parameters
x : np.ndarray of shape (n_samples, n_features)
Data features.
sample_weight : np.ndarray of shape (n_samples, ), default=None
Sample weight.
Returns
mono_loss : float
monotonicity loss.
certify_mono(n_samples=10000)
Certify whether monotonicity constraint is satisfied.
Parameters
n_samples : int, default=10000
Size of random samples for certifying the monotonicity constraint.
Returns
mono_status : bool
True means monotonicity constraint is satisfied.
get_raw_output(x, main_effect=True, interaction=True)
Returns numpy array of raw prediction.
Parameters
x : np.ndarray of shape (n_samples, n_features)
Data features.
main_effect : bool, default=True
Whether to include main effects.
interaction : bool, default=True
Whether to include interactions.
Returns
pred : np.ndarray of shape (n_samples, 1)
numpy array of raw prediction.
predict_main_effect(x)
Returns numpy array of main effects’ raw prediction.
Parameters
x : np.ndarray of shape (n_samples, n_features)
Data features.
Returns
pred : np.ndarray of shape (n_samples, n_features)
numpy array of main effects’ raw prediction.
predict_interaction(x)
Returns numpy array of interactions’ raw prediction.
Parameters
x : np.ndarray of shape (n_samples, n_features)
Data features.
Returns
pred : np.ndarray of shape (n_samples, n_interactions)
numpy array of interactions’ raw 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.
extract_model_info(feature_names)
interpret(dataset)
reset_calibrate_interval()
reset_calibrate_proba()
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
X : X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : array-like of shape (n_samples, )
Target values.
alpha : float, default=0.1
Expected miscoverage for the conformal prediction.
max_depth : int, 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.
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
X : np.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(X)
Model predictions, calling the child class’s ‘_predict’ method.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
Returns
np.ndarray: The (calibrated) final prediction
name()
version()
save(file_name: str)
Save the model into file system.
Parameters
file_name: str
The path and name of the file.
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
MoReLUDNNRegressor
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
name : str, default=None
Optional identifier for the model instance.
hidden_layer_sizes : tuple 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_epochs : int, default=1000
Maximum number of complete passes through the training dataset.
learning_rate : float, default=0.001
Step size used for gradient updates during optimization.
batch_size : int, default=500
Number of training samples used in each gradient update.
l1_reg : float, default=1e-5
Strength of L1 regularization applied to model weights.
val_ratio : float, default=0.2
Proportion of training data to use for validation in early stopping.
n_epoch_no_change : int, default=20
Number of epochs with no improvement after which training will be stopped.
device : string, default=None
Computing device to use for training (‘cpu’, ‘cuda’, etc.).
n_jobs : int, default=10
Number of parallel processes for computation (-1 for using all available cores).
verbose : bool, default=False
If True, prints training progress and statistics.
random_state : int, 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.
__init__(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)
get_weights()
get_biases()
fit(X, y, sample_weight=None)
Fit ReLuDNN model.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Data features.
y : np.ndarray of shape (n_samples, )
Target response.
sample_weight : np.ndarray of shape (n_samples, ), default=None
Sample weight.
Returns
self : object
Fitted Estimator.
get_raw_output(X, last_hidden_layer=False)
Returns numpy array of raw predicted value before softmax.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Data features.
last_hidden_layer : boolean, default=False
Whether to output last hidden layer results.
Returns
pred : np.ndarray of shape (n_samples, )
The raw predicted value.
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
X : np.ndarray of shape (n_samples, n_features)
Input samples for which to generate predictions.
Returns
pred : np.ndarray of shape (n_samples, n_last_hidden_layer_units)
Last hidden layer outputs for each input sample.
interpret(dataset)
reset_calibrate_interval()
reset_calibrate_proba()
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
X : X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : array-like of shape (n_samples, )
Target values.
alpha : float, default=0.1
Expected miscoverage for the conformal prediction.
max_depth : int, 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.
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
X : np.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(X)
Model predictions, calling the child class’s ‘_predict’ method.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
Returns
np.ndarray: The (calibrated) final prediction
name()
version()
save(file_name: str)
Save the model into file system.
Parameters
file_name: str
The path and name of the file.
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
MoMoERegressor
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
name : str, default=None
Identifier for the model instance.
n_clusters : int, 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.
centroids : np.ndarray, default=None
Pre-defined cluster centers of shape (n_clusters, n_features). If provided, skips the clustering step and uses these centers directly.
calibration : bool, default=True
Whether to calibrate the gating network’s probability estimates using cross-validation.
cv : int, 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_names : list or None, default=None
The list of feature names. If None, will use “X0”, “X1”, “X2”, etc.
cluster_features : list or None, default=None
The list of feature names used for clustering. If None, will use all features.
gating_features : list or None, default=None
The list of feature names used for gating model fitting. If None, will use all features.
ltc_baseline_n_estimators : int, default=300
The number of estimators used for fitting the baseline Xgboost, used when cluster_method=“ltc” only.
ltc_baseline_max_depth : int, default=2
The max depth used for fitting the baseline Xgboost, used when cluster_method=“ltc” only.
ltc_n_estimators : int, default=300
The number of estimators used for fitting the gradient boosting models in trajectory analysis, used when cluster_method=“ltc” only.
ltc_max_depth : int, 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.
__init__(name: str=None, n_clusters: int=10, cluster_method: str='kmeans', centroids: np.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)
set_params(**params)
get_params(deep=True)
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
params : mapping of string to any
Parameter names mapped to their values.
fit_cluster(cluster_id, cluster_labels, X, y, sample_weight, **kwargs)
Fit a model for a single cluster. This function is designed for parallelization.
fit(X, y, sample_weight=None, **kwargs)
get_raw_output(X)
Return the raw prediction outputs.
get_pr_weight(X)
Return the weight of each expert.
interpret(dataset)
reset_calibrate_interval()
reset_calibrate_proba()
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
X : X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : array-like of shape (n_samples, )
Target values.
alpha : float, default=0.1
Expected miscoverage for the conformal prediction.
max_depth : int, 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.
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
X : np.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(X)
Model predictions, calling the child class’s ‘_predict’ method.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
Returns
np.ndarray: The (calibrated) final prediction
name()
version()
save(file_name: str)
Save the model into file system.
Parameters
file_name: str
The path and name of the file.
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
ModelBaseRegressor
Base Class for Modeva Regressors.
reset_calibrate_interval()
reset_calibrate_proba()
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
X : X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : array-like of shape (n_samples, )
Target values.
alpha : float, default=0.1
Expected miscoverage for the conformal prediction.
max_depth : int, 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.
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
X : np.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(X)
Model predictions, calling the child class’s ‘_predict’ method.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
Returns
np.ndarray: The (calibrated) final prediction
name()
version()
save(file_name: str)
Save the model into file system.
Parameters
file_name: str
The path and name of the file.
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
MoLogisticRegression
A lightweight wrapper of sklearn.linear_model.LogisticRegression.
Note that categorical features are preprocessed by one-hot encoding in this wrapper.
Parameters
name : str, default=None
Identifier for the model instance.
feature_names : list or None, default=None
The list of feature names.
feature_types : list 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.
__init__(name: str=None, feature_names=None, feature_types=None, *args, **kwargs)
get_params(deep=True)
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
params : dict
Parameter names mapped to their values.
fit(X, y, sample_weight=None)
Fits the estimator to the provided data.
Parameters
X : array-like, shape (n_samples, n_features)
Training data.
y : array-like, shape (n_samples,) or (n_samples, n_outputs)
Target values.
sample_weight : array-like, shape (n_samples,), optional
Sample weights.
Returns
self : object
Fitted model instance.
set_params(**params)
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as ~sklearn.pipeline.Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Parameters
**params : dict
Estimator parameters.
Returns
self : estimator instance
reset_calibrate_interval()
reset_calibrate_proba()
calibrate_interval(X, y, alpha=0.1)
Fit a conformal prediction model to the given data.
This method computes the model’s prediction interval calibrated to the given data.
It computes the calibration quantile based on predicted probabilities for the positive class.
Parameters
X : X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : array-like of shape (n_samples, )
Target values.
alpha : float, default=0.1
Expected miscoverage for the conformal prediction.
Raises
ValueError: If the model is neither a regressor nor a classifier.
predict_interval(X)
Predict the prediction set for the given data based on the conformal prediction model.
This method computes the model prediction interval (regression) or prediction sets (classification) using conformal prediction.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
Returns
np.ndarray: 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.
calibrate_proba(X, y, sample_weight=None, method='sigmoid')
Fit the calibration method on the model’s predictions.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : np.ndarray of shape (n_samples, )
Ground truth labels.
sample_weight : array-like, shape (n_samples,), default=None
Sample weights.
method : {‘sigmoid’, ‘isotonic’}, default=‘sigmoid’
The calibration method.
- ‘sigmoid’: Platt’s method, i.e., fit a logistic regression on predicted probabilities and y
- ‘isotonic’: Fit an isotonic regression on predicted probabilities and y.
Returns
self: Calibrated estimator
predict_proba(X, calibration: bool=True)
Predict (calibrated) probabilities for X.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will return calibrated probability if calibration is done. Otherwise, will return raw probability.
Returns
np.ndarray: The (calibrated) predicted probabilities
predict(X, calibration: bool=True)
Model predictions, calling the child class’s ‘_predict’ method.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.
Returns
np.ndarray: The (calibrated) final prediction
decision_function(X, calibration: bool=True)
Computes the decision function for the given input data.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.
Returns
logit_prediction : array, shape (n_samples,) or (n_samples, n_classes)
Array of (calibrated) logit predictions.
name()
version()
save(file_name: str)
Save the model into file system.
Parameters
file_name: str
The path and name of the file.
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_effect(fidx, X)
extract_model_info(X)
interpret(dataset)
MoDecisionTreeClassifier
A lightweight wrapper of sklearn.tree.DecisionTreeClassifier.
Parameters
name : str, 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.
__init__(name: str=None, *args, **kwargs)
get_params(deep=True)
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
params : dict
Parameter names mapped to their values.
interpret(dataset)
Interpret the decision tree with given dataset.
Parameters
dataset : DataSet instance
The dataset for interpreting the model.
Returns
An instance of InterpretDecisionTree
set_params(**params)
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as ~sklearn.pipeline.Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Parameters
**params : dict
Estimator parameters.
Returns
self : estimator instance
fit(X, y, sample_weight=None, **kwargs)
Fits the estimator to the provided data.
Parameters
X : array-like, shape (n_samples, n_features)
Training data.
y : array-like, shape (n_samples,) or (n_samples, n_outputs)
Target values.
sample_weight : array-like, shape (n_samples,), default=None
Sample weights.
Returns
self : object
Fitted model instance.
reset_calibrate_interval()
reset_calibrate_proba()
calibrate_interval(X, y, alpha=0.1)
Fit a conformal prediction model to the given data.
This method computes the model’s prediction interval calibrated to the given data.
It computes the calibration quantile based on predicted probabilities for the positive class.
Parameters
X : X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : array-like of shape (n_samples, )
Target values.
alpha : float, default=0.1
Expected miscoverage for the conformal prediction.
Raises
ValueError: If the model is neither a regressor nor a classifier.
predict_interval(X)
Predict the prediction set for the given data based on the conformal prediction model.
This method computes the model prediction interval (regression) or prediction sets (classification) using conformal prediction.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
Returns
np.ndarray: 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.
calibrate_proba(X, y, sample_weight=None, method='sigmoid')
Fit the calibration method on the model’s predictions.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : np.ndarray of shape (n_samples, )
Ground truth labels.
sample_weight : array-like, shape (n_samples,), default=None
Sample weights.
method : {‘sigmoid’, ‘isotonic’}, default=‘sigmoid’
The calibration method.
- ‘sigmoid’: Platt’s method, i.e., fit a logistic regression on predicted probabilities and y
- ‘isotonic’: Fit an isotonic regression on predicted probabilities and y.
Returns
self: Calibrated estimator
predict_proba(X, calibration: bool=True)
Predict (calibrated) probabilities for X.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will return calibrated probability if calibration is done. Otherwise, will return raw probability.
Returns
np.ndarray: The (calibrated) predicted probabilities
predict(X, calibration: bool=True)
Model predictions, calling the child class’s ‘_predict’ method.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.
Returns
np.ndarray: The (calibrated) final prediction
decision_function(X, calibration: bool=True)
Computes the decision function for the given input data.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.
Returns
logit_prediction : array, shape (n_samples,) or (n_samples, n_classes)
Array of (calibrated) logit predictions.
name()
version()
save(file_name: str)
Save the model into file system.
Parameters
file_name: str
The path and name of the file.
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
MoRandomForestClassifier
A lightweight wrapper of sklearn.ensemble.RandomForestClassifier.
Parameters
name : str, 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.
__init__(name: str=None, *args, **kwargs)
get_params(deep=True)
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
params : dict
Parameter names mapped to their values.
set_params(**params)
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as ~sklearn.pipeline.Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Parameters
**params : dict
Estimator parameters.
Returns
self : estimator instance
fit(X, y, sample_weight=None, **kwargs)
Fits the estimator to the provided data.
Parameters
X : array-like, shape (n_samples, n_features)
Training data.
y : array-like, shape (n_samples,) or (n_samples, n_outputs)
Target values.
sample_weight : array-like, shape (n_samples,), default=None
Sample weights.
Returns
self : object
Fitted model instance.
reset_calibrate_interval()
reset_calibrate_proba()
calibrate_interval(X, y, alpha=0.1)
Fit a conformal prediction model to the given data.
This method computes the model’s prediction interval calibrated to the given data.
It computes the calibration quantile based on predicted probabilities for the positive class.
Parameters
X : X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : array-like of shape (n_samples, )
Target values.
alpha : float, default=0.1
Expected miscoverage for the conformal prediction.
Raises
ValueError: If the model is neither a regressor nor a classifier.
predict_interval(X)
Predict the prediction set for the given data based on the conformal prediction model.
This method computes the model prediction interval (regression) or prediction sets (classification) using conformal prediction.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
Returns
np.ndarray: 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.
calibrate_proba(X, y, sample_weight=None, method='sigmoid')
Fit the calibration method on the model’s predictions.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : np.ndarray of shape (n_samples, )
Ground truth labels.
sample_weight : array-like, shape (n_samples,), default=None
Sample weights.
method : {‘sigmoid’, ‘isotonic’}, default=‘sigmoid’
The calibration method.
- ‘sigmoid’: Platt’s method, i.e., fit a logistic regression on predicted probabilities and y
- ‘isotonic’: Fit an isotonic regression on predicted probabilities and y.
Returns
self: Calibrated estimator
predict_proba(X, calibration: bool=True)
Predict (calibrated) probabilities for X.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will return calibrated probability if calibration is done. Otherwise, will return raw probability.
Returns
np.ndarray: The (calibrated) predicted probabilities
predict(X, calibration: bool=True)
Model predictions, calling the child class’s ‘_predict’ method.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.
Returns
np.ndarray: The (calibrated) final prediction
decision_function(X, calibration: bool=True)
Computes the decision function for the given input data.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.
Returns
logit_prediction : array, shape (n_samples,) or (n_samples, n_classes)
Array of (calibrated) logit predictions.
name()
version()
save(file_name: str)
Save the model into file system.
Parameters
file_name: str
The path and name of the file.
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
extract_model_info(X, feature_names, feature_types)
Extract the tree information as functional ANOVA format.
Parameters
X : array-like
Input features.
feature_names: list of str
The feature names.
feature_types: list of str
The feature types.
interpret(dataset)
Interpret the ensemble tree model with given dataset using functional ANOVA framework.
Parameters
dataset : DataSet instance
The dataset for interpreting the model.
Returns
An instance of InterpretFANOVA
MoGradientBoostingClassifier
A lightweight wrapper of sklearn.ensemble.GradientBoostingClassifier.
Parameters
name : str, 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.
__init__(name: str=None, *args, **kwargs)
get_params(deep=True)
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
params : dict
Parameter names mapped to their values.
set_params(**params)
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as ~sklearn.pipeline.Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Parameters
**params : dict
Estimator parameters.
Returns
self : estimator instance
fit(X, y, sample_weight=None, **kwargs)
Fits the estimator to the provided data.
Parameters
X : array-like, shape (n_samples, n_features)
Training data.
y : array-like, shape (n_samples,) or (n_samples, n_outputs)
Target values.
sample_weight : array-like, shape (n_samples,), default=None
Sample weights.
Returns
self : object
Fitted model instance.
reset_calibrate_interval()
reset_calibrate_proba()
calibrate_interval(X, y, alpha=0.1)
Fit a conformal prediction model to the given data.
This method computes the model’s prediction interval calibrated to the given data.
It computes the calibration quantile based on predicted probabilities for the positive class.
Parameters
X : X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : array-like of shape (n_samples, )
Target values.
alpha : float, default=0.1
Expected miscoverage for the conformal prediction.
Raises
ValueError: If the model is neither a regressor nor a classifier.
predict_interval(X)
Predict the prediction set for the given data based on the conformal prediction model.
This method computes the model prediction interval (regression) or prediction sets (classification) using conformal prediction.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
Returns
np.ndarray: 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.
calibrate_proba(X, y, sample_weight=None, method='sigmoid')
Fit the calibration method on the model’s predictions.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : np.ndarray of shape (n_samples, )
Ground truth labels.
sample_weight : array-like, shape (n_samples,), default=None
Sample weights.
method : {‘sigmoid’, ‘isotonic’}, default=‘sigmoid’
The calibration method.
- ‘sigmoid’: Platt’s method, i.e., fit a logistic regression on predicted probabilities and y
- ‘isotonic’: Fit an isotonic regression on predicted probabilities and y.
Returns
self: Calibrated estimator
predict_proba(X, calibration: bool=True)
Predict (calibrated) probabilities for X.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will return calibrated probability if calibration is done. Otherwise, will return raw probability.
Returns
np.ndarray: The (calibrated) predicted probabilities
predict(X, calibration: bool=True)
Model predictions, calling the child class’s ‘_predict’ method.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.
Returns
np.ndarray: The (calibrated) final prediction
decision_function(X, calibration: bool=True)
Computes the decision function for the given input data.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.
Returns
logit_prediction : array, shape (n_samples,) or (n_samples, n_classes)
Array of (calibrated) logit predictions.
name()
version()
save(file_name: str)
Save the model into file system.
Parameters
file_name: str
The path and name of the file.
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
extract_model_info(X, feature_names, feature_types)
Extract the tree information as functional ANOVA format.
Parameters
X : array-like
Input features.
feature_names: list of str
The feature names.
feature_types: list of str
The feature types.
interpret(dataset)
Interpret the ensemble tree model with given dataset using functional ANOVA framework.
Parameters
dataset : DataSet instance
The dataset for interpreting the model.
Returns
An instance of InterpretFANOVA
MoXGBClassifier
A lightweight wrapper of xgboost.XGBClassifier.
Parameters
name : str, 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.
__init__(name: str=None, *args, **kwargs)
get_params(deep=True)
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
params : dict
Parameter names mapped to their values.
set_params(**params)
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as ~sklearn.pipeline.Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Parameters
**params : dict
Estimator parameters.
Returns
self : estimator instance
fit(X, y, sample_weight=None, **kwargs)
Fits the estimator to the provided data.
Parameters
X : array-like, shape (n_samples, n_features)
Training data.
y : array-like, shape (n_samples,) or (n_samples, n_outputs)
Target values.
sample_weight : array-like, shape (n_samples,), default=None
Sample weights.
Returns
self : object
Fitted model instance.
reset_calibrate_interval()
reset_calibrate_proba()
calibrate_interval(X, y, alpha=0.1)
Fit a conformal prediction model to the given data.
This method computes the model’s prediction interval calibrated to the given data.
It computes the calibration quantile based on predicted probabilities for the positive class.
Parameters
X : X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : array-like of shape (n_samples, )
Target values.
alpha : float, default=0.1
Expected miscoverage for the conformal prediction.
Raises
ValueError: If the model is neither a regressor nor a classifier.
predict_interval(X)
Predict the prediction set for the given data based on the conformal prediction model.
This method computes the model prediction interval (regression) or prediction sets (classification) using conformal prediction.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
Returns
np.ndarray: 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.
calibrate_proba(X, y, sample_weight=None, method='sigmoid')
Fit the calibration method on the model’s predictions.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : np.ndarray of shape (n_samples, )
Ground truth labels.
sample_weight : array-like, shape (n_samples,), default=None
Sample weights.
method : {‘sigmoid’, ‘isotonic’}, default=‘sigmoid’
The calibration method.
- ‘sigmoid’: Platt’s method, i.e., fit a logistic regression on predicted probabilities and y
- ‘isotonic’: Fit an isotonic regression on predicted probabilities and y.
Returns
self: Calibrated estimator
predict_proba(X, calibration: bool=True)
Predict (calibrated) probabilities for X.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will return calibrated probability if calibration is done. Otherwise, will return raw probability.
Returns
np.ndarray: The (calibrated) predicted probabilities
predict(X, calibration: bool=True)
Model predictions, calling the child class’s ‘_predict’ method.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.
Returns
np.ndarray: The (calibrated) final prediction
decision_function(X, calibration: bool=True)
Computes the decision function for the given input data.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.
Returns
logit_prediction : array, shape (n_samples,) or (n_samples, n_classes)
Array of (calibrated) logit predictions.
name()
version()
save(file_name: str)
Save the model into file system.
Parameters
file_name: str
The path and name of the file.
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
extract_model_info(X, feature_names, feature_types)
Extract the tree information as functional ANOVA format.
Parameters
X : array-like
Input features.
feature_names: list of str
The feature names.
feature_types: list of str
The feature types.
interpret(dataset)
Interpret the ensemble tree model with given dataset using functional ANOVA framework.
Parameters
dataset : DataSet instance
The dataset for interpreting the model.
Returns
An instance of InterpretFANOVA
MoLGBMClassifier
A lightweight wrapper of lightgbm.LGBMClassifier.
Parameters
name : str, 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.
__init__(name: str=None, *args, **kwargs)
get_params(deep=True)
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
params : dict
Parameter names mapped to their values.
set_params(**params)
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as ~sklearn.pipeline.Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Parameters
**params : dict
Estimator parameters.
Returns
self : estimator instance
fit(X, y, sample_weight=None, **kwargs)
Fits the estimator to the provided data.
Parameters
X : array-like, shape (n_samples, n_features)
Training data.
y : array-like, shape (n_samples,) or (n_samples, n_outputs)
Target values.
sample_weight : array-like, shape (n_samples,), default=None
Sample weights.
Returns
self : object
Fitted model instance.
reset_calibrate_interval()
reset_calibrate_proba()
calibrate_interval(X, y, alpha=0.1)
Fit a conformal prediction model to the given data.
This method computes the model’s prediction interval calibrated to the given data.
It computes the calibration quantile based on predicted probabilities for the positive class.
Parameters
X : X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : array-like of shape (n_samples, )
Target values.
alpha : float, default=0.1
Expected miscoverage for the conformal prediction.
Raises
ValueError: If the model is neither a regressor nor a classifier.
predict_interval(X)
Predict the prediction set for the given data based on the conformal prediction model.
This method computes the model prediction interval (regression) or prediction sets (classification) using conformal prediction.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
Returns
np.ndarray: 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.
calibrate_proba(X, y, sample_weight=None, method='sigmoid')
Fit the calibration method on the model’s predictions.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : np.ndarray of shape (n_samples, )
Ground truth labels.
sample_weight : array-like, shape (n_samples,), default=None
Sample weights.
method : {‘sigmoid’, ‘isotonic’}, default=‘sigmoid’
The calibration method.
- ‘sigmoid’: Platt’s method, i.e., fit a logistic regression on predicted probabilities and y
- ‘isotonic’: Fit an isotonic regression on predicted probabilities and y.
Returns
self: Calibrated estimator
predict_proba(X, calibration: bool=True)
Predict (calibrated) probabilities for X.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will return calibrated probability if calibration is done. Otherwise, will return raw probability.
Returns
np.ndarray: The (calibrated) predicted probabilities
predict(X, calibration: bool=True)
Model predictions, calling the child class’s ‘_predict’ method.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.
Returns
np.ndarray: The (calibrated) final prediction
decision_function(X, calibration: bool=True)
Computes the decision function for the given input data.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.
Returns
logit_prediction : array, shape (n_samples,) or (n_samples, n_classes)
Array of (calibrated) logit predictions.
name()
version()
save(file_name: str)
Save the model into file system.
Parameters
file_name: str
The path and name of the file.
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
extract_model_info(X, feature_names, feature_types)
Extract the tree information as functional ANOVA format.
Parameters
X : array-like
Input features.
feature_names: list of str
The feature names.
feature_types: list of str
The feature types.
interpret(dataset)
Interpret the ensemble tree model with given dataset using functional ANOVA framework.
Parameters
dataset : DataSet instance
The dataset for interpreting the model.
Returns
An instance of InterpretFANOVA
MoCatBoostClassifier
A lightweight wrapper of catboost.CatBoostClassifier.
Parameters
name : str, 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.
__init__(name: str=None, *args, **kwargs)
get_params(deep=True)
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
params : dict
Parameter names mapped to their values.
set_params(**params)
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as ~sklearn.pipeline.Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Parameters
**params : dict
Estimator parameters.
Returns
self : estimator instance
fit(X, y, sample_weight=None, **kwargs)
Fits the estimator to the provided data.
Parameters
X : array-like, shape (n_samples, n_features)
Training data.
y : array-like, shape (n_samples,) or (n_samples, n_outputs)
Target values.
sample_weight : array-like, shape (n_samples,), default=None
Sample weights.
Returns
self : object
Fitted model instance.
reset_calibrate_interval()
reset_calibrate_proba()
calibrate_interval(X, y, alpha=0.1)
Fit a conformal prediction model to the given data.
This method computes the model’s prediction interval calibrated to the given data.
It computes the calibration quantile based on predicted probabilities for the positive class.
Parameters
X : X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : array-like of shape (n_samples, )
Target values.
alpha : float, default=0.1
Expected miscoverage for the conformal prediction.
Raises
ValueError: If the model is neither a regressor nor a classifier.
predict_interval(X)
Predict the prediction set for the given data based on the conformal prediction model.
This method computes the model prediction interval (regression) or prediction sets (classification) using conformal prediction.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
Returns
np.ndarray: 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.
calibrate_proba(X, y, sample_weight=None, method='sigmoid')
Fit the calibration method on the model’s predictions.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : np.ndarray of shape (n_samples, )
Ground truth labels.
sample_weight : array-like, shape (n_samples,), default=None
Sample weights.
method : {‘sigmoid’, ‘isotonic’}, default=‘sigmoid’
The calibration method.
- ‘sigmoid’: Platt’s method, i.e., fit a logistic regression on predicted probabilities and y
- ‘isotonic’: Fit an isotonic regression on predicted probabilities and y.
Returns
self: Calibrated estimator
predict_proba(X, calibration: bool=True)
Predict (calibrated) probabilities for X.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will return calibrated probability if calibration is done. Otherwise, will return raw probability.
Returns
np.ndarray: The (calibrated) predicted probabilities
predict(X, calibration: bool=True)
Model predictions, calling the child class’s ‘_predict’ method.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.
Returns
np.ndarray: The (calibrated) final prediction
decision_function(X, calibration: bool=True)
Computes the decision function for the given input data.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.
Returns
logit_prediction : array, shape (n_samples,) or (n_samples, n_classes)
Array of (calibrated) logit predictions.
name()
version()
save(file_name: str)
Save the model into file system.
Parameters
file_name: str
The path and name of the file.
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
extract_model_info(X, feature_names, feature_types)
Extract the tree information as functional ANOVA format.
Parameters
X : array-like
Input features.
feature_names: list of str
The feature names.
feature_types: list of str
The feature types.
interpret(dataset)
Interpret the ensemble tree model with given dataset using functional ANOVA framework.
Parameters
dataset : DataSet instance
The dataset for interpreting the model.
Returns
An instance of InterpretFANOVA
MoGLMTreeClassifier
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
name : str, default=None
Identifier name for the model instance.
max_depth : int, default=3
Maximum depth of the tree. Controls model complexity.
min_samples_leaf : int, default=50
Minimum number of samples required in a leaf node.
min_impurity_decrease : float, default=0
Minimum required decrease in impurity to split a node.
split_custom : dict, default=None
Dictionary mapping feature indices to custom split points.
n_screen_grid : int, default=1
Number of grid points used in initial feature screening.
n_feature_search : int, default=10
Number of top features to consider after screening.
n_split_grid : int, default=20
Number of grid points to evaluate for splitting.
reg_lambda : float, default=0.1
L1 regularization strength for leaf models.
clip_predict : bool, default=False
Whether to clip predictions to training data range.
random_state : int, 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.
__init__(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)
fit(X, y, sample_weight=None)
decision_rule(node_id)
decision_path_indice(x, node_id)
decision_path(x)
get_raw_output(x)
output
Parameters ---------x : array-like of shape (n_samples, n_features) containing the input dataset Returns -------np.ndarray of shape (n_samples,),
extract_model_info(X, feature_names, feature_types)
interpret(dataset)
reset_calibrate_interval()
reset_calibrate_proba()
calibrate_interval(X, y, alpha=0.1)
Fit a conformal prediction model to the given data.
This method computes the model’s prediction interval calibrated to the given data.
It computes the calibration quantile based on predicted probabilities for the positive class.
Parameters
X : X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : array-like of shape (n_samples, )
Target values.
alpha : float, default=0.1
Expected miscoverage for the conformal prediction.
Raises
ValueError: If the model is neither a regressor nor a classifier.
predict_interval(X)
Predict the prediction set for the given data based on the conformal prediction model.
This method computes the model prediction interval (regression) or prediction sets (classification) using conformal prediction.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
Returns
np.ndarray: 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.
calibrate_proba(X, y, sample_weight=None, method='sigmoid')
Fit the calibration method on the model’s predictions.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : np.ndarray of shape (n_samples, )
Ground truth labels.
sample_weight : array-like, shape (n_samples,), default=None
Sample weights.
method : {‘sigmoid’, ‘isotonic’}, default=‘sigmoid’
The calibration method.
- ‘sigmoid’: Platt’s method, i.e., fit a logistic regression on predicted probabilities and y
- ‘isotonic’: Fit an isotonic regression on predicted probabilities and y.
Returns
self: Calibrated estimator
predict_proba(X, calibration: bool=True)
Predict (calibrated) probabilities for X.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will return calibrated probability if calibration is done. Otherwise, will return raw probability.
Returns
np.ndarray: The (calibrated) predicted probabilities
predict(X, calibration: bool=True)
Model predictions, calling the child class’s ‘_predict’ method.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.
Returns
np.ndarray: The (calibrated) final prediction
decision_function(X, calibration: bool=True)
Computes the decision function for the given input data.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.
Returns
logit_prediction : array, shape (n_samples,) or (n_samples, n_classes)
Array of (calibrated) logit predictions.
name()
version()
save(file_name: str)
Save the model into file system.
Parameters
file_name: str
The path and name of the file.
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
MoGLMTreeBoostClassifier
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
name : str, default=None
Model identifier name for reference.
n_estimators : int, default=100
Number of boosting rounds (trees) to fit.
max_depth : int, default=1
Maximum tree depth. Model is most interpretable when depth=1.
learning_rate : float, default=1.0
Shrinkage rate applied to each tree’s contribution.
n_epoch_no_change : int, default=5
Early stopping rounds - training stops if validation loss doesn’t improve.
min_samples_leaf : int, default=50
Minimum samples required in a leaf node.
min_impurity_decrease : float, default=0
Minimum required decrease in impurity to split a node.
split_custom : dict, default=None
Custom split points specified per feature.
n_screen_grid : int, default=1
Grid size for initial split point screening.
n_feature_search : int, default=5
Number of features to consider after screening.
n_split_grid : int, default=20
Grid size for fine-grained split point search.
reg_lambda : float, default=0.1
L1 regularization strength parameter.
clip_predict : bool, default=False
Whether to clip predictions to training data range.
simplified : bool, default=True
Use simplified partial linear regression for splits.
val_ratio : float, default=0.2
Proportion of data used for validation.
verbose : bool, default=False
Whether to print training progress.
random_state : int, default=0
Random seed for reproducibility.
Attributes
estimators : list
Fitted GLMTree models.
n_features_in : int
Number of input features.
__init__(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)
fit(X, y, sample_weight=None)
fit the GLMTree Boosting model
Parameters ---------X : array-like of shape (n_samples, n_features) containing the input dataset y : array-like of shape (n_samples,) containing target values sample_weight : array-like of shape (n_samples,) containing the weight of each sample Returns -------object self : Estimator instance.
get_raw_output(x)
output
Parameters ---------x : array-like of shape (n_samples, n_features) containing the input dataset Returns -------np.ndarray of shape (n_samples,),
extract_model_info(X, feature_names, feature_types)
interpret(dataset)
reset_calibrate_interval()
reset_calibrate_proba()
calibrate_interval(X, y, alpha=0.1)
Fit a conformal prediction model to the given data.
This method computes the model’s prediction interval calibrated to the given data.
It computes the calibration quantile based on predicted probabilities for the positive class.
Parameters
X : X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : array-like of shape (n_samples, )
Target values.
alpha : float, default=0.1
Expected miscoverage for the conformal prediction.
Raises
ValueError: If the model is neither a regressor nor a classifier.
predict_interval(X)
Predict the prediction set for the given data based on the conformal prediction model.
This method computes the model prediction interval (regression) or prediction sets (classification) using conformal prediction.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
Returns
np.ndarray: 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.
calibrate_proba(X, y, sample_weight=None, method='sigmoid')
Fit the calibration method on the model’s predictions.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : np.ndarray of shape (n_samples, )
Ground truth labels.
sample_weight : array-like, shape (n_samples,), default=None
Sample weights.
method : {‘sigmoid’, ‘isotonic’}, default=‘sigmoid’
The calibration method.
- ‘sigmoid’: Platt’s method, i.e., fit a logistic regression on predicted probabilities and y
- ‘isotonic’: Fit an isotonic regression on predicted probabilities and y.
Returns
self: Calibrated estimator
predict_proba(X, calibration: bool=True)
Predict (calibrated) probabilities for X.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will return calibrated probability if calibration is done. Otherwise, will return raw probability.
Returns
np.ndarray: The (calibrated) predicted probabilities
predict(X, calibration: bool=True)
Model predictions, calling the child class’s ‘_predict’ method.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.
Returns
np.ndarray: The (calibrated) final prediction
decision_function(X, calibration: bool=True)
Computes the decision function for the given input data.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.
Returns
logit_prediction : array, shape (n_samples,) or (n_samples, n_classes)
Array of (calibrated) logit predictions.
name()
version()
save(file_name: str)
Save the model into file system.
Parameters
file_name: str
The path and name of the file.
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
MoNeuralTreeClassifier
A neural network-based classification model that combines GLM trees with monotonicity constraints.
This model first fits a depth-1 boosted GLMTree, converts it to an equivalent neural network, and then fine-tunes the network parameters. It supports monotonicity constraints and provides interpretability through feature effects analysis.
Parameters
name : str, default=None
Custom identifier for the model instance.
estimator : MoGLMTreeBoostRegressor, default=None
Pre-fitted or unfitted GLMTree regressor for initialization. If None, creates a new instance.
feature_names : list of str, default=None
Names of input features for interpretability.
val_ratio : float, default=0.2
Proportion of data used for validation during training (0 to 1).
device : str, default=None
Computing device for training (‘cpu’, ‘cuda’, etc.).
verbose : bool, default=False
If True, prints training progress and statistics.
random_state : int, default=0
Seed for reproducible random operations.
nn_temperature : float, default=0.0001
Smoothing parameter for neural network activation.
nn_lr : float, default=0.001
Learning rate for neural network optimization.
nn_max_epochs : int, default=200
Maximum number of training epochs.
nn_batch_size : int, default=200
Number of samples per training batch.
nn_n_epoch_no_change : int, default=10
Early stopping patience - number of epochs without improvement.
reg_mono : float, default=0.1
Strength of monotonicity regularization.
mono_sample_size : int, default=1000
Number of random samples for monotonicity regularization.
mono_increasing_list : tuple of str, default=()
Features that should have monotonically increasing relationships.
mono_decreasing_list : tuple of str, default=()
Features that should have monotonically decreasing relationships.
**kwargs
Additional parameters passed to MoGLMTreeBoostRegressor.
Attributes
net : object
The internal Pytorch network object.
__init__(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)
set_params(**params)
get_params(deep=True)
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 -------params : mapping of string to any Parameter names mapped to their values.
get_mono_loss(x, sample_weight=None)
Returns monotonicity loss of given samples.
Parameters
x : np.ndarray of shape (n_samples, n_features)
Data features.
sample_weight : np.ndarray of shape (n_samples, ), default=None
Sample weight.
Returns
mono_loss : float
monotonicity loss.
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_samples : int, default=10000
Number of random samples to use for verification.
Returns
mono_status : bool
True if monotonicity constraints are satisfied, False otherwise.
fit(X, y, sample_weight=None)
get_aggregate_output(X)
Returns numpy array of raw prediction.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Data features.
Returns
pred : np.ndarray of shape (n_samples, 1)
numpy array of raw prediction.
get_sparsity(x)
extract_model_info(X, feature_names, feature_types)
interpret(dataset)
reset_calibrate_interval()
reset_calibrate_proba()
calibrate_interval(X, y, alpha=0.1)
Fit a conformal prediction model to the given data.
This method computes the model’s prediction interval calibrated to the given data.
It computes the calibration quantile based on predicted probabilities for the positive class.
Parameters
X : X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : array-like of shape (n_samples, )
Target values.
alpha : float, default=0.1
Expected miscoverage for the conformal prediction.
Raises
ValueError: If the model is neither a regressor nor a classifier.
predict_interval(X)
Predict the prediction set for the given data based on the conformal prediction model.
This method computes the model prediction interval (regression) or prediction sets (classification) using conformal prediction.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
Returns
np.ndarray: 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.
calibrate_proba(X, y, sample_weight=None, method='sigmoid')
Fit the calibration method on the model’s predictions.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : np.ndarray of shape (n_samples, )
Ground truth labels.
sample_weight : array-like, shape (n_samples,), default=None
Sample weights.
method : {‘sigmoid’, ‘isotonic’}, default=‘sigmoid’
The calibration method.
- ‘sigmoid’: Platt’s method, i.e., fit a logistic regression on predicted probabilities and y
- ‘isotonic’: Fit an isotonic regression on predicted probabilities and y.
Returns
self: Calibrated estimator
predict_proba(X, calibration: bool=True)
Predict (calibrated) probabilities for X.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will return calibrated probability if calibration is done. Otherwise, will return raw probability.
Returns
np.ndarray: The (calibrated) predicted probabilities
predict(X, calibration: bool=True)
Model predictions, calling the child class’s ‘_predict’ method.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.
Returns
np.ndarray: The (calibrated) final prediction
decision_function(X, calibration: bool=True)
Computes the decision function for the given input data.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.
Returns
logit_prediction : array, shape (n_samples,) or (n_samples, n_classes)
Array of (calibrated) logit predictions.
name()
version()
save(file_name: str)
Save the model into file system.
Parameters
file_name: str
The path and name of the file.
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
MoGAMINetClassifier
Generalized additive model with pairwise interaction classifier.
Parameters
name : str, default=None
The name of the model.
feature_names : list or None, default=None
The list of feature names. If None, will use “X0”, “X1”, “X2”, etc.
feature_types : list or None, default=None
The list of feature types. Available types include “numerical” and “categorical”. If None, will use numerical for all features.
interact_num : int, default=10
The max number of interactions to be included in the second stage training.
subnet_size_main_effect : tuple of int, default=(20, )
The hidden layer architecture of each subnetwork in the main effect block.
subnet_size_interaction : tuple 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_epochs : tuple 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_rates : tuple 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_thres : tuple 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_size : int, default=1000
The batch size. Note that it should not be larger than the training size * (1 - validation ratio).
batch_size_inference : int, 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_epoch : int, 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_ratio : float, default=0.2
The validation ratio, should be greater than 0 and smaller than 1.
warm_start : bool, 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_size : int, default=5000
The sub-sample size for GAM fitting as warm_start=True.
mlp_sample_size : int, default=1000
The generated sample size for individual subnetwork fitting as warm_start=True.
heredity : bool, default=True
Whether to perform interaction screening subject to heredity constraint.
loss_threshold : float, 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_clarity : float, default=0.1
The regularization strength of marginal clarity constraint.
reg_mono : float, default=0.1
The regularization strength of monotonicity constraint.
mono_sample_size : int, 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_list : tuple of str, default=()
The feature name tuple subject to monotonic increasing constraint.
mono_decreasing_list : tuple of str, default=()
The feature name tuple subject to monotonic decreasing constraint.
include_interaction_list : tuple of (str, str), default=()
The tuple of interaction to be included for fitting, each interaction is expressed by (feature_name1, feature_name2).
boundary_clip : bool, default=True
In the inference stage, whether to clip the feature values by their min and max values in the training data.
normalize : bool, default=True
Whether to normalize the data before inputting to the network.
verbose : bool, default=False
Whether to output the training logs.
n_jobs : int, default=10
The number of cpu cores for parallel computing. -1 means all the available cpus will be used.
device : string, default=None
The hardware device name used for training.
random_state : int, 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.
__init__(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)
fit(X, y, sample_weight=None)
Fit GAMINetClassifier model.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Data features.
y : np.ndarray of shape (n_samples, )
Target response.
sample_weight : np.ndarray of shape (n_samples, )
Sample weight.
Returns
self : object
Fitted Estimator.
get_clarity_loss(x, sample_weight=None)
Returns clarity loss of given samples.
Parameters
x : np.ndarray of shape (n_samples, n_features)
Data features
sample_weight : np.ndarray of shape (n_samples, )
Sample weight.
Returns
clarity_loss : float
clarity loss.
get_mono_loss(x, sample_weight=None)
Returns monotonicity loss of given samples.
Parameters
x : np.ndarray of shape (n_samples, n_features)
Data features.
sample_weight : np.ndarray of shape (n_samples, ), default=None
Sample weight.
Returns
mono_loss : float
monotonicity loss.
certify_mono(n_samples=10000)
Certify whether monotonicity constraint is satisfied.
Parameters
n_samples : int, default=10000
Size of random samples for certifying the monotonicity constraint.
Returns
mono_status : bool
True means monotonicity constraint is satisfied.
get_raw_output(x, main_effect=True, interaction=True)
Returns numpy array of raw prediction.
Parameters
x : np.ndarray of shape (n_samples, n_features)
Data features.
main_effect : bool, default=True
Whether to include main effects.
interaction : bool, default=True
Whether to include interactions.
Returns
pred : np.ndarray of shape (n_samples, 1)
numpy array of raw prediction.
predict_main_effect(x)
Returns numpy array of main effects’ raw prediction.
Parameters
x : np.ndarray of shape (n_samples, n_features)
Data features.
Returns
pred : np.ndarray of shape (n_samples, n_features)
numpy array of main effects’ raw prediction.
predict_interaction(x)
Returns numpy array of interactions’ raw prediction.
Parameters
x : np.ndarray of shape (n_samples, n_features)
Data features.
Returns
pred : np.ndarray of shape (n_samples, n_interactions)
numpy array of interactions’ raw 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.
extract_model_info(feature_names)
interpret(dataset)
reset_calibrate_interval()
reset_calibrate_proba()
calibrate_interval(X, y, alpha=0.1)
Fit a conformal prediction model to the given data.
This method computes the model’s prediction interval calibrated to the given data.
It computes the calibration quantile based on predicted probabilities for the positive class.
Parameters
X : X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : array-like of shape (n_samples, )
Target values.
alpha : float, default=0.1
Expected miscoverage for the conformal prediction.
Raises
ValueError: If the model is neither a regressor nor a classifier.
predict_interval(X)
Predict the prediction set for the given data based on the conformal prediction model.
This method computes the model prediction interval (regression) or prediction sets (classification) using conformal prediction.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
Returns
np.ndarray: 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.
calibrate_proba(X, y, sample_weight=None, method='sigmoid')
Fit the calibration method on the model’s predictions.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : np.ndarray of shape (n_samples, )
Ground truth labels.
sample_weight : array-like, shape (n_samples,), default=None
Sample weights.
method : {‘sigmoid’, ‘isotonic’}, default=‘sigmoid’
The calibration method.
- ‘sigmoid’: Platt’s method, i.e., fit a logistic regression on predicted probabilities and y
- ‘isotonic’: Fit an isotonic regression on predicted probabilities and y.
Returns
self: Calibrated estimator
predict_proba(X, calibration: bool=True)
Predict (calibrated) probabilities for X.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will return calibrated probability if calibration is done. Otherwise, will return raw probability.
Returns
np.ndarray: The (calibrated) predicted probabilities
predict(X, calibration: bool=True)
Model predictions, calling the child class’s ‘_predict’ method.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.
Returns
np.ndarray: The (calibrated) final prediction
decision_function(X, calibration: bool=True)
Computes the decision function for the given input data.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.
Returns
logit_prediction : array, shape (n_samples,) or (n_samples, n_classes)
Array of (calibrated) logit predictions.
name()
version()
save(file_name: str)
Save the model into file system.
Parameters
file_name: str
The path and name of the file.
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
MoReLUDNNClassifier
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
name : str, default=None
Optional identifier for the model instance.
hidden_layer_sizes : tuple 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_epochs : int, default=1000
Maximum number of complete passes through the training dataset.
learning_rate : float, default=0.001
Step size used for gradient updates during optimization.
batch_size : int, default=500
Number of training samples used in each gradient update.
l1_reg : float, default=1e-5
Strength of L1 regularization applied to model weights.
val_ratio : float, default=0.2
Proportion of training data to use for validation in early stopping.
n_epoch_no_change : int, default=20
Number of epochs with no improvement after which training will be stopped.
device : string, default=None
Computing device to use for training (‘cpu’, ‘cuda’, etc.).
n_jobs : int, default=10
Number of parallel processes for computation (-1 for using all available cores).
verbose : bool, default=False
If True, prints training progress and statistics.
random_state : int, 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.
__init__(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)
get_weights()
get_biases()
fit(X, y, sample_weight=None)
Fit ReLuDNN model.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Data features.
y : np.ndarray of shape (n_samples, )
Target response.
sample_weight : np.ndarray of shape (n_samples, ), default=None
Sample weight.
Returns
self : object
Fitted Estimator.
get_raw_output(X, last_hidden_layer=False)
Returns numpy array of raw predicted value before softmax.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Data features.
last_hidden_layer : boolean, default=False
Whether to output last hidden layer results.
Returns
pred : np.ndarray of shape (n_samples, )
The raw predicted value.
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
X : np.ndarray of shape (n_samples, n_features)
Input samples for which to generate predictions.
Returns
pred : np.ndarray of shape (n_samples, n_last_hidden_layer_units)
Last hidden layer outputs for each input sample.
interpret(dataset)
reset_calibrate_interval()
reset_calibrate_proba()
calibrate_interval(X, y, alpha=0.1)
Fit a conformal prediction model to the given data.
This method computes the model’s prediction interval calibrated to the given data.
It computes the calibration quantile based on predicted probabilities for the positive class.
Parameters
X : X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : array-like of shape (n_samples, )
Target values.
alpha : float, default=0.1
Expected miscoverage for the conformal prediction.
Raises
ValueError: If the model is neither a regressor nor a classifier.
predict_interval(X)
Predict the prediction set for the given data based on the conformal prediction model.
This method computes the model prediction interval (regression) or prediction sets (classification) using conformal prediction.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
Returns
np.ndarray: 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.
calibrate_proba(X, y, sample_weight=None, method='sigmoid')
Fit the calibration method on the model’s predictions.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : np.ndarray of shape (n_samples, )
Ground truth labels.
sample_weight : array-like, shape (n_samples,), default=None
Sample weights.
method : {‘sigmoid’, ‘isotonic’}, default=‘sigmoid’
The calibration method.
- ‘sigmoid’: Platt’s method, i.e., fit a logistic regression on predicted probabilities and y
- ‘isotonic’: Fit an isotonic regression on predicted probabilities and y.
Returns
self: Calibrated estimator
predict_proba(X, calibration: bool=True)
Predict (calibrated) probabilities for X.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will return calibrated probability if calibration is done. Otherwise, will return raw probability.
Returns
np.ndarray: The (calibrated) predicted probabilities
predict(X, calibration: bool=True)
Model predictions, calling the child class’s ‘_predict’ method.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.
Returns
np.ndarray: The (calibrated) final prediction
decision_function(X, calibration: bool=True)
Computes the decision function for the given input data.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.
Returns
logit_prediction : array, shape (n_samples,) or (n_samples, n_classes)
Array of (calibrated) logit predictions.
name()
version()
save(file_name: str)
Save the model into file system.
Parameters
file_name: str
The path and name of the file.
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
MoMoEClassifier
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
name : str, default=None
Identifier for the model instance.
n_clusters : int, 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.
centroids : np.ndarray, default=None
Pre-defined cluster centers of shape (n_clusters, n_features). If provided, skips the clustering step and uses these centers directly.
calibration : bool, default=True
Whether to calibrate the gating network’s probability estimates using cross-validation.
cv : int, 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_names : list or None, default=None
The list of feature names. If None, will use “X0”, “X1”, “X2”, etc.
cluster_features : list or None, default=None
The list of feature names used for clustering. If None, will use all features.
gating_features : list or None, default=None
The list of feature names used for gating model fitting. If None, will use all features.
ltc_baseline_n_estimators : int, default=300
The number of estimators used for fitting the baseline Xgboost, used when cluster_method=“ltc” only.
ltc_baseline_max_depth : int, default=2
The max depth used for fitting the baseline Xgboost, used when cluster_method=“ltc” only.
ltc_n_estimators : int, default=300
The number of estimators used for fitting the gradient boosting models in trajectory analysis, used when cluster_method=“ltc” only.
ltc_max_depth : int, 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.
__init__(name: str=None, n_clusters: int=10, cluster_method: str='kmeans', centroids: np.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)
set_params(**params)
get_params(deep=True)
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
params : mapping of string to any
Parameter names mapped to their values.
fit_cluster(cluster_id, cluster_labels, X, y, sample_weight, **kwargs)
Fit a model for a single cluster. This function is designed for parallelization.
fit(X, y, sample_weight=None, **kwargs)
get_raw_output(X)
Return the raw prediction outputs.
get_pr_weight(X)
Return the weight of each expert.
interpret(dataset)
reset_calibrate_interval()
reset_calibrate_proba()
calibrate_interval(X, y, alpha=0.1)
Fit a conformal prediction model to the given data.
This method computes the model’s prediction interval calibrated to the given data.
It computes the calibration quantile based on predicted probabilities for the positive class.
Parameters
X : X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : array-like of shape (n_samples, )
Target values.
alpha : float, default=0.1
Expected miscoverage for the conformal prediction.
Raises
ValueError: If the model is neither a regressor nor a classifier.
predict_interval(X)
Predict the prediction set for the given data based on the conformal prediction model.
This method computes the model prediction interval (regression) or prediction sets (classification) using conformal prediction.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
Returns
np.ndarray: 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.
calibrate_proba(X, y, sample_weight=None, method='sigmoid')
Fit the calibration method on the model’s predictions.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : np.ndarray of shape (n_samples, )
Ground truth labels.
sample_weight : array-like, shape (n_samples,), default=None
Sample weights.
method : {‘sigmoid’, ‘isotonic’}, default=‘sigmoid’
The calibration method.
- ‘sigmoid’: Platt’s method, i.e., fit a logistic regression on predicted probabilities and y
- ‘isotonic’: Fit an isotonic regression on predicted probabilities and y.
Returns
self: Calibrated estimator
predict_proba(X, calibration: bool=True)
Predict (calibrated) probabilities for X.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will return calibrated probability if calibration is done. Otherwise, will return raw probability.
Returns
np.ndarray: The (calibrated) predicted probabilities
predict(X, calibration: bool=True)
Model predictions, calling the child class’s ‘_predict’ method.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.
Returns
np.ndarray: The (calibrated) final prediction
decision_function(X, calibration: bool=True)
Computes the decision function for the given input data.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.
Returns
logit_prediction : array, shape (n_samples,) or (n_samples, n_classes)
Array of (calibrated) logit predictions.
name()
version()
save(file_name: str)
Save the model into file system.
Parameters
file_name: str
The path and name of the file.
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
ModelBaseClassifier
Base Class for Modeva Classifiers.
reset_calibrate_interval()
reset_calibrate_proba()
calibrate_interval(X, y, alpha=0.1)
Fit a conformal prediction model to the given data.
This method computes the model’s prediction interval calibrated to the given data.
It computes the calibration quantile based on predicted probabilities for the positive class.
Parameters
X : X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : array-like of shape (n_samples, )
Target values.
alpha : float, default=0.1
Expected miscoverage for the conformal prediction.
Raises
ValueError: If the model is neither a regressor nor a classifier.
predict_interval(X)
Predict the prediction set for the given data based on the conformal prediction model.
This method computes the model prediction interval (regression) or prediction sets (classification) using conformal prediction.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
Returns
np.ndarray: 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.
calibrate_proba(X, y, sample_weight=None, method='sigmoid')
Fit the calibration method on the model’s predictions.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
y : np.ndarray of shape (n_samples, )
Ground truth labels.
sample_weight : array-like, shape (n_samples,), default=None
Sample weights.
method : {‘sigmoid’, ‘isotonic’}, default=‘sigmoid’
The calibration method.
- ‘sigmoid’: Platt’s method, i.e., fit a logistic regression on predicted probabilities and y
- ‘isotonic’: Fit an isotonic regression on predicted probabilities and y.
Returns
self: Calibrated estimator
predict_proba(X, calibration: bool=True)
Predict (calibrated) probabilities for X.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will return calibrated probability if calibration is done. Otherwise, will return raw probability.
Returns
np.ndarray: The (calibrated) predicted probabilities
predict(X, calibration: bool=True)
Model predictions, calling the child class’s ‘_predict’ method.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.
Returns
np.ndarray: The (calibrated) final prediction
decision_function(X, calibration: bool=True)
Computes the decision function for the given input data.
Parameters
X : np.ndarray of shape (n_samples, n_features)
Feature matrix for prediction.
calibration : bool, default=True
If True, will use calibrated probability if calibration is done. Otherwise, will use raw probability.
Returns
logit_prediction : array, shape (n_samples,) or (n_samples, n_classes)
Array of (calibrated) logit predictions.
name()
version()
save(file_name: str)
Save the model into file system.
Parameters
file_name: str
The path and name of the file.
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