Package: lisbon
lisbonlisbonaims to be a drop-in replacement forliblinearwhichscikit-learnleaverages for linear classification problems, currently only supports L2-regularised hinge loss for binary classification by solving the dual problem (routine 3). The APIs followscikit-learn'sliblinearwrapper and importing the Python library will monkey-patchscikit-learn's svm library to uselisbonfor the supported calculation.fromsklearnimportsvmimportlisbonand the following computations will uselisbonif supported. To switch backlisbon.unload()will swap back the original fit function.Please seelisbon/__init__.pyto see how the runtime patching is done andbench.pyfor an example.Install from sourceif your platform does not supportAVX2instruction set as the PyPI packaged version assumesAVX2support.InstallationInstall from PyPIpip install lisbonInstall from sourceMake sure you have the Rust toolchainrustc,cargo,rust-stdinstalled. The quickest way to do it iscurl https://sh.rustup.rs -sSf | sh -sFor a minimal installation:curl https://sh.rustup.rs -sSf | sh -s -- --profile minimalWith your desired Python environment,pip install maturinClone this repository and fromlisbon's project root, runRUSTFLAGS='-C target-cpu=native' maturin develop --releasewill installlisbonas a package to your Python environmentNote that theRUSTFLAGS='-C target-cpu=native'environmental variable ensures that rustc compiles against your CPU's supported instruction sets to enable more SIMD optimisations (e.g. AVX2, FMA).For dev/benchmark purposes, consider installing the packages listed inrequirements-dev.txtFor WindowsTo set the rustc flags on windows with powershell:$Env:RUSTFLAGS="-C target-cpu=native"maturindevelop--releaseLimitationslisbon's speed up comes from vector instruction sets hence some platforms are not supported if not built from source.Currently,lisbononly supports L2 regularised hinge loss and does not supportsample weightsclass weightsdifferent penaltyCfor labelsmulticlass classificationDeviations from the source implementationAs withscikit-learn's modification, the order of labels are flipped to be consistent with the rest of thescikit-learnfamilyliblinearuses [+1, -1] orderingscikit-learnuses [-1, +1] orderingUses a MT19937 + tweaked Lemire post-processor to generate a random number within rangeWhy is lisbon fasterliblinearuses sparse matrix representation for the dot/norm operations, soscikit-learnneeds to convert the dense numpy matrix to sparse first then pass to liblinear.lisbonuses the dense matrix directly as sparse represented data can be inefficient and prevents some SIMD optimisations.By reading the numpy C array directly underneath there’s no need to copy/duplicate data which saves memory.Specialised. Some array reads and computations are optimised away as we know what the values are for the L2-regularised hinge loss binary classification routine.Ref2-normA Dual Coordinate Descent Method for Large-scale Linear SVMLicenseThis project is licensed under either ofApache License, Version 2.0, (LICENSE-APACHEorhttps://www.apache.org/licenses/LICENSE-2.0)MIT license (LICENSE-MITorhttps://opensource.org/licenses/MIT)at your option.ContributionUnless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in lisbon by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions.