Skip to main content

Distance Weighted Discrimination for Python

Project description

Overview

This package implements Distance Weighted Discrimination (DWD). DWD For details see (Marron et al 2007, Wang and Zou 2018). Originally implemented in Python by Iain Carmichael. Currently maintained by Kitware, Inc.

The package currently implements:

  • Original DWD formulation solved with Second Order Cone Programming (SOCP) and solved using cvxpy.

  • Genralized DWD (gDWD) and kernel gDWD solved with the Majorization-Minimization algorithm presented in Wang and Zou, 2018.

Marron, James Stephen, Michael J. Todd, and Jeongyoun Ahn. “Distance-weighted discrimination.” Journal of the American Statistical Association 102, no. 480 (2007): 1267-1271.

Wang, Boxiang, and Hui Zou. “Another look at distance‐weighted discrimination.” Journal of the Royal Statistical Society: Series B (Statistical Methodology) 80, no. 1 (2018): 177-198.

Installation

The DWD package can be installed via pip or github. This package is currently only tested in python 3.6.

pip install dwd
git clone https://github.com/idc9/dwd.git
python setup.py install

Example

from sklearn.datasets import make_blobs, make_circles
from dwd import DWD, KernGDWD

# sample sythetic training data
X, y = make_blobs(n_samples=200, n_features=2,
                  centers=[[0, 0],
                           [2, 2]])

# fit DWD classifier
dwd = DWD(C='auto').fit(X, y)

# compute training accuracy
dwd.score(X, y)

0.94
https://raw.githubusercontent.com/slicersalt/dwd/master/doc/figures/dwd_sep_hyperplane.png
# sample some non-linear, toy data
X, y = make_circles(n_samples=200, noise=0.2, factor=0.5, random_state=1)

# fit kernel DWD wit gaussian kernel
kdwd = KernGDWD(lambd=.1, kernel='rbf',
                kernel_kws={'gamma': 1}).fit(X, y)

# compute training accuracy
kdwd.score(X, y)

0.915
https://raw.githubusercontent.com/slicersalt/dwd/master/doc/figures/kern_dwd.png

For more example code see these example notebooks (including the code to generate the above figures). If the notebooks aren’t loading on github you can copy/paste the notebook url into https://nbviewer.jupyter.org/.

Help and Support

Additional documentation, examples and code revisions are coming soon.

Documentation

The source code is located on github: https://github.com/slicersalt/dwd

Testing

Testing is done using nose.

Contributing

We welcome contributions to make this a stronger package: data examples, bug fixes, spelling errors, new features, etc.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dwd-1.0.0.tar.gz (210.5 kB view details)

Uploaded Source

Built Distribution

dwd-1.0.0-py3-none-any.whl (21.5 kB view details)

Uploaded Python 3

File details

Details for the file dwd-1.0.0.tar.gz.

File metadata

  • Download URL: dwd-1.0.0.tar.gz
  • Upload date:
  • Size: 210.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.25.1

File hashes

Hashes for dwd-1.0.0.tar.gz
Algorithm Hash digest
SHA256 91ec1a42fb55ea9ba874bf3d482141778598d18340e324335872116925ec72b5
MD5 523731fa780959b4eafbff19b0b7fc75
BLAKE2b-256 e7d6eccf40e2838ed7588d0d4ab5f3e4d7be3daf4df97b0782b673f045c08468

See more details on using hashes here.

File details

Details for the file dwd-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: dwd-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 21.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.25.1

File hashes

Hashes for dwd-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 96fe9dfb323f3d81fa6549f7721309831f94c465476802445806b8af38141676
MD5 8c154eaee775aab2a958636a51ae7812
BLAKE2b-256 866029688acf9f75514a9e572bb9e11f031ba69a51088df9803f79124463636c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page