前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Github 项目推荐 | 用 Python 实现的大规模线性回归、分类和排名库 —— lightning

Github 项目推荐 | 用 Python 实现的大规模线性回归、分类和排名库 —— lightning

作者头像
AI研习社
发布2018-07-26 10:54:47
8280
发布2018-07-26 10:54:47
举报
文章被收录于专栏:AI研习社

Lightning 是大规模线性回归、分类、排名的 Python 库。

Highlights:

  • 遵循 scikit-learn API 约定(http://scikit-learn.org/)
  • 本地支持密集和稀疏数据表示
  • 在 Cython 中实现的计算要求较高的部分

Solvers supported:

  • 原始坐标下降
  • 双坐标下降 (SDCA,Prox-SDCA)
  • SGD,AdaGrad,SAG,SAGA,SVRG
  • FISTA

示例

该示例展示了如何在 News20 数据集中学习具有组套索惩罚的多类分类器。

代码语言:javascript
复制
from sklearn.datasets import fetch_20newsgroups_vectorized
from lightning.classification import CDClassifier

# Load News20 dataset from scikit-learn.
bunch = fetch_20newsgroups_vectorized(subset="all")
X = bunch.data
y = bunch.target

# Set classifier options.
clf = CDClassifier(penalty="l1/l2",
                   loss="squared_hinge",
                   multiclass=True,
                   max_iter=20,
                   alpha=1e-4,
                   C=1.0 / X.shape[0],
                   tol=1e-3)

# Train the model.
clf.fit(X, y)

# Accuracy
print(clf.score(X, y))

# Percentage of selected features
print(clf.n_nonzero(percentage=True))

依赖

  • Python >= 2.7
  • Numpy >= 1.3
  • SciPy >= 0.7
  • scikit-learn >= 0.15
  • 从源代码构建还需要 Cython 和一个可用的 C / C ++ 编译器
  • 要运行测试,nose >= 0.10

安装

Lightning 稳定版本的预编译二进制文件在主要平台可用,需要用 pip 安装:

代码语言:javascript
复制
pip install sklearn-contrib-lightning

或者用 conda:

代码语言:javascript
复制
conda install -c conda-forge sklearn-contrib-lightning

开发版本的 Lightning 可以从 git 库上安装。在这种情况下,假设你拥有 git 版本控制系统,一个可用的 C ++ 编译器,Cython 和 numpy 开发库,然后输入:

代码语言:javascript
复制
git clone https://github.com/scikit-learn-contrib/lightning.git
cd lightning
python setup.py build
sudo python setup.py install

文档

http://contrib.scikit-learn.org/lightning/

Github

https://github.com/scikit-learn-contrib/lightning

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2018-05-17,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 AI研习社 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 示例
  • 依赖
  • 安装
  • 文档
  • Github
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档