matlab - 如何对时间序列数据执行 K 均值聚类?

标签 matlab time-series cluster-analysis data-mining k-means

如何对时间序列数据进行 K 均值聚类? 我了解当输入数据是一组点时这是如何工作的,但我不知道如何使用 1XM 对时间序列进行聚类,其中 M 是数据长度。特别是,我不确定如何更新时间序列数据的集群均值。

我有一组带标签的时间序列,我想使用 K-means 算法来检查我是否会得到类似的标签。我的 X 矩阵将是 N X M,其中 N 是时间序列的数量,M 是数据长度,如上所述。

有人知道怎么做吗?例如,我如何修改 this k-means MATLAB code以便它适用于时间序列数据?此外,我希望能够使用除欧氏距离之外的不同距离度量。

为了更好地说明我的疑惑,这里是我为时间序列数据修改的代码:


% Check if second input is centroids
if ~isscalar(k) 
    c=k;
    k=size(c,1);
else
    c=X(ceil(rand(k,1)*n),:); % assign centroid randomly at start
end

% allocating variables
g0=ones(n,1); 
gIdx=zeros(n,1);
D=zeros(n,k);

% Main loop converge if previous partition is the same as current
while any(g0~=gIdx)
%     disp(sum(g0~=gIdx))
    g0=gIdx;
    % Loop for each centroid
    for t=1:k
        %  d=zeros(n,1);
        % Loop for each dimension
        for s=1:n
            D(s,t) = sqrt(sum((X(s,:)-c(t,:)).^2)); 
        end
    end
    % Partition data to closest centroids
    [z,gIdx]=min(D,[],2);
    % Update centroids using means of partitions
    for t=1:k

        % Is this how we calculate new mean of the time series?
        c(t,:)=mean(X(gIdx==t,:));

    end
end

最佳答案

时间序列通常是高维的。并且您需要专门的距离函数来比较它们的相似性。另外,可能存在异常值。

k-means 专为具有(有意义的)欧氏距离的低维空间而设计。它对异常值不是很稳健,因为它对异常值施加了平方权重。

对我来说,对时间序列数据使用 k-means 听起来不是个好主意。尝试研究更现代、更强大的聚类算法。许多将允许您使用任意距离函数,包括时间序列距离,例如 DTW。

关于matlab - 如何对时间序列数据执行 K 均值聚类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3503668/

相关文章:

Matlab绘图去除刻度线

matlab - 为 NaN 值创建 Bin

r - 在 R 中使用 Fable 进行时间序列预测;确定混合模型的最佳模型组合

python - pyclustering 当矩阵具有三个以上的维度时可视化 xmeans

python - 绘制同一社区或分区的网络和分组顶点

python - Hadoop 和 NLTK : Fails with stopwords

matlab - 通过 cuFFT 在逆 FFT 中缩放

matlab - Armadillo + Matlab Mex 段错误

python - 将每日和每月时间序列与 Pandas 合并

r - 用平均值填补时间序列中的空白