duanluan2047 2014-03-17 16:37
浏览 35
已采纳

如何获得趋势线的端点?

I am using this logic:

MYSQL Trendline calculation

to calculate the slope of a set of time-series data. But my data is such (measuring current output over time) that the 'slope' makes no sense as it is dependent on the relative scale of the axes. For example current shown in milliamps would produce a different slope than current represented in Amps over the same time period. What I need is to calculate whether the trend over the specified time represents a certain percentage increase.

To summarize, I am using this sql query:

    SELECT COUNT(*) AS N,SUM(UNIX_TIMESTAMP(timestamp)) AS Sum_X,
        SUM(UNIX_TIMESTAMP(timestamp) * UNIX_TIMESTAMP(timestamp)) AS Sum_X2,
        SUM(max_current) AS Sum_Y,
        SUM(max_current*max_current) AS Sum_Y2,
        SUM(UNIX_TIMESTAMP(timestamp) * max_current) AS Sum_XY
        FROM circuit_history
        WHERE circuit_filename = '".$cfn."'
        AND timestamp > date_sub(now(), interval 60 day)";

And my slope is calculated thusly:

$slope = ($row['N'] * $row['Sum_XY'] - $row['Sum_X'] * $row['Sum_Y'])/($row['N'] * $row['Sum_X2'] - $row['Sum_X'] * $row['Sum_X']);

But I am getting numbers like 5.9808374081288E-10 because of the scale of the unix timestamps.

What is the best way to get from this to a percentage increase or decrease? Or more specifically, how do I get the Y values from the endpoints of the trendline?

  • 写回答

1条回答 默认 最新

  • dongyin2643 2014-03-17 16:42
    关注
    1. Want to change your scale from Amps/Time to MilliAmps/Time? Multiply by 1000
    2. Trouble with Unix timestamp? Because your timescale reaches back to Jan 1, 1970. Pick a timestamp as your 'zero' time and subtract it from all of the others.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效