AEFCNClusterer¶
- class AEFCNClusterer(n_clusters=None, estimator=None, clustering_algorithm='deprecated', clustering_params=None, latent_space_dim=128, temporal_latent_space=False, n_layers=3, n_filters=None, kernel_size=None, dilation_rate=1, strides=1, padding='same', activation='relu', use_bias=True, n_epochs=2000, batch_size=32, use_mini_batch_size=False, random_state=None, verbose=False, loss='mse', metrics=None, optimizer='Adam', file_path='./', save_best_model=False, save_last_model=False, best_file_name='best_model', last_file_name='last_file', callbacks=None)[source]¶
Auto-Encoder based Fully Convolutional Network (FCN), as described in [1].
- Parameters:
- n_clustersint, default=None
Please use ‘estimator’ parameter.
- estimatoraeon clusterer, default=None
An aeon estimator to be built using the transformed data. Defaults to aeon TimeSeriesKMeans() with euclidean distance and mean averaging method and n_clusters set to 2.
- clustering_algorithmstr, default=”deprecated”
Please use ‘estimator’ parameter.
- clustering_paramsdict, default=None
Please use ‘estimator’ parameter.
- latent_space_dimint, default=128
Dimension of the latent space of the auto-encoder.
- temporal_latent_spacebool, default = False
Flag to choose whether the latent space is an MTS or Euclidean space.
- n_layersint, default = 3
Number of convolution layers.
- n_filtersint or list of int, default = [128,256,128]
Number of filters used in convolution layers.
- kernel_sizeint or list of int, default = [8,5,3]
Size of convolution kernel.
- dilation_rateint or list of int, default = 1
The dilation rate for convolution.
- stridesint or list of int, default = 1
The strides of the convolution filter.
- paddingstr or list of str, default = “same”
The type of padding used for convolution.
- activationstr or list of str, default = “relu”
Activation used after the convolution.
- use_biasbool or list of bool, default = True
Whether or not ot use bias in convolution.
- n_epochsint, default = 2000
The number of epochs to train the model.
- batch_sizeint, default = 16
The number of samples per gradient update.
- use_mini_batch_sizebool, default = True,
Whether or not to use the mini batch size formula.
- random_stateint, RandomState instance or None, default=None
If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, the random number generator is the RandomState instance used by np.random. Seeded random number generation can only be guaranteed on CPU processing, GPU processing will be non-deterministic.
- verboseboolean, default = False
Whether to output extra information.
- lossstring, default=”mean_squared_error”
Fit parameter for the keras model.
- metricskeras metrics, default = [“mean_squared_error”]
will be set to mean_squared_error as default if None
- optimizerkeras.optimizers object, default = Adam(lr=0.01)
Specify the optimizer and the learning rate to be used.
- file_pathstr, default = “./”
File path to save best model.
- save_best_modelbool, default = False
Whether or not to save the best model, if the modelcheckpoint callback is used by default, this condition, if True, will prevent the automatic deletion of the best saved model from file and the user can choose the file name.
- save_last_modelbool, default = False
Whether or not to save the last model, last epoch trained, using the base class method save_last_model_to_file.
- best_file_namestr, default = “best_model”
The name of the file of the best model, if save_best_model is set to False, this parameter is discarded.
- last_file_namestr, default = “last_model”
The name of the file of the last model, if save_last_model is set to False, this parameter is discarded.
- callbackskeras.callbacks, default = None
List of keras callbacks.
Notes
Adapted from the implementation from Fawaz et. al https://github.com/hfawaz/dl-4-tsc/blob/master/classifiers/fcn.py
References
[1]Zhao et. al, Convolutional neural networks for time series classification,
Journal of Systems Engineering and Electronics, 28(1):2017.
Examples
>>> from aeon.clustering.deep_learning import AEFCNClusterer >>> from aeon.datasets import load_unit_test >>> 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) >>> aefcn = AEFCNClusterer(n_epochs=5,batch_size=4) >>> aefcn.fit(X_train) AEFCNClusterer(...)
Methods
build_model
(input_shape, **kwargs)Construct a compiled, un-trained, keras model that is ready for training.
Check if the estimator has been fitted.
clone
([random_state])Obtain a clone of the object with the same hyperparameters.
create_test_instance
([parameter_set, ...])Construct Estimator instance if possible.
fit
(X[, y])Fit time series clusterer to training data.
fit_predict
(X[, y])Compute cluster centers and predict cluster index for each time series.
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_fitted_params
([deep])Get fitted parameters.
Get metadata routing of this object.
get_params
([deep])Get parameters for this estimator.
get_tag
(tag_name[, tag_value_default, ...])Get tag value from estimator class.
get_tags
()Get tags from estimator.
get_test_params
([parameter_set])Return testing parameter settings for the estimator.
load_from_path
(serial)Load object from file location.
load_from_serial
(serial)Load object from serialized memory container.
predict
(X[, y])Predict the closest cluster each sample in X belongs to.
Predicts labels probabilities for sequences in X.
reset
([keep])Reset the object to a clean post-init state.
save
([path])Save serialized self to bytes-like object or to (.zip) file.
save_last_model_to_file
([file_path])Save the last epoch of the trained deep learning model.
score
(X[, y])Score the quality of the clusterer.
set_params
(**params)Set the parameters of this estimator.
set_tags
(**tag_dict)Set dynamic tags to given values.
summary
()Summary function to return the losses/metrics for model fit.
- build_model(input_shape, **kwargs)[source]¶
Construct a compiled, un-trained, keras model that is ready for training.
In aeon, time series are stored in numpy arrays of shape (n_channels,n_timepoints). Keras/tensorflow assume data is in shape (n_timepoints,n_channels). This method also assumes (n_timepoints,n_channels). Transpose should happen in fit.
- Parameters:
- input_shapetuple
The shape of the data fed into the input layer, should be (n_timepoints,n_channels).
- Returns:
- outputa compiled Keras Model.
- classmethod get_test_params(parameter_set='default')[source]¶
Return testing parameter settings for the estimator.
- Parameters:
- parameter_setstr, default=”default”
Name of the set of test parameters to return, for use in tests. If no special parameters are defined for a value, will return “default” set. For classifiers, a “default” set of parameters should be provided for general testing, and a “results_comparison” set for comparing against previously recorded results if the general set does not produce suitable probabilities to compare against.
- Returns:
- paramsdict or list of dict, default={}
Parameters to create testing instances of the class. Each dict are parameters to construct an “interesting” test instance, i.e., MyClass(**params) or MyClass(**params[i]) creates a valid test instance. create_test_instance uses the first (or only) dictionary in params.
- check_is_fitted()[source]¶
Check if the estimator has been fitted.
- Raises:
- NotFittedError
If the estimator has not been fitted yet.
- clone(random_state=None)[source]¶
Obtain a clone of the object with the same hyperparameters.
A clone is a different object without shared references, in post-init state. This function is equivalent to returning
sklearn.clone
of self. Equal in value totype(self)(**self.get_params(deep=False))
.- Parameters:
- random_stateint, RandomState instance, or None, default=None
Sets the random state of the clone. If None, the random state is not set. If int, random_state is the seed used by the random number generator. If RandomState instance, random_state is the random number generator.
- Returns:
- estimatorobject
Instance of
type(self)
, clone of self (see above)
- classmethod create_test_instance(parameter_set='default', return_first=True)[source]¶
Construct Estimator instance if possible.
Calls the get_test_params method and returns an instance or list of instances using the returned dict or list of dict.
- Parameters:
- parameter_setstr, default=”default”
Name of the set of test parameters to return, for use in tests. If no special parameters are defined for a value, will return “default” set.
- return_firstbool, default=True
If True, return the first instance of the list of instances. If False, return the list of instances.
- Returns:
- instanceBaseAeonEstimator or list of BaseAeonEstimator
Instance of the class with default parameters. If return_first is False, returns list of instances.
- fit(X, y=None) BaseCollectionEstimator [source]¶
Fit time series clusterer to training data.
- Parameters:
- X3D np.ndarray (any number of channels, equal length series)
of shape (n_cases, n_channels, n_timepoints)
- or 2D np.array (univariate, equal length series)
of shape (n_cases, n_timepoints)
- or list of numpy arrays (any number of channels, unequal length series)
of shape [n_cases], 2D np.array (n_channels, n_timepoints_i), where n_timepoints_i is length of series i
other types are allowed and converted into one of the above.
- y: ignored, exists for API consistency reasons.
- Returns:
- self:
Fitted estimator.
- fit_predict(X, y=None) ndarray [source]¶
Compute cluster centers and predict cluster index for each time series.
Convenience method; equivalent of calling fit(X) followed by predict(X)
- Parameters:
- Xnp.ndarray (2d or 3d array of shape (n_cases, n_timepoints) or shape
(n_cases, n_channels, n_timepoints)). Time series instances to train clusterer and then have indexes each belong to return.
- y: ignored, exists for API consistency reasons.
- Returns:
- np.ndarray (1d array of shape (n_cases,))
Index of the cluster each time series in X belongs to.
- classmethod get_class_tag(tag_name, tag_value_default=None, raise_error=False)[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.
- raise_errorbool
Whether a ValueError is raised when the tag is not found.
- Returns:
- tag_value
Value of the
tag_name
tag in self. If not found, returns an error if raise_error is True, otherwise it returns tag_value_default.
- Raises:
- ValueError
if raise_error is
True
andtag_name
is not inself.get_tags().keys()
Examples
>>> from aeon.classification import DummyClassifier >>> DummyClassifier.get_class_tag("capability:multivariate") True
- classmethod get_class_tags()[source]¶
Get class tags from estimator class and all its parent classes.
- Returns:
- collected_tagsdict
Dictionary of tag name and tag value pairs. Collected from
_tags
class attribute via nested inheritance. These are not overridden by dynamic tags set byset_tags
or class__init__
calls.
- get_fitted_params(deep=True)[source]¶
Get fitted parameters.
- State required:
Requires state to be “fitted”.
- Parameters:
- deepbool, default=True
Whether to return fitted parameters of components.
If True, will return a dict of parameter name : value for this object, including fitted parameters of fittable components (= BaseAeonEstimator-valued parameters).
If False, will return a dict of parameter name : value for this object, but not include fitted parameters of components.
- Returns:
- fitted_paramsdict with str-valued keys
Dictionary of fitted parameters, paramname : paramvalue keys-value pairs include:
always: all fitted parameters of this object
if
deep=True
, also contains keys/value pairs of component parameters parameters of components are indexed as[componentname]__[paramname]
all parameters ofcomponentname
appear asparamname
with its valueif
deep=True
, also contains arbitrary levels of component recursion, e.g.,[componentname]__[componentcomponentname]__[paramname]
, etc.
- 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.
- get_tag(tag_name, tag_value_default=None, raise_error=True)[source]¶
Get tag value from estimator class.
Includes dynamic and overridden tags.
- Parameters:
- tag_namestr
Name of tag to be retrieved.
- tag_value_defaultany type, default=None
Default/fallback value if tag is not found.
- raise_errorbool
Whether a ValueError is raised when the tag is not found.
- Returns:
- tag_value
Value of the
tag_name
tag in self. If not found, returns an error if raise_error is True, otherwise it returns tag_value_default.
- Raises:
- ValueError
if raise_error is
True
andtag_name
is not inself.get_tags().keys()
Examples
>>> from aeon.classification import DummyClassifier >>> d = DummyClassifier() >>> d.get_tag("capability:multivariate") True
- get_tags()[source]¶
Get tags from estimator.
Includes dynamic and overridden tags.
- Returns:
- collected_tagsdict
Dictionary of tag name and tag value pairs. Collected from
_tags
class attribute via nested inheritance and then any overridden and new tags from__init__
orset_tags
.
- classmethod load_from_path(serial)[source]¶
Load object from file location.
- Parameters:
- serialobject
Result of ZipFile(path).open(“object).
- Returns:
- deserialized self resulting in output at path, of cls.save(path)
- classmethod load_from_serial(serial)[source]¶
Load object from serialized memory container.
- Parameters:
- serialobject
First element of output of cls.save(None).
- Returns:
- deserialized self resulting in output serial, of cls.save(None).
- predict(X, y=None) ndarray [source]¶
Predict the closest cluster each sample in X belongs to.
- Parameters:
- X3D np.ndarray
Input data, any number of channels, equal length series of shape
( n_cases, n_channels, n_timepoints)
or 2D np.array (univariate, equal length series) of shape(n_cases, n_timepoints)
or list of numpy arrays (any number of channels, unequal length series) of shape[n_cases]
, 2D np.array(n_channels, n_timepoints_i)
, wheren_timepoints_i
is length of seriesi
. Other types are allowed and converted into one of the above.- y: ignored, exists for API consistency reasons.
- Returns:
- np.array
shape ``(n_cases)`, index of the cluster each time series in X. belongs to.
- predict_proba(X) ndarray [source]¶
Predicts labels probabilities for sequences in X.
Default behaviour is to call _predict and set the predicted class probability to 1, other class probabilities to 0. Override if better estimates are obtainable.
- Parameters:
- X3D np.ndarray
Input data, any number of channels, equal length series of shape
( n_cases, n_channels, n_timepoints)
or 2D np.array (univariate, equal length series) of shape(n_cases, n_timepoints)
or list of numpy arrays (any number of channels, unequal length series) of shape[n_cases]
, 2D np.array(n_channels, n_timepoints_i)
, wheren_timepoints_i
is length of seriesi
. Other types are allowed and converted into one of the above.
- Returns:
- y2D array of shape [n_cases, n_classes] - predicted class probabilities
1st dimension indices correspond to instance indices in X 2nd dimension indices correspond to possible labels (integers) (i, j)-th entry is predictive probability that i-th instance is of class j
- reset(keep=None)[source]¶
Reset the object to a clean post-init state.
After a
self.reset()
call, self is equal or similar in value totype(self)(**self.get_params(deep=False))
, assuming no other attributes were kept usingkeep
.- Detailed behaviour:
- removes any object attributes, except:
hyper-parameters (arguments of
__init__
) object attributes containing double-underscores, i.e., the string “__”
runs
__init__
with current values of hyperparameters (result of get_params)- Not affected by the reset are:
object attributes containing double-underscores class and object methods, class attributes any attributes specified in the
keep
argument
- Parameters:
- keepNone, str, or list of str, default=None
If None, all attributes are removed except hyper-parameters. If str, only the attribute with this name is kept. If list of str, only the attributes with these names are kept.
- Returns:
- self
Reference to self.
- save(path=None)[source]¶
Save serialized self to bytes-like object or to (.zip) file.
Behaviour: if path is None, returns an in-memory serialized self if path is a file location, stores self at that location as a zip file
saved files are zip files with following contents: _metadata - contains class of self, i.e., type(self) _obj - serialized self. This class uses the default serialization (pickle).
- Parameters:
- pathNone or file location (str or Path).
if None, self is saved to an in-memory object if file location, self is saved to that file location. If:
path=”estimator” then a zip file estimator.zip will be made at cwd. path=”/home/stored/estimator” then a zip file estimator.zip will be stored in /home/stored/.
- Returns:
- if path is None - in-memory serialized self
- if path is file location - ZipFile with reference to the file.
- save_last_model_to_file(file_path='./')[source]¶
Save the last epoch of the trained deep learning model.
- Parameters:
- file_pathstr, default = “./”
The directory where the model will be saved
- Returns:
- None
- score(X, y=None) float [source]¶
Score the quality of the clusterer.
- Parameters:
- Xnp.ndarray (2d or 3d array of shape (n_cases, n_timepoints) or shape
(n_cases, n_channels, n_timepoints)). Time series instances to train clusterer and then have indexes each belong to return.
- y: ignored, exists for API consistency reasons.
- Returns:
- scorefloat
Score of the clusterer.
- 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.