lantianzz / scorecard-bundle Goto Github PK
View Code? Open in Web Editor NEWA High-level Scorecard Modeling API | 评分卡建模尽在于此
Home Page: https://scorecard-bundle.bubu.blue/
License: BSD 3-Clause "New" or "Revised" License
A High-level Scorecard Modeling API | 评分卡建模尽在于此
Home Page: https://scorecard-bundle.bubu.blue/
License: BSD 3-Clause "New" or "Revised" License
the usage of np.quantile is not correct, you may use np.percentile or df[x].quantile
如题,有缺失值的变量运行就会出错
评分卡ChiMerge的时候,存在结果中不包含inf档位的情况。
hello,作者好!
我遇到一种情况是训练集上得到的特征离散化区间,在测试集上找不到对应的值,出现keyerror:450~inf错误。追查到错误后,我在LogisticRegressionScoreCard.py源代码上做了简单粗暴的修改:
def map_np(array, dictionary):
"""map function for numpy array
Parameters
----------
array: numpy.array, shape (number of examples,)
The array of data to map values to.
distionary: dict
The distionary object.
Return
----------
result: numpy.array, shape (number of examples,)
The mapped result.
"""
result = []
for e in array:
try:
result.append(dictionary[e])
except:
result.append(0)
# return [dictionary[e] for e in array]
return result
测试可以跑通,奇怪的是看一个变量的离散化区间范围正无穷到负无穷,不会出现区间值找不到的情况,是不是训练集上该区间没有得到这个值?
最后,感谢写出这个实用的库!
it's because np.quantilehas problem. Quantile function determines boundary by (a+b)/2, but (a+np.Inf)/2 equals np.NaN
codes below can solve the problem.
boundaries = np.unique(
np.quantile(x, np.arange(0, 1, 1/initial_intervals)[1:])
) # Add [1:] so that 0% persentile will not be a threshold
boundaries=boundaries[~np.isnan(boundaries)]
if np.Inf in x:
boundaries=np.append(boundaries,np.Inf)
if np.NINF in x:
boundaries=np.append(boundaries,np.NINF)
boundaries.sort(axis=0)
codes below is calculated in every while loop, and takes too much time.
intervals, unique_intervals = assign_interval_unique(x, unique_intervals[:, 1])
pt_value, pt_column, pt_index = pivot_table_np(intervals[:, 1], y)
In my situation, original code takes 10m to calculate one feature. After optimazation, it takes about 10s.
in first loop, defines df:
df = pd.DataFrame(pt_value, columns=pt_column)
df['pt_index'] = pt_index
df['chi2'] = np.append(chi2_array, [np.NaN] * (m - 1))
in other loops, adjust df, and adjust intermediate variable:
```
merge_index_start=index_adjacent_to_merge[0]
# print(df.loc[merge_index_start:merge_index_start+m-1, :].sum(axis=0).to_frame())
df=pd.concat(
[
df.loc[:merge_index_start-1,:],
df.loc[merge_index_start:merge_index_start+m-1, :].sum(axis=0).to_frame().T,
df.loc[merge_index_start+ m:, :],
],
ignore_index=True
)
# print(df)
df.loc[merge_index_start:merge_index_start , 'pt_index']=new_interval[0][1]
pt_value = df[pt_column].to_numpy()
pt_index = df['pt_index'].to_numpy()
boundaries_tmp = np.unique(
np.concatenate((np.array([-float('inf')]),
df['pt_index'].to_numpy(), np.array([float('inf')])),
axis=0))
boundaries_tmp.sort()
unique_intervals=np.array([[boundaries_tmp[i],boundaries_tmp[i+1]] for i in range(len(boundaries_tmp)-1)])
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.