简体   繁体   English

Azure流分析-计算线性回归

[英]Azure Stream Analytics - Calculate Linear Regression

I am trying to calculate some linear regression with Azure Stream Analytics. 我正在尝试使用Azure Stream Analytics计算一些线性回归。

The Setup: There is a Sensor sending temperature and time to an IoT-Hub, the Stream-Analytics is listening to the IoT-Hub with a SlidingWindow and should calculate the trend of the temperature in this window (with linear regression). 设置:有一个传感器向IoT中心发送温度和时间,Stream-Analytics使用SlidingWindow监听IoT中心,并应在此窗口中计算温度趋势(线性回归)。

An event looks like this: 一个事件如下所示:

{"deviceId":"sensor_1","temp":322.3376736446427,"time":1517500183940}

The SQL I got so far is this: 到目前为止,我得到的SQL是:

WITH Step1 AS
(
select time AS x, avg(time) over () AS x_bar,
       temp AS y, avg(temp) over () AS y_bar
FROM inputStream
GROUP BY SlidingWindow(second,10) 
),
Step2 AS (
    SELECT (sum((x - x_bar) * (y - y_bar)) / sum((x - x_bar) * (x - x_bar))) AS slope,
           max(x_bar) AS x_bar_max,
           max(y_bar) AS y_bar_max    
    FROM Step1
),
FinalStep AS (
    SELECT  slope, 
            y_bar_max - x_bar_max * slope AS intercept
    FROM Step2
)

SELECT * INTO outputEventHub FROM FinalStep

The original Linear Regression SQL-Template from here looked like this: 原来的线性回归SQL-模板从这里是这样的:

select slope, 
       y_bar_max - x_bar_max * slope as intercept 
from (
    select sum((x - x_bar) * (y - y_bar)) / sum((x - x_bar) * (x - x_bar)) as slope,
           max(x_bar) as x_bar_max,
           max(y_bar) as y_bar_max    
    from (
        select x, avg(x) over () as x_bar,
               y, avg(y) over () as y_bar
        from ols) s;
) 

If you know some better way to do this without Stream Analytics I am also fine. 如果您知道一些无需Stream Analytics的更好方法,也可以。 Please share your thoughts and thanks in advance! 请事先分享您的想法和感谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM