Docsity

Streaming Data Analytics - schemino, Dispense di Database Relazionali

Anteprima parziale del testo

Scarica Streaming Data Analytics - schemino e più Dispense in PDF di Database Relazionali solo su Docsity!

Streaming Data Analytics

Pole’s schemino

Table of Contents

Continuous Numerous Flows that can Turn into a Torrent: Complex Event Processing (EPL)

Final Forward Transfer.............................................................................................................. 84 Strategies........................................................................................................................................ 84 Neural Networks 101..................................................................................................................... 88 Streaming Machine Learning vs Continual Learning.................................................................... 88 Different Settings...................................................................................................................... 88 What Type of Drift they can Handle......................................................................................... 88 Different Goals.......................................................................................................................... 89 Different Evaluations................................................................................................................ 89 Online CL.................................................................................................................................. 89 Answers to questions.......................................................................................................................... 90 Breadth of Streaming Data Engineering........................................................................................ 90 Which are the four approaches to tame velocity? List them all before comparing and contrasting two of them............................................................................................................. 90 Which are the three time-models we introduced? List them all before comparing and contrasting two of them............................................................................................................. 90 What are the basic types of windows? List them all and describe the behavior of at least two of them...................................................................................................................................... 90 What is a context, and how does it relate to interval-based time model? Give an example that supports your explanation......................................................................................................... 91 !!! Why do we say that a Complex Event Processor can tame the torrent effect? Support your claim with an example.............................................................................................................. 91 What are latency/throughput? Given an example of both in the same domain........................ 92 Is there an exact incremental algorithm for computing average, median and distinct? Why?. 92 !!! Describe the Kafka components at a conceptual, system, and physical level. Illustrate them using an example....................................................................................................................... 92 !!! Illustrate the programming model of Spark Structured Streaming at the logical and physical level. Illustrate them using an example...................................................................... 93 How does Spark Structured Stream treat late arrivals in windowed aggregation? Illustrate it using an example....................................................................................................................... 93 Depth of Streaming Data Engineering........................................................................................... 94 What’s the difference between the stream-only and the absolute time models? Explain it, proposing examples of queries that can be answered in both models and queries that can be answered only with the absolute time model............................................................................ 94 What’s the difference between the absolute and the interval-based time models? Explain it, proposing examples of queries that can be answered in both models and queries that can be answered only with the interval-based time model................................................................... 94 What are streams and events? How do they relate to each other? Give an example................ 94 !!! What is a tumbling logical window? Give an example at the conceptual level and show that you know both EPL’s and Spark Structured Streaming’s syntax....................................... 94 !!! What is a hopping logical window? Give an example at the conceptual level and show that you know both EPL’s and Spark Structured Streaming’s syntax.............................................. 95 What is the role of the output clause in EPL? Does it exist in Spark Structured Streaming? Give an example that supports your explanation...................................................................... 95 What’s the role of the followed by operator (->) in EPL? Is it possible to implement it in Spark Structured Streaming? Give an example that supports your explanation....................... 95 Explain stream to stream joins. Given an example in EPL or Spark Structured Streaming that illustrates the different results you obtain using an inner and a left outer join......................... 96 Explain stream to table joins. Given an example in EPL or Spark Structured Streaming that illustrates the different results you obtain using an inner and a left outer join......................... 97 What makes Kafka scale horizontally? Explain it using an example....................................... 97 What’s the role of a topic in Kafka? How does it relate to partitions and brokers? Explain it using an example....................................................................................................................... 98

!!! Which are the typical Streaming Machine Learning algorithms for classification? Illustrate one of them in detail................................................................................................................ 113 !!! What are the key factors to consider when building an SML Ensemble Classification model?..................................................................................................................................... 114 How does SML regression compare to time series forecasting w.r.t. types of input features, training, forecasting horizon, and adaptability?...................................................................... 115 Depth of Streaming Machine Learning........................................................................................ 116 !!! Which are the drift detectors that monitor the error rate? Illustrate how one of them works. ................................................................................................................................................. 116 !!! Which are the data drift detectors? Illustrate how one of them works............................... 117 How does ADWIN detect a concept drift? Illustrate it with an example................................ 118 How does the SML version of KNN work? Illustrate it with an example.............................. 118 !!! How does the SML version of Naïve Bayes work? Illustrate it with an example............. 118 How does the Hoeffding Tree work? Illustrate it with an example........................................ 119 How does the Hoeffding Adaptive Tree work? Illustrate it with an example......................... 119 What is Hoeffding Bound? How and why is it used in SML to build a decision tree?........... 119 !!! Why is the Poisson distribution used in SML ensemble methods? What’s the impact of the value of lambda? Illustrate how lambda is used in the SML methods.................................... 120 Breadth and Depth of Continual Learning................................................................................... 120 What’s the stability-plasticity dilemma? Illustrate your explanation with a narrative example and discuss the different learning abilities that a CL solution should have............................ 120 What are the main differences between Streaming Machine Learning and Continual Learning? Discuss them w.r.t to the setting, the goals, and the evaluation process................................. 121 What are the main differences between Streaming Machine Learning and Continual Learning w.r.t. the concept drifts they manage? Discuss also which cases require avoiding forgetting and which do not..................................................................................................................... 122 What are the three main scenarios in Continual Learning? Describe each of them briefly.... 123 !!! How do CL replay strategies work? Explain one specific strategy in detail. What are the other two categories of CL strategies? Briefly explain them.................................................. 124 !!! How do CL regularization strategies work? Explain one specific strategy in detail. What are the other two categories of CL strategies? Briefly explain them...................................... 125 !!! How do CL architectural strategies work? Explain one specific strategy in detail. What are the other two categories of CL strategies? Briefly explain them............................................ 126 !!! Which are the primary evaluation metrics used in Continual Learning? Illustrate what they measure and why they are all useful to assess the properties of a method............................. 128 Exercises........................................................................................................................................... 128 EPL.............................................................................................................................................. 128 Basics...................................................................................................................................... 128 SQL style queries.................................................................................................................... 129 Event Based style queries....................................................................................................... 129 Grouping and average operator............................................................................................... 129 Logical Tumbling Window..................................................................................................... 129 Physical Tumbling Window.................................................................................................... 129 Logical Sliding Window......................................................................................................... 129 Physical Sliding Window........................................................................................................ 129 Average over a window........................................................................................................... 130 Output clause........................................................................................................................... 130 Pattern Matching..................................................................................................................... 131 Every....................................................................................................................................... 132 Pattern Guards......................................................................................................................... 133 Example on IBM stock market............................................................................................... 134 Creating a table from an unbounded stream........................................................................... 134

