RuleTree.base.RuleTreeBase.RuleTreeBase

RuleTree.base.RuleTreeBase.RuleTreeBase#

class RuleTreeBase[source]#

Bases: BaseEstimator, ABC

Base class for RuleTree estimators.

RuleTree estimators may receive one input container for each supported data type: X for tabular data, X_ts for time series, X_img for images, and X_txt for text. The only assumption made by this base class is that the first dimension of every provided container is the number of samples. This is enough to validate that all provided inputs, and y when available, refer to the same set of instances.

Internally, the inputs are handled as a single dictionary {data_type: array} (see RuleTree.utils.define.DATA_INPUT_TYPES), built by _validate_inputs().

Notes

The class follows the scikit-learn estimator API by inheriting from sklearn.base.BaseEstimator. The base implementation only validates inputs; concrete estimators are expected to implement the actual fitting and prediction behavior.

See also

RuleTree.tree.RuleTree.RuleTree

the base class of the trees.

__init__()#

Methods

__init__()

fit([X, y, X_ts, X_img, X_txt])

Validate input data before fitting.

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get parameters for this estimator.

predict([X, X_ts, X_img, X_txt])

Validate input data before prediction.

set_fit_request(*[, X_img, X_ts, X_txt])

Configure whether metadata should be requested to be passed to the fit method.

set_params(**params)

Set the parameters of this estimator.

set_predict_request(*[, X_img, X_ts, X_txt])

Configure whether metadata should be requested to be passed to the predict method.

fit(X=None, y=None, X_ts=None, X_img=None, X_txt=None)[source]#

Validate input data before fitting.

Parameters:
  • X (array-like of shape (n_samples, n_features), default=None) – Tabular input data.

  • X_ts (array-like of shape (n_samples, ...), default=None) – Time-series input data.

  • X_img (array-like of shape (n_samples, ...), default=None) – Image input data.

  • X_txt (array-like of shape (n_samples, ...), default=None) – Text input data.

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

Returns:

self – The validated estimator instance.

Return type:

RuleTreeBase

Raises:

ValueError – If no input container is provided, or if the provided containers and y do not have a consistent number of samples.

predict(X=None, X_ts=None, X_img=None, X_txt=None)[source]#

Validate input data before prediction.

Parameters:
  • X (array-like of shape (n_samples, n_features), default=None) – Tabular input data.

  • X_ts (array-like of shape (n_samples, ...), default=None) – Time-series input data.

  • X_img (array-like of shape (n_samples, ...), default=None) – Image input data.

  • X_txt (array-like of shape (n_samples, ...), default=None) – Text input data.

Raises:

ValueError – If no input container is provided, or if the provided containers do not have a consistent number of samples.

set_fit_request(*, X_img: bool | None | str = '$UNCHANGED$', X_ts: bool | None | str = '$UNCHANGED$', X_txt: bool | None | str = '$UNCHANGED$') → RuleTreeBase#

Configure whether metadata should be requested to be passed to the fit method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

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

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

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

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

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

Added in version 1.3.

Parameters:
  • X_img (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for X_img parameter in fit.

  • X_ts (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for X_ts parameter in fit.

  • X_txt (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for X_txt parameter in fit.

Returns:

self – The updated object.

Return type:

object

set_predict_request(*, X_img: bool | None | str = '$UNCHANGED$', X_ts: bool | None | str = '$UNCHANGED$', X_txt: bool | None | str = '$UNCHANGED$') → RuleTreeBase#

Configure whether metadata should be requested to be passed to the predict method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

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

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

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

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

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

Added in version 1.3.

Parameters:
  • X_img (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for X_img parameter in predict.

  • X_ts (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for X_ts parameter in predict.

  • X_txt (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for X_txt parameter in predict.

Returns:

self – The updated object.

Return type:

object