跳转到主要内容

Python的Distance Weighted Discrimination

项目描述

概述

此软件包实现了距离加权判别(DWD)。关于DWD的详细信息,请参阅(Marron et al 2007Wang and Zou 2018)。最初由Iain Carmichael在Python中实现。目前由Kitware, Inc维护。

该软件包目前实现了

  • 使用二次锥规划(SOCP)解决的原始DWD公式,并使用cvxpy解决。

  • 广义DWD(gDWD)和核gDWD使用Wang和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.

安装

DWD软件包可以通过pip或GitHub安装。该软件包目前仅在python 3.6上进行了测试。

$ pip install dwd

锥形求解器 socp_dwd.DWD 依赖于 cvxpy,它并非所有平台都可用。请参阅cvxpy 安装说明。如果满足 cvxpy 依赖项,则使用 pip install dwd[socp]

Flit用于打包,所有包元数据都存储在pyproject.toml中。要本地安装或开发此项目,请使用flit install或使用flit build构建一个pip可安装的wheel。

示例

from sklearn.datasets import make_blobs
from dwd.socp_dwd import DWD

# 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

dwd_sep_hyperplane

from sklearn.datasets import make_circles
from dwd.gen_kern_dwd import KernGDWD

# 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

kern_dwd

更多示例代码请参阅这些示例笔记本(包括生成上述图表的代码)。如果GitHub上的笔记本无法加载,您可以将笔记本URL复制/粘贴到https://nbviewer.jupyter.org/

帮助和支持

更多文档、示例和代码修订即将推出。

文档

源代码位于GitHub上:https://github.com/slicersalt/dwd

测试

使用nose进行测试。

贡献

我们欢迎贡献,以使这个包更强大:数据示例、错误修复、拼写错误、新功能等。

由以下支持