Streaming Data Engineering

Introduction

4 types of velocity/streams in streaming data engineering:

  • Event Based system: collects myriads of tiny flows
  • Data Stream Management System: handle continuous few massive unstoppable flows
  • Complex Event Processing: handle continuous numerous flows that can turn into a turrent
  • Event Driven Architecture: handle any flow of any size and speed Regarding streaming data science:
  • Time Series Analytics: explain the past and forecast the future of a continuous flow of data without assuming data independence
  • Streaming Machine Learning: learning one data at a time from a continuous flow of data without assuming identically distributed data
  • Continual Learning: long life learning from a sequence of experiences without forgetting the past

Time Models

Stream only

You only know the order of arrival of events. You cannot measure the time between events, but only know if something happened before or after another event. Events can be forgotten so answers can change over time.

Absolute

We know when (what time) an event arrives. This helps to know not only if something happened before another, but how much time passed between two events.

Interval-base

Here we also know how much an event is long, and so if one or more event overlaps or get the events that last more or less than a certain amount of time.

Continuous Numerous Flows that can Turn into a Torrent: Complex

Event Processing (EPL)

CEP systems allow to define rules to generate composite events from primitive ones (raise if ).

Handle Myriads of flows of any size and speed: Event Driven

Architecture

Store events so that a service writes once and clients can read many times asynchronously.

from TemperatureSensorEvent where temperature > 50;

  • With the Event-Based System Style the data points are filtered before even flowing into the query and thus the query execution is not even triggered select * from TemperatureSensorEvent(temperature > 50);

Basic Aggregation

select sensor, avg(temperature) from TemperatureSensorEvent group by sensor; You evaluate data by only saving what matters and so you can delete old data. In the case of the average you save the number of events seen so far and the previous average so you can compute the new one just by saving two values in memory.

Data Windowing

They instruct the engine how long to retain relevant events or under what conditions events can be discarded. In EPL the possible window types are:

  • Logical Sliding (win:time(time_period) or #time(time_period)): sliding window that covers the specified time interval into the past
    • The events received in the last 4 seconds for every event
  • Logical Tumbling (win:time_batch(time_period[, reference point] [, flow control]) or #time_batch(time_period …)): tumbling window that batches events and releases them every specified time interval, with flow control options
  • The events received in the last 2 seconds every 2 seconds
  • Physical Sliding (win:length(size) or #length(size)): sliding window that covers the specified number of elements into the past
  • The last 4 events received for every event
  • Physical Tumbling (win:length_batch(size) or #length_batch(size)): tumbling window that batches events and releases them when a given minimum number of events has been collected
  • The last 2 events received
  • BONUS: Logical Hopping : last 4 seconds every 2 seconds
  • select sensor, avg(temperature) from TemperatureSensorEvent.win:time(4 seconds) group by sensor output snapshot every 2 seconds; You can use them in a query in the from clause of an event: from TemperatureSensorEvent.win:time(4 seconds)

Output

output [all | first | last | snapshot] every output_rate [seconds | events] It is used to create logical hopping windows. Here is an explanation of the keywords:

  • first ensures that the first result generated by the query is output immediately
  • last outputs the most recent result at the time of the query’s execution, discarding any intermediate results that may have been calculated
  • all outputs every result generated by the query, including both current and previous calculations (if previous calculations are not possible anymore because data in the current time slot/batch has not arrived then output null, for example if I want to calculate the average of S1 and S2 but in a certain time slot/batch there is no data arriving from S1 then output null as the average)
  • snapshot outputs only the current state of the query at the specified interval. Unlike all, it doesn’t include previous results
  • [num] and until
  • Guards filter out events and cause termination
  • timer:within it constraints the arrival of an event wrt to the arrival of another event (only if the TemperatureSensorEvent must occur within 2 seconds after the matching SmokeSensorEvent)
  • timer:withinmax
  • while-expression
  • Logical operators
  • and
  • or
  • not Example: select a.sensor from pattern [ a = SmokeEvent(smoke=true) -> TempEvent(val>50, sensor=a.sensor) where timer:within(2 min) ] Note that this example matches only once, to make it match multiple times, use every select a.sensor from pattern [every( a = SmokeEvent(smoke=true) -> TempEvent(val>50, sensor=a.sensor) where timer:within(2 min) )] The where keyword counts in the future. It counts from the arrive of b 10 seconds.

Every

• A
  • Fire when A is encountered and then stop
  • every A
  • Fire when A is encountered and do not stop
  • every(A -> B)
  • Detect an event A followed by an event B: at the time when B occurs, the pattern matches and restarts looking for the next A event
  • every A -> B
  • The pattern fires for every A followed by a B event
  • A -> every B
  • The pattern fires for an A event followed by every B event
  • every A -> every B
  • The pattern fires for every A event followed by every B event

Pattern Guards

  • and not