Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SLOPE函数实现了这个功能了么 #30

Open
985153073 opened this issue Dec 5, 2018 · 2 comments
Open

SLOPE函数实现了这个功能了么 #30

985153073 opened this issue Dec 5, 2018 · 2 comments

Comments

@985153073
Copy link

SLOPE函数实现了这个功能了么

@OwlWinter
Copy link

+1,希望可以实现 slope 函数

@jones2000
Copy link

我的HQChart里面有SLOPE实现, 希望能帮到你。
py文件代码

`# SLOPE 线性回归斜率
# SLOPE(X,N)  返回线性回归斜率。
def SLOPE(self,data,n) :
if not JSAlgorithm.IsVaildArray(data) :
return []

    dataLen=len(data)
    if n<1 or n>=dataLen :
        return []
    
    result=JSAlgorithm.CreateArray(dataLen)
    for start in range(dataLen) :
        if JSAlgorithm.IsNumber(data[start]) :
            break

    for i in range(start+n-1,dataLen) :
        x, y, xy, xx = 0,0,0,0
        for j in range(n) :
            if j>i: 
                break
            x+=(i-j)       # 数据索引相加
            y+=data[i-j]   # 数据相加

        x=x/n
        y=y/n

        for j in range(n) :
            if j>i :
                break
            xy+=(i-j-x)*(data[i-j]-y)
            xx+=(i-j-x)*(i-j-x)

        if xx :
            result[i]= xy/xx
        elif i :
            result[i]=result[i-1]

    return result`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants