Lightning: Easily Train and Deploy Large-Scale Linear Models in Python


lightning is a library for large-scale linear classification, regression and ranking in Python.


  • follows the scikit-learn API conventions
  • supports natively both dense and sparse data representations
  • computationally demanding parts implemented in Cython

Solvers supported:

  • primal coordinate descent
  • dual coordinate descent (SDCA, Prox-SDCA)
  • SGD, AdaGrad, SAG, SAGA, SVRG


Example that shows how to learn a multiclass classifier with group lasso penalty on the News20 dataset (c.f., Blondel et al. 2013):

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 =
y =

# Set classifier options.
clf = CDClassifier(penalty="l1/l2",
                   C=1.0 / X.shape[0],

# Train the model., y)

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

# Percentage of selected features


lightning requires Python >= 3.7, setuptools, Joblib, Numpy >= 1.12, SciPy >= 0.19 and scikit-learn >= 0.19. Building from source also requires Cython and a working C/C++ compiler. To run the tests you will also need pytest.


Precompiled binaries for the stable version of lightning are available for the main platforms and can be installed using pip:

pip install sklearn-contrib-lightning

or conda:

conda install -c conda-forge sklearn-contrib-lightning

The development version of lightning can be installed from its git repository. In this case it is assumed that you have the git version control system, a working C++ compiler, Cython and the numpy development libraries. In order to install the development version, type:

git clone
cd lightning
python install


On GitHub


If you use this software, please cite it. Here is a BibTex snippet that you can use:

  author       = {Blondel, Mathieu and
                  Pedregosa, Fabian},
  title        = {{Lightning: large-scale linear classification,
                 regression and ranking in Python}},
  year         = 2016,
  doi          = {10.5281/zenodo.200504},
  url          = {}

Other citing formats are available in its Zenodo entry.

Download Details:

Author: Scikit-learn-contrib
Source Code: 

#machinelearning #python 

Lightning: Easily Train and Deploy Large-Scale Linear Models in Python
1.05 GEEK