【问题标题】:how to make Sliding window model for data stream mining?如何制作数据流挖掘的滑动窗口模型?
【发布时间】:2011-02-26 05:04:03
【问题描述】:

我们有一个流(来自传感器的数据或服务器上的点击流数据)带有滑动窗口算法的情况,我们必须将最后(例如)500 个数据样本存储在内存中。然后使用这些样本创建直方图、聚合和捕获有关输入数据流中异常的信息。

请告诉我如何制作这样的滑动窗口。

【问题讨论】:

    标签: matlab plot scroll sliding-window data-stream


    【解决方案1】:

    如果您询问如何以滑动窗口的方式存储和维护这些值,请考虑以下简单示例,该示例跟踪某些随机数据流的最后 10 个值的运行平均值:

    WINDOW_SIZE = 10;
    x = nan(WINDOW_SIZE,1);
    
    %# init
    counter = 0;
    stats = [NaN NaN];                    %# previous/current value
    
    %# prepare figure
    SHOW_LIM = 200;
    hAx = axes('XLim',[1 SHOW_LIM], 'YLim',[200 800]);
    hLine = line('XData',1, 'YData',nan, 'EraseMode','none', ...
        'Parent',hAx, 'Color','b', 'LineWidth',2);
    
    %# infinite loop!
    while true
       val = randi([1 1000]);            %# get new value from data stream
       x = [ x(2:end) ; val ];           %# add to window in a cyclic manner
       counter = counter + 1;
    
       %# do something interesting with x
       stats(1) = stats(2);              %# keep track of the previous mean
       stats(2) = nanmean(x);            %# update the current mean
    
       %# show and update plot
       set(hLine, 'XData',[counter-1 counter], 'YData',[stats(1) stats(2)])
       if rem(counter,SHOW_LIM)==0
          %# show only the last couple of means
          set(hAx, 'XLim', [counter counter+SHOW_LIM]);
       end
       drawnow
       pause(0.02)
       if ~ishandle(hAx), break, end     %# break in case you close the figure
    end
    


    更新

    EraseMode=none property 在最近的版本中已被弃用和删除。使用animatedline 函数代替类似的功能。

    【讨论】:

    • 感谢它真的很有帮助它让我知道如何处理数据再次感谢
    猜你喜欢
    • 2011-02-07
    • 1970-01-01
    • 2011-12-16
    • 2019-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-28
    • 2013-07-21
    相关资源
    最近更新 更多