Closed Lindababybaby closed 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 感谢回复,floor (-2.3) = -3 trunc (-2.3)= -2 ,我比较了Pyrthon 和R 版的Scorecard 包 两个软件的分箱结果差异较大,定位到了原因,就是 和R 的pretty 方法比,python 里的pretty 函数 中 的如上问题,谢谢!
挺好,我回头改改,谢谢
def pretty(low, high, n): ''' pretty breakpoints, the same as pretty function in R
@ShichenXie