tslearn.utils.check_dims¶
- tslearn.utils.check_dims(X, X_fit_dims=None, extend=True, check_n_features_only=False)[source]¶
将X重塑为一个3维数组,其中X.shape[0]个单变量时间序列,每个时间序列的长度为X.shape[1],前提是X是2维的且extend为True。然后检查提供的X_fit_dims和X的维度(除了第一个维度)是否匹配。
- Parameters:
- Xarray-like
要比较的第一个数组。
- X_fit_dimstuple (default: None)
由fit生成的数据的维度,用于与提供的数组X的维度进行比较。 如果为None,则仅在必要时执行X的重塑。
- extendboolean (default: True)
是否重塑X,如果它是二维的。
- check_n_features_only: boolean (default: False)
- Returns:
- array
重塑后的X数组
- Raises:
- ValueError
如果X为None或(如果提供了X_fit_dims)提供的数据的维度之一(除了第一个)与X_fit_dims不匹配,将引发异常。
示例
>>> X = numpy.empty((10, 3)) >>> check_dims(X).shape (10, 3, 1) >>> X = numpy.empty((10, 3, 1)) >>> check_dims(X).shape (10, 3, 1) >>> X_fit_dims = (5, 3, 1) >>> check_dims(X, X_fit_dims).shape (10, 3, 1) >>> X_fit_dims = (5, 3, 2) >>> check_dims(X, X_fit_dims) Traceback (most recent call last): ValueError: Dimensions (except first) must match! ((5, 3, 2) and (10, 3, 1) are passed shapes) >>> X_fit_dims = (5, 5, 1) >>> check_dims(X, X_fit_dims, check_n_features_only=True).shape (10, 3, 1) >>> X_fit_dims = (5, 5, 2) >>> check_dims( ... X, ... X_fit_dims, ... check_n_features_only=True ... ) Traceback (most recent call last): ValueError: Number of features of the provided timeseries must match! (last dimension) must match the one of the fitted data! ((5, 5, 2) and (10, 3, 1) are passed shapes)