ShichenXie / scorecardpy

Scorecard Development in python, 评分卡
http://shichen.name/scorecard
MIT License
725 stars 301 forks source link

谢老师好,请问 下文中 pretty 函数bug? exp = np.trunc(np.log10(abs(x))) 中的trunc是不是应该改为floor? #81

Closed Lindababybaby closed 3 years ago

Lindababybaby commented 3 years ago

def pretty(low, high, n): ''' pretty breakpoints, the same as pretty function in R

Params
------
low: minimal value 
low: maximal value 
n: number of intervals

Returns
------
numpy.ndarray
    returns a breakpoints array
'''
# nicenumber
def nicenumber(x):
    exp = np.trunc(np.log10(abs(x)))
    f   = abs(x) / 10**exp
    if f < 1.5:
        nf = 1.
    elif f < 3.:
        nf = 2.
    elif f < 7.:
        nf = 5.
    else:
        nf = 10.
    return np.sign(x) * nf * 10.**exp
# pretty breakpoints
d     = abs(nicenumber((high-low)/(n-1)))
miny  = np.floor(low  / d) * d
maxy  = np.ceil (high / d) * d
return np.arange(miny, maxy+0.5*d, d)

@ShichenXie

ShichenXie commented 3 years ago

这两有啥区别

Lindababybaby commented 3 years ago

这两有啥区别

@ShichenXie 感谢回复,floor (-2.3) = -3 trunc (-2.3)= -2 ,我比较了Pyrthon 和R 版的Scorecard 包 两个软件的分箱结果差异较大,定位到了原因,就是 和R 的pretty 方法比,python 里的pretty 函数 中 的如上问题,谢谢!

ShichenXie commented 3 years ago

挺好,我回头改改,谢谢