Module connectome.models.ebm
wrapper for the explainable boosting machine with integrated feature selection based on the mutual information
Classes
class EBMmi (features: Union[numpy.ndarray, pandas.core.frame.DataFrame], target: numpy.ndarray, feature_names: list = None, classification: bool = True, fit_directly: bool = True, **kwargs)-
Class that wraps the explainable boosting machine and performs feature selection before fitting the model based on the mutual information scores of the features with the target variable. The integrated feature selection step is necessary as the explainable boosting machine is computationally very costly especially in the case of high number of features.
Examples:
>>> import numpy as np >>> import pandas as pd >>> # create synthetic data >>> X, y = make_classification(n_informative=15) >>> X = pd.DataFrame( >>> X, >>> columns=["feature_" + str(i) >>> for i in range(X.shape[1])]) >>> X_regr, y_regr = make_regression(n_features=20, n_informative=15) >>> X_regr = pd.DataFrame( >>> X_regr, >>> columns=["feature_" + str(i) >>> for i in range(X_regr.shape[1])]) >>> >>> # initialize some models >>> ebm_class = EBMmi(X, y, classification=True) >>> ebm_regr = EBMmi(X_regr, y_regr, classification=False) >>> >>> # check the size >>> print(sys.getsizeof(ebm_class)*1e-6) >>> >>> # plot functions >>> ebm_class.plot_mi(n=5) >>> ebm_regr.plot_mi(n=5)Methods
def explain_global(self)def explain_local(self, inputs: Union[numpy.ndarray, pandas.core.frame.DataFrame], target: numpy.ndarray = None) ‑> Nonedef fit(self, n_features: int = 650, return_model: bool = False)def get_contributions(self, inputs: Union[numpy.ndarray, pandas.core.frame.DataFrame]) ‑> Union[numpy.ndarray, tuple]def get_mutual_info(self) ‑> pandas.core.frame.DataFramedef get_sel_features_names(self) ‑> listdef get_selected_features(self, n: int = 650) ‑> Union[numpy.ndarray, pandas.core.frame.DataFrame]def plot_mi(self, n: int = 30)def predict(self, inputs: pandas.core.frame.DataFrame) ‑> numpy.ndarraydef predict_proba(self, inputs) ‑> numpy.ndarraydef save_model(self, name: str = 'ebm_trained')