Giter Site home page Giter Site logo

Change cat-binning about woe_scoring HOT 2 CLOSED

kiraplenkin avatar kiraplenkin commented on July 16, 2024
Change cat-binning

from woe_scoring.

Comments (2)

kiraplenkin avatar kiraplenkin commented on July 16, 2024

`bins = list([bin] for bin in np.unique(X[~pd.isna(X)]))

if len(bins) > max_bins:
    bad_rates_dict = dict(sorted({bins[i][0]: y[np.isin(X, bins[i])].sum() / len(y[np.isin(X, bins[i])]) for i in
                                  range(len(bins))}.items(), key=lambda item: item[1]))
    bad_rate_list = [bad_rates_dict[i] for i in bad_rates_dict]
    q_list = [0.0]
    for quantile in range(1, max_bins):
        q_list.append(
            np.nanquantile(np.array(bad_rate_list), quantile / max_bins, axis=0)
        )
    q_list.append(1)
    q_list = list(sorted(set(q_list)))

    new_bins = [copy.deepcopy([list(bad_rates_dict.keys())[0]])]
    start = 1
    for i in range(len(q_list) - 1):
        for n in range(start, len(list(bad_rates_dict.keys()))):
            if (bad_rate_list[n] >= q_list[i]) & (
                    bad_rate_list[n] < q_list[i + 1]
            ):
                try:
                    new_bins[i] += [list(bad_rates_dict.keys())[n]]
                    start += 1
                except IndexError:
                    new_bins.append([])
                    new_bins[i] += [list(bad_rates_dict.keys())[n]]
                    start += 1

    bad_rates, _ = bin_bad_rate(X, y, new_bins, cat=True)
    bins = [bad_rate["bin"] for bad_rate in bad_rates]
else:
    bad_rates, _ = bin_bad_rate(X, y, bins, cat=True)`

from woe_scoring.

kiraplenkin avatar kiraplenkin commented on July 16, 2024

#15

from woe_scoring.

Related Issues (20)

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.