TimeSeriesKernelKMeans
TimeSeriesKernelKMeans
- class TimeSeriesKernelKMeans(n_clusters: int = 8, kernel: str = 'gak', n_init: int = 10, max_iter: int = 300, tol: float = 0.0001, kernel_params: dict | None = None, verbose: bool = False, n_jobs: int | None = None, random_state: int | RandomState = None)[source]
Kernel k-means clustering, from tslearn.
Direct interface to
tslearn.clustering.KernelKMeans.- Parameters:
- n_clusters: int, defaults = 8
The number of clusters to form as well as the number of centroids to generate.
- kernelstring, or callable (default: “gak”)
The kernel should either be “gak”, in which case the Global Alignment Kernel from [2]_ is used or a value that is accepted as a metric by scikit-learn’s pairwise_kernels
- n_init: int, defaults = 10
Number of times the k-means algorithm will be run with different centroid seeds. The final result will be the best output of n_init consecutive runs in terms of inertia.
- kernel_paramsdict or None (default: None)
Kernel parameters to be passed to the kernel function. None means no kernel parameter is set. For Global Alignment Kernel, the only parameter of interest is
sigma. If set to ‘auto’, it is computed based on a sampling of the training set (cf tslearn.metrics.sigma_gak). If no specific value is set forsigma, its defaults to 1.- max_iter: int, defaults = 300
Maximum number of iterations of the k-means algorithm for a single run.
- tol: float, defaults = 1e-4
Relative tolerance with regards to Frobenius norm of the difference in the cluster centers of two consecutive iterations to declare convergence.
- verbose: bool, defaults = False
Verbosity mode.
- n_jobsint or None, optional (default=None)
The number of jobs to run in parallel for GAK cross-similarity matrix computations.
Nonemeans 1 unless in ajoblib.parallel_backendcontext.-1means using all processors. See scikit-learns’ Glossary for more details.- random_state: int or np.random.RandomState instance or None, defaults = None
Determines random number generation for centroid initialization.
- Attributes:
- labels_: np.ndarray (1d array of shape (n_instance,))
Labels that is the index each time series belongs to.
- inertia_: float
Sum of squared distances of samples to their closest cluster center, weighted by the sample weights if provided.
- n_iter_: int
Number of iterations run.
Examples
>>> from sktime.clustering.kernel_k_means import TimeSeriesKernelKMeans >>> from sktime.datasets import load_arrow_head >>> X_train, y_train = load_arrow_head(split="train") >>> X_test, y_test = load_arrow_head(split="test") >>> clusterer = TimeSeriesKernelKMeans(n_clusters=3) >>> clusterer.fit(X_train) TimeSeriesKernelKMeans(n_clusters=3) >>> y_pred = clusterer.predict(X_test)
Methods
check_is_fitted([method_name])Check if the estimator has been fitted.
clone()Obtain a clone of the object with same hyper-parameters and config.
clone_tags(estimator[, tag_names])Clone tags from another object as dynamic override.
create_test_instance([parameter_set])Construct an instance of the class, using first test parameter set.
create_test_instances_and_names([parameter_set])Create list of all test instances and a list of names for them.
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 class tag value from class, with tag level inheritance from parents.
get_class_tags()Get class tags from class, with tag level inheritance from parent classes.
get_config()Get config flags for self.
get_fitted_params([deep])Get fitted parameters.
get_param_defaults()Get object's parameter defaults.
get_param_names([sort])Get object's parameter names.
get_params([deep])Get a dict of parameters values for this object.
get_tag(tag_name[, tag_value_default, ...])Get tag value from instance, with tag level inheritance and overrides.
get_tags()Get tags from instance, with tag level inheritance and overrides.
get_test_params([parameter_set])Return testing parameter settings for the estimator.
is_composite()Check if the object is composed of other BaseObjects.
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.
predict_proba(X)Predicts labels probabilities for sequences in X.
reset()Reset the object to a clean post-init state.
save([path, serialization_format])Save serialized self to bytes-like object or to (.zip) file.
score(X[, y])Score the quality of the clusterer.
set_config(**config_dict)Set config flags to given values.
set_params(**params)Set the parameters of this object.
set_random_state([random_state, deep, ...])Set random_state pseudo-random seed parameters for self.
set_tags(**tag_dict)Set instance level tag overrides to given values.

