如何建立数据流挖掘的滑动窗口模型?

发布于 2024-09-03 20:19:49 字数 136 浏览 8 评论 0原文

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

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

we have a situation that a stream (data from sensor or click stream data at server) is coming with sliding window algorithm we have to store the last (say) 500 samples of data in memory. These samples are then used to create histograms, aggregations & capture information about anomalies in the input data stream.

please tell me how to make such sliding window.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

过期情话 2024-09-10 20:19:49

如果您询问如何以滑动窗口方式存储和维护这些值,请考虑这个简单的示例,该示例跟踪某些随机数据流的最后 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

animation


更新

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

If you are asking how to store and maintain these values in a sliding-window manner, consider this simple example which keep tracks of the running mean of the last 10 values of some random stream of data:

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

animation


Update

The EraseMode=none property was deprecated and removed in recent versions. Use the animatedline function instead for a similar functionality.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文