scorecardpy


Namescorecardpy JSON
Version 0.1.9.7 PyPI version JSON
download
home_pagehttp://github.com/shichenxie/scorecardpy
SummaryCredit Risk Scorecard
upload_time2023-07-29 15:24:14
maintainer
docs_urlNone
authorShichen Xie
requires_python
license
keywords credit scorecard woe binning performace evaluation
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # scorecardpy

[![PyPI version](https://img.shields.io/pypi/pyversions/scorecardpy.svg)](https://pypi.python.org/pypi/scorecardpy)
[![PyPI release](https://img.shields.io/pypi/v/scorecardpy.svg)](https://pypi.python.org/pypi/scorecardpy)
[![Downloads](http://pepy.tech/badge/scorecardpy)](http://pepy.tech/project/scorecardpy)
[![Downloads](https://pepy.tech/badge/scorecardpy/month)](https://pepy.tech/project/scorecardpy/month)


This package is python version of R package [scorecard](https://github.com/ShichenXie/scorecard). 
Its goal is to make the development of traditional credit risk scorecard model easier and efficient by providing functions for some common tasks. 
- data partition (`split_df`)
- variable selection (`iv`, `var_filter`)
- weight of evidence (woe) binning (`woebin`, `woebin_plot`, `woebin_adj`, `woebin_ply`)
- scorecard scaling (`scorecard`, `scorecard_ply`)
- performance evaluation (`perf_eva`, `perf_psi`)

## Installation

- Install the release version of `scorecardpy` from [PYPI](https://pypi.org/project/scorecardpy/) with:
```
pip install scorecardpy
```

- Install the latest version of `scorecardpy` from [github](https://github.com/shichenxie/scorecardpy) with:
```
pip install git+git://github.com/shichenxie/scorecardpy.git
```

## Example

This is a basic example which shows you how to develop a common credit risk scorecard:

``` python
# Traditional Credit Scoring Using Logistic Regression
import scorecardpy as sc

# data prepare ------
# load germancredit data
dat = sc.germancredit()

# filter variable via missing rate, iv, identical value rate
dt_s = sc.var_filter(dat, y="creditability")

# breaking dt into train and test
train, test = sc.split_df(dt_s, 'creditability').values()

# woe binning ------
bins = sc.woebin(dt_s, y="creditability")
# sc.woebin_plot(bins)

# binning adjustment
# # adjust breaks interactively
# breaks_adj = sc.woebin_adj(dt_s, "creditability", bins) 
# # or specify breaks manually
breaks_adj = {
    'age.in.years': [26, 35, 40],
    'other.debtors.or.guarantors': ["none", "co-applicant%,%guarantor"]
}
bins_adj = sc.woebin(dt_s, y="creditability", breaks_list=breaks_adj)

# converting train and test into woe values
train_woe = sc.woebin_ply(train, bins_adj)
test_woe = sc.woebin_ply(test, bins_adj)

y_train = train_woe.loc[:,'creditability']
X_train = train_woe.loc[:,train_woe.columns != 'creditability']
y_test = test_woe.loc[:,'creditability']
X_test = test_woe.loc[:,train_woe.columns != 'creditability']

# logistic regression ------
from sklearn.linear_model import LogisticRegression
lr = LogisticRegression(penalty='l1', C=0.9, solver='saga', n_jobs=-1)
lr.fit(X_train, y_train)
# lr.coef_
# lr.intercept_

# predicted proability
train_pred = lr.predict_proba(X_train)[:,1]
test_pred = lr.predict_proba(X_test)[:,1]

# performance ks & roc ------
train_perf = sc.perf_eva(y_train, train_pred, title = "train")
test_perf = sc.perf_eva(y_test, test_pred, title = "test")

# score ------
card = sc.scorecard(bins_adj, lr, X_train.columns)
# credit score
train_score = sc.scorecard_ply(train, card, print_step=0)
test_score = sc.scorecard_ply(test, card, print_step=0)

# psi
sc.perf_psi(
  score = {'train':train_score, 'test':test_score},
  label = {'train':y_train, 'test':y_test}
)
```

            

Raw data

            {
    "_id": null,
    "home_page": "http://github.com/shichenxie/scorecardpy",
    "name": "scorecardpy",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "credit scorecard,woe binning,performace evaluation",
    "author": "Shichen Xie",
    "author_email": "xie@shichen.name",
    "download_url": "https://files.pythonhosted.org/packages/56/5a/7bae50d0875192a86d2153535fa221596c9f0c83b86dd7c25b005aa37de9/scorecardpy-0.1.9.7.tar.gz",
    "platform": null,
    "description": "# scorecardpy\n\n[![PyPI version](https://img.shields.io/pypi/pyversions/scorecardpy.svg)](https://pypi.python.org/pypi/scorecardpy)\n[![PyPI release](https://img.shields.io/pypi/v/scorecardpy.svg)](https://pypi.python.org/pypi/scorecardpy)\n[![Downloads](http://pepy.tech/badge/scorecardpy)](http://pepy.tech/project/scorecardpy)\n[![Downloads](https://pepy.tech/badge/scorecardpy/month)](https://pepy.tech/project/scorecardpy/month)\n\n\nThis package is python version of R package [scorecard](https://github.com/ShichenXie/scorecard). \nIts goal is to make the development of traditional credit risk scorecard model easier and efficient by providing functions for some common tasks. \n- data partition (`split_df`)\n- variable selection (`iv`, `var_filter`)\n- weight of evidence (woe) binning (`woebin`, `woebin_plot`, `woebin_adj`, `woebin_ply`)\n- scorecard scaling (`scorecard`, `scorecard_ply`)\n- performance evaluation (`perf_eva`, `perf_psi`)\n\n## Installation\n\n- Install the release version of `scorecardpy` from [PYPI](https://pypi.org/project/scorecardpy/) with:\n```\npip install scorecardpy\n```\n\n- Install the latest version of `scorecardpy` from [github](https://github.com/shichenxie/scorecardpy) with:\n```\npip install git+git://github.com/shichenxie/scorecardpy.git\n```\n\n## Example\n\nThis is a basic example which shows you how to develop a common credit risk scorecard:\n\n``` python\n# Traditional Credit Scoring Using Logistic Regression\nimport scorecardpy as sc\n\n# data prepare ------\n# load germancredit data\ndat = sc.germancredit()\n\n# filter variable via missing rate, iv, identical value rate\ndt_s = sc.var_filter(dat, y=\"creditability\")\n\n# breaking dt into train and test\ntrain, test = sc.split_df(dt_s, 'creditability').values()\n\n# woe binning ------\nbins = sc.woebin(dt_s, y=\"creditability\")\n# sc.woebin_plot(bins)\n\n# binning adjustment\n# # adjust breaks interactively\n# breaks_adj = sc.woebin_adj(dt_s, \"creditability\", bins) \n# # or specify breaks manually\nbreaks_adj = {\n    'age.in.years': [26, 35, 40],\n    'other.debtors.or.guarantors': [\"none\", \"co-applicant%,%guarantor\"]\n}\nbins_adj = sc.woebin(dt_s, y=\"creditability\", breaks_list=breaks_adj)\n\n# converting train and test into woe values\ntrain_woe = sc.woebin_ply(train, bins_adj)\ntest_woe = sc.woebin_ply(test, bins_adj)\n\ny_train = train_woe.loc[:,'creditability']\nX_train = train_woe.loc[:,train_woe.columns != 'creditability']\ny_test = test_woe.loc[:,'creditability']\nX_test = test_woe.loc[:,train_woe.columns != 'creditability']\n\n# logistic regression ------\nfrom sklearn.linear_model import LogisticRegression\nlr = LogisticRegression(penalty='l1', C=0.9, solver='saga', n_jobs=-1)\nlr.fit(X_train, y_train)\n# lr.coef_\n# lr.intercept_\n\n# predicted proability\ntrain_pred = lr.predict_proba(X_train)[:,1]\ntest_pred = lr.predict_proba(X_test)[:,1]\n\n# performance ks & roc ------\ntrain_perf = sc.perf_eva(y_train, train_pred, title = \"train\")\ntest_perf = sc.perf_eva(y_test, test_pred, title = \"test\")\n\n# score ------\ncard = sc.scorecard(bins_adj, lr, X_train.columns)\n# credit score\ntrain_score = sc.scorecard_ply(train, card, print_step=0)\ntest_score = sc.scorecard_ply(test, card, print_step=0)\n\n# psi\nsc.perf_psi(\n  score = {'train':train_score, 'test':test_score},\n  label = {'train':y_train, 'test':y_test}\n)\n```\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Credit Risk Scorecard",
    "version": "0.1.9.7",
    "project_urls": {
        "Bug Reports": "https://github.com/shichenxie/scorecardpy/issues",
        "Homepage": "http://github.com/shichenxie/scorecardpy",
        "Source": "https://github.com/shichenxie/scorecardpy/"
    },
    "split_keywords": [
        "credit scorecard",
        "woe binning",
        "performace evaluation"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "565a7bae50d0875192a86d2153535fa221596c9f0c83b86dd7c25b005aa37de9",
                "md5": "459dd45355dad6194debd4b8b317baf7",
                "sha256": "a81c7e6f3bf5f10a87b61af73b25f1fc8bc5acbadf5d9e38c3addb02df128d03"
            },
            "downloads": -1,
            "filename": "scorecardpy-0.1.9.7.tar.gz",
            "has_sig": false,
            "md5_digest": "459dd45355dad6194debd4b8b317baf7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 58129,
            "upload_time": "2023-07-29T15:24:14",
            "upload_time_iso_8601": "2023-07-29T15:24:14.356727Z",
            "url": "https://files.pythonhosted.org/packages/56/5a/7bae50d0875192a86d2153535fa221596c9f0c83b86dd7c25b005aa37de9/scorecardpy-0.1.9.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-29 15:24:14",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "shichenxie",
    "github_project": "scorecardpy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "scorecardpy"
}
        
Elapsed time: 0.34142s