TimeSeriesForestClassifier¶
- class TimeSeriesForestClassifier(min_interval=3, n_estimators=200, n_jobs=1, random_state=None)[source]¶
Time series forest classifier.
A time series forest is an ensemble of decision trees built on random intervals. Overview: Input n series length m. For each tree
sample sqrt(m) intervals,
find mean, std and slope for each interval, concatenate to form new
data set, – build decision tree on new data set.
Ensemble the trees with averaged probability estimates.
This implementation deviates from the original in minor ways. It samples intervals with replacement and does not use the splitting criteria tiny refinement described in [1]. This is an intentionally stripped down, non configurable version for use as a hive-cote component. For a configurable tree based ensemble, see sktime.classifiers.ensemble.TimeSeriesForestClassifier
- Parameters
- n_estimatorsint, ensemble size, optional (default = 200)
- min_intervalint, minimum width of an interval, optional (default
- to 3)
- n_jobsint, optional (default=1)
The number of jobs to run in parallel for both fit and predict.
-1means using all processors.- random_stateint, seed for random, optional (default = none)
- Attributes
- n_classesint
- n_intervalsint
- classes_List of classes for a given problem
References
- 1
H.Deng, G.Runger, E.Tuv and M.Vladimir, “A time series forest for classification and feature extraction”,Information Sciences, 239, 2013 Java implementation https://github.com/uea-machine-learning/tsml/blob/master/src/main/ java/tsml/classifiers/interval_based/TSF.java Arxiv version of the paper: https://arxiv.org/abs/1302.2277
Methods
apply(X)Apply trees in the forest to X, return leaf indices.
Check if the estimator has been fitted.
clone_tags(estimator[, tag_names])clone/mirror tags from another estimator as dynamic override.
Construct Estimator instance if possible.
Return the decision path in the forest.
fit(X, y)Build a forest of trees from the training set (X, y).
get_class_tag(tag_name[, tag_value_default])Get tag value from estimator class (only class tags).
Get class tags from estimator class and all its parent classes.
get_params([deep])Get parameters for this estimator.
get_tag(tag_name[, tag_value_default])Get tag value from estimator class and dynamic tag overrides.
get_tags()Get tags from estimator class and dynamic tag overrides.
Get default parameters of the estimator.
predict(X)Find predictions for all cases in X.
Predict class log-probabilities for X.
Find 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_tags(**tag_dict)Set dynamic tags to given values.
- predict(X)[source]¶
Find predictions for all cases in X. Built on top of predict_proba.
- Parameters
- XThe training input samples. array-like or pandas data frame.
- If a Pandas data frame is passed, a check is performed that it only
- has one column.
- If not, an exception is thrown, since this classifier does not yet have
- multivariate capability.
- Returns
- outputarray of shape = [n_test_instances]
- predict_proba(X)[source]¶
Find probability estimates for each class for all cases in X.
- Parameters
- XThe training input samples. array-like or sparse matrix of shape
- = [n_test_instances, series_length]
If a Pandas data frame is passed (sktime format) a check is performed that it only has one column. If not, an exception is thrown, since this classifier does not yet have multivariate capability.
- Returns
- outputnd.array of shape = (n_instances, n_classes)
Predicted probabilities
- apply(X)[source]¶
Apply trees in the forest to X, return leaf indices.
- Parameters
- X{array-like, sparse matrix} of shape (n_samples, n_features)
The input samples. Internally, its dtype will be converted to
dtype=np.float32. If a sparse matrix is provided, it will be converted into a sparsecsr_matrix.
- Returns
- X_leavesndarray of shape (n_samples, n_estimators)
For each datapoint x in X and for each tree in the forest, return the index of the leaf x ends up in.
- check_is_fitted()[source]¶
Check if the estimator has been fitted.
- Raises
- NotFittedError
If the estimator has not been fitted yet.
- clone_tags(estimator, tag_names=None)[source]¶
clone/mirror tags from another estimator as dynamic override.
- Parameters
- estimatorestimator inheriting from :class:BaseEstimator
- tag_namesstr or list of str, default = None
Names of tags to clone. If None then all tags in estimator are used as tag_names.
- Returns
- Self :
Reference to self.
Notes
Changes object state by setting tag values in tag_set from estimator as dynamic tags in self.
- classmethod create_test_instance()[source]¶
Construct Estimator instance if possible.
- Returns
- instanceobject of the class with default parameters
Notes
get_test_params can return dict or list of dict. This function takes first or single dict that get_test_params returns, and constructs the object with that.
- decision_path(X)[source]¶
Return the decision path in the forest.
New in version 0.18.
- Parameters
- X{array-like, sparse matrix} of shape (n_samples, n_features)
The input samples. Internally, its dtype will be converted to
dtype=np.float32. If a sparse matrix is provided, it will be converted into a sparsecsr_matrix.
- Returns
- indicatorsparse matrix of shape (n_samples, n_nodes)
Return a node indicator matrix where non zero elements indicates that the samples goes through the nodes. The matrix is of CSR format.
- n_nodes_ptrndarray of shape (n_estimators + 1,)
The columns from indicator[n_nodes_ptr[i]:n_nodes_ptr[i+1]] gives the indicator value for the i-th estimator.
- property feature_importances_[source]¶
The impurity-based feature importances.
The higher, the more important the feature. The importance of a feature is computed as the (normalized) total reduction of the criterion brought by that feature. It is also known as the Gini importance.
Warning: impurity-based feature importances can be misleading for high cardinality features (many unique values). See
sklearn.inspection.permutation_importanceas an alternative.- Returns
- feature_importances_ndarray of shape (n_features,)
The values of this array sum to 1, unless all trees are single node trees consisting of only the root node, in which case it will be an array of zeros.
- fit(X, y)[source]¶
Build a forest of trees from the training set (X, y).
- Parameters
- Xt: np.ndarray or pd.DataFrame
Panel training data.
- ynp.ndarray
The class labels.
- Returns
- selfobject
An fitted instance of the classifier
- classmethod get_class_tag(tag_name, tag_value_default=None)[source]¶
Get tag value from estimator class (only class tags).
- Parameters
- tag_namestr
Name of tag value.
- tag_value_defaultany type
Default/fallback value if tag is not found.
- Returns
- tag_value :
Value of the tag_name tag in self. If not found, returns tag_value_default.
- classmethod get_class_tags()[source]¶
Get class tags from estimator class and all its parent classes.
- Returns
- collected_tagsdict
Dictionary of tag name : tag value pairs. Collected from _tags class attribute via nested inheritance. NOT overridden by dynamic tags set by set_tags or mirror_tags.
- 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.
- get_tag(tag_name, tag_value_default=None)[source]¶
Get tag value from estimator class and dynamic tag overrides.
- Parameters
- tag_namestr
Name of tag value.
- tag_value_defaultany type
Default/fallback value if tag is not found.
- Returns
- tag_value :
Value of the tag_name tag in self. If not found, returns tag_value_default.
- get_tags()[source]¶
Get tags from estimator class and dynamic tag overrides.
- Returns
- collected_tagsdict
Dictionary of tag name : tag value pairs. Collected from _tags class attribute via nested inheritance and then any overrides and new tags from _tags_dynamic object attribute.
- classmethod get_test_params()[source]¶
Get default parameters of the estimator.
- Returns
- paramsdict or list of dict, default = {}
Default parameters related to the estimator class
- property is_fitted[source]¶
Whether fit has been called.
- predict_log_proba(X)[source]¶
Predict class log-probabilities for X.
The predicted class log-probabilities of an input sample is computed as the log of the mean predicted class probabilities of the trees in the forest.
- Parameters
- X{array-like, sparse matrix} of shape (n_samples, n_features)
The input samples. Internally, its dtype will be converted to
dtype=np.float32. If a sparse matrix is provided, it will be converted into a sparsecsr_matrix.
- Returns
- pndarray of shape (n_samples, n_classes), or a list of n_outputs
such arrays if n_outputs > 1. The class probabilities of the input samples. The order of the classes corresponds to that in the attribute classes_.
- 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)wrt. 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_tags(**tag_dict)[source]¶
Set dynamic tags to given values.
- Parameters
- tag_dictdict
Dictionary of tag name : tag value pairs.
- Returns
- Self :
Reference to self.
Notes
Changes object state by settting tag values in tag_dict as dynamic tags in self.