在MySQL(5.1)数据库表中,有数据表示:
MySQL会支持关联数据还是需要使用PHP/C#来计算?
我在哪里可以找到计算相关性的好公式(自从我上次这样做以来已经很长时间了)?
Mar*_*tin 15
以下是样本相关系数的粗略实现,如下所述:
create table sample( x float not null, y float not null );
insert into sample values (1, 10), (2, 4), (3, 5), (6,17);
select @ax := avg(x),
@ay := avg(y),
@div := (stddev_samp(x) * stddev_samp(y))
from sample;
select sum( ( x - @ax ) * (y - @ay) ) / ((count(x) -1) * @div) from sample;
+---------------------------------------------------------+
| sum( ( x - @ax ) * (y - @ay) ) / ((count(x) -1) * @div) |
+---------------------------------------------------------+
| 0.700885077729073 |
+---------------------------------------------------------+
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11983 次 |
| 最近记录: |