Coder Social home page Coder Social logo

lantianzz / scorecard-bundle Goto Github PK

View Code? Open in Web Editor NEW
74.0 5.0 29.0 5.81 MB

A High-level Scorecard Modeling API | 评分卡建模尽在于此

Home Page: https://scorecard-bundle.bubu.blue/

License: BSD 3-Clause "New" or "Revised" License

Python 100.00%
scorecared feature-discretization woe model-evaluation chimerge credit-scorecard scorecard-bundle

scorecard-bundle's People

Contributors

lantianzz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

scorecard-bundle's Issues

ChiMerge.py

the usage of np.quantile is not correct, you may use np.percentile or df[x].quantile

[Fixed] KeyError due to more extreme values in the test set (某些情况下测试集特征数值比训练集更大会导致KeyError)

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

测试可以跑通,奇怪的是看一个变量的离散化区间范围正无穷到负无穷,不会出现区间值找不到的情况,是不是训练集上该区间没有得到这个值?

最后,感谢写出这个实用的库!

chi_merge_vector can't handle data with np.Inf

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)

chi_merge_vector has redundant calculation.

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)])

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.