RotationForest#
- class RotationForest(n_estimators=200, min_group=3, max_group=3, remove_proportion=0.5, base_estimator=None, time_limit_in_minutes=0.0, contract_max_n_estimators=500, save_transformed_data=False, n_jobs=1, random_state=None)[source]#
A rotation forest (RotF) vector classifier.
Implementation of the Rotation Forest classifier described in Rodriguez et al (2013) [1]. Builds a forest of trees build on random portions of the data transformed using PCA.
Intended as a benchmark for time series data and a base classifier for transformation based approaches such as ShapeletTransformClassifier, this sktime implementation only works with continuous attributes.
- Parameters:
- n_estimatorsint, default=200
Number of estimators to build for the ensemble.
- min_groupint, default=3
The minimum size of an attribute subsample group.
- max_groupint, default=3
The maximum size of an attribute subsample group.
- remove_proportionfloat, default=0.5
The proportion of cases to be removed per group.
- base_estimatorBaseEstimator or None, default=”None”
Base estimator for the ensemble. By default, uses the sklearn
DecisionTreeClassifier
using entropy as a splitting measure.- time_limit_in_minutesint, default=0
Time contract to limit build time in minutes, overriding
n_estimators
. Default of0
meansn_estimators
is used.- contract_max_n_estimatorsint, default=500
Max number of estimators to build when
time_limit_in_minutes
is set.- save_transformed_databool, default=False
Save the data transformed in fit in
transformed_data_
for use in_get_train_probs
.- n_jobsint, default=1
The number of jobs to run in parallel for both
fit
andpredict
.-1
means using all processors.- random_stateint, RandomState instance or None, default=None
If
int
, random_state is the seed used by the random number generator; IfRandomState
instance, random_state is the random number generator; IfNone
, the random number generator is theRandomState
instance used bynp.random
.
- Attributes:
- classes_list
The unique class labels in the training set.
- n_classes_int
The number of unique classes in the training set.
- n_instances_int
The number of train cases in the training set.
- n_atts_int
The number of attributes in the training set.
- transformed_data_list of shape (n_estimators) of ndarray
The transformed training dataset for all classifiers. Only saved when
save_transformed_data
isTrue
.- estimators_list of shape (n_estimators) of BaseEstimator
The collections of estimators trained in fit.
See also
ShapeletTransformClassifier
A shapelet-based classifier using Rotation Forest.
Notes
For the Java version, see tsml.
References
[1]Rodriguez, Juan José, Ludmila I. Kuncheva, and Carlos J. Alonso. “Rotation forest: A new classifier ensemble method.” IEEE transactions on pattern analysis and machine intelligence 28.10 (2006).
[2]Bagnall, A., et al. “Is rotation forest the best classifier for problems with continuous features?.” arXiv preprint arXiv:1809.06705 (2018).
Examples
>>> from sktime.classification.sklearn import RotationForest >>> from sktime.datasets import load_unit_test >>> from sktime.datatypes._panel._convert import from_nested_to_3d_numpy >>> X_train, y_train = load_unit_test(split="train", return_X_y=True) >>> X_test, y_test = load_unit_test(split="test", return_X_y=True) >>> X_train = from_nested_to_3d_numpy(X_train) >>> X_test = from_nested_to_3d_numpy(X_test) >>> clf = RotationForest(n_estimators=10) >>> clf.fit(X_train, y_train) RotationForest(...) >>> y_pred = clf.predict(X_test)
Methods
fit
(X, y)Fit a forest of trees on cases (X,y), where y is the target variable.
Get metadata routing of this object.
get_params
([deep])Get parameters for this estimator.
predict
(X)Predict for all cases in X.
Probability estimates for each class for all cases in X.
score
(X, y[, sample_weight])Return the mean accuracy on the given test data and labels.
set_params
(**params)Set the parameters of this estimator.
set_score_request
(*[, sample_weight])Request metadata passed to the
score
method.- fit(X, y)[source]#
Fit a forest of trees on cases (X,y), where y is the target variable.
- Parameters:
- X2d ndarray or DataFrame of shape = [n_instances, n_attributes]
The training data.
- yarray-like, shape = [n_instances]
The class labels.
- Returns:
- self
Reference to self.
Notes
Changes state by creating a fitted model that updates attributes ending in “_”.
- predict(X)[source]#
Predict for all cases in X. Built on top of predict_proba.
- Parameters:
- X2d ndarray or DataFrame of shape = [n_instances, n_attributes]
The data to make predictions for.
- Returns:
- yarray-like, shape = [n_instances]
Predicted class labels.
- predict_proba(X)[source]#
Probability estimates for each class for all cases in X.
- Parameters:
- X2d ndarray or DataFrame of shape = [n_instances, n_attributes]
The data to make predictions for.
- Returns:
- yarray-like, shape = [n_instances, n_classes_]
Predicted probabilities using the ordering in classes_.
- get_metadata_routing()[source]#
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
- routingMetadataRequest
A
MetadataRequest
encapsulating routing information.
- get_params(deep=True)[source]#
Get parameters for this estimator.
- Parameters:
- deepbool, default=True
If True, will return the parameters for this estimator and contained subobjects that are estimators.
- Returns:
- paramsdict
Parameter names mapped to their values.
- score(X, y, sample_weight=None)[source]#
Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
- Parameters:
- Xarray-like of shape (n_samples, n_features)
Test samples.
- yarray-like of shape (n_samples,) or (n_samples, n_outputs)
True labels for X.
- sample_weightarray-like of shape (n_samples,), default=None
Sample weights.
- Returns:
- scorefloat
Mean accuracy of
self.predict(X)
w.r.t. y.
- set_params(**params)[source]#
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as
Pipeline
). The latter have parameters of the form<component>__<parameter>
so that it’s possible to update each component of a nested object.- Parameters:
- **paramsdict
Estimator parameters.
- Returns:
- selfestimator instance
Estimator instance.
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') RotationForest [source]#
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed toscore
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it toscore
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
- sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
sample_weight
parameter inscore
.
- Returns:
- selfobject
The updated object.