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
Flit is used for packaging, and all package metadata is stored in pyproject.toml
. To install this project locally or for development, use flit install
or build a pip-installable wheel with flit build
.
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
# 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
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
Built Distribution
File details
Details for the file dwd-1.0.2.tar.gz
.
File metadata
- Download URL: dwd-1.0.2.tar.gz
- Upload date:
- Size: 211.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.25.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f178597cdb5ff79ce3b9663ae011749c3ccf90f8f5714396d6199f9cd1f4489 |
|
MD5 | dc132267fe750dbd5fb39d2d6f23cc4d |
|
BLAKE2b-256 | 370c07b5c0673701089ad56a1607e36d764c4d070a2967fd787ff4af6f0b1e19 |
File details
Details for the file dwd-1.0.2-py3-none-any.whl
.
File metadata
- Download URL: dwd-1.0.2-py3-none-any.whl
- Upload date:
- Size: 22.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.25.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbbfef629f609ebab47da010c312a67bb51d9ce3312f41ee1d50c292832335c5 |
|
MD5 | 0ecc7659e150b5e407eb53c85b66e0b9 |
|
BLAKE2b-256 | d47bd6ae2f7cd26ad361f4ab8f6dbf7b7901b29a502ec341706c7d7243fb0d6f |