Skip to main content

Vowpal Wabbit Python package

Project description

PyPI Package Build Status Windows Build Status Coverage

Vowpal Wabbit is a fast machine learning library for online learning, and this is the python wrapper for the project.

Installing this package builds Vowpal Wabbit locally for explicit use within python, it will not create the command-line version of the tool (or affect any previously existing command-line installations). To install the command-line version see the main project page: https://github.com/VowpalWabbit/vowpal_wabbit

The version of the PyPI vowpalwabbit package corresponds to the tagged version of the code in the github repo that will be used during building and installation. If you need to make local changes to the code and rebuild the python binding be sure to pip uninstall vowpalwabbit then rebuild using the local repo installation instructions below.

Installation

From PyPI:

Linux/Mac OSX:

$ pip install vowpalwabbit

Windows:

> pip install --global-option="--vcpkg-root=path\to\vcpkg" vowpalwabbit

From local repo (useful when making modifications):

# Dependencies
$ sudo apt install libboost-dev libboost-program-options-dev libboost-system-dev libboost-thread-dev libboost-math-dev libboost-test-dev libboost-python-dev zlib1g-dev cmake

# Build and install package
$ python setup.py install

Usage

You can use the python wrapper directly like this:

>>> from vowpalwabbit import pyvw
>>> vw = pyvw.vw(quiet=True)
>>> ex = vw.example('1 | a b c')
>>> vw.learn(ex)
>>> vw.predict(ex)

Or you can use the included scikit-learn interface like this:

>>> import numpy as np
>>> from sklearn import datasets
>>> from sklearn.model_selection import train_test_split
>>> from vowpalwabbit.sklearn_vw import VWClassifier
>>>
>>> # generate some data
>>> X, y = datasets.make_hastie_10_2(n_samples=10000, random_state=1)
>>> X = X.astype(np.float32)
>>>
>>> # split train and test set
>>> X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=256)
>>>
>>> # build model
>>> model = VWClassifier()
>>> model.fit(X_train, y_train)
>>>
>>> # predict model
>>> y_pred = model.predict(X_test)
>>>
>>> # evaluate model
>>> model.score(X_train, y_train)
>>> model.score(X_test, y_test)

Troubleshooting

Some common causes of failure for installation are due to missing or mis-matched dependencies when Vowpal Wabbit builds. Make sure you have boost and boost-python installed on your system.

For Ubuntu/Debian/Mint

$ apt install libboost-dev libboost-program-options-dev libboost-system-dev libboost-thread-dev libboost-math-dev libboost-test-dev libboost-python-dev zlib1g-dev cmake

For Mac OSX

$ brew install cmake
$ brew install boost
#If you want to build with python 2 support
brew install boost-python
#If you want to build with python 3 support
brew install boost-python3

For Windows

  1. Install vcpkg

  2. Run

> vcpkg --triplet x64-windows install zlib boost-system boost-program-options boost-test boost-align boost-foreach boost-python boost-math boost-thread python3 boost-python

Installing Vowpal Wabbit under an Anaconda environment (on OSX or Linux) can be done using the following steps:

$ git clone https://github.com/VowpalWabbit/vowpal_wabbit.git
# create conda environment if necessary
$ conda create -n vowpalwabbit
$ source activate vowpalwabbit
# install necessary boost dependencies
$ conda install -y -c anaconda boost
$ pip install -e vowpal_wabbit/python

For python3 on Ubuntu 16.04 LTS: Ubuntu 16.04 defaults to an old, custom-built version of boost. As such, the boost_python library names do not follow the standard naming convention adopted by offical boost releases for the boost_python libraries. You may need to manually create the relevant symlinks in this case. Example commands for python 3.5 follows:

$ cd /usr/lib/x86_64-linux-gnu/
$ sudo ln -s libboost_python-py35.so libboost_python3.so
$ sudo ln -s libboost_python-py35.a libboost_python3.a

Development

Contributions are welcome for improving the python wrapper to Vowpal Wabbit.

  1. Check for open issues or create one to discuss a feature idea or bug.

  2. Fork the repo on Github and make changes to the master branch (or a new branch off of master).

  3. Write a test in the python/tests folder showing the bug was fixed or feature works (recommend using pytest).

  4. Make sure package installs and tests pass under all supported environments (this calls tox automatically).

  5. Send the pull request.

Tests can be run using setup.py:

$ python setup.py test

Directory Structure:

  • python : this is where the c++ extension lives

  • python/vowpalwabbit : this is then main directory for python wrapper code and utilities

  • python/examples : example python code and jupyter notebooks to demonstrate functionality

  • python/tests : contains all tests for python code

Note: neither examples nor tests directories are included in the distributed package, they are only for development purposes.

Experimental build for Windows

An extension on the experimental Windows CMake build for the main project.

Note: attempting to install boost-python in vcpkg while multiple python versions are installed in vcpkg will cause errors. Ensure only the relevant python version is installed in the environment before proceeding.

Python3

  1. install required vcpkgs

> vcpkg install python3:x64-windows
> vcpkg install boost-python:x64-windows
  1. Run

> python setup.py --vcpkg-root=path\to\vcpkg install

Python2

Due to limitations in the current version of boost-python, some manual changes must be made to the vcpkg tools

  1. Edit [vcpkg-root]\ports\boost-python

  2. Edit the file CONTROL
    1. Change the Build-Depends entry for python3 to python2

  3. install required vcpkgs

> vcpkg install python2:x64-windows
> vcpkg install boost-python:x64-windows
  1. Run

> python setup.py --vcpkg-root=path\to\vcpkg install

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

vowpalwabbit-8.7.0.post1.tar.gz (3.1 MB view details)

Uploaded Source

Built Distributions

vowpalwabbit-8.7.0.post1-cp37-cp37m-win_amd64.whl (3.0 MB view details)

Uploaded CPython 3.7mWindows x86-64

vowpalwabbit-8.7.0.post1-cp36-cp36m-win_amd64.whl (2.9 MB view details)

Uploaded CPython 3.6mWindows x86-64

File details

Details for the file vowpalwabbit-8.7.0.post1.tar.gz.

File metadata

  • Download URL: vowpalwabbit-8.7.0.post1.tar.gz
  • Upload date:
  • Size: 3.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.1 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for vowpalwabbit-8.7.0.post1.tar.gz
Algorithm Hash digest
SHA256 de9529660858b380127b2bea335b41a29e8f264551315042300022eb4e6524ea
MD5 40b38cbf4cf2a0ea926275b98bce1243
BLAKE2b-256 f40950efc9630809fdd19056d2fff8e7b8e374063002b5a70b016854fe5e8492

See more details on using hashes here.

File details

Details for the file vowpalwabbit-8.7.0.post1-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: vowpalwabbit-8.7.0.post1-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 3.0 MB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.1 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for vowpalwabbit-8.7.0.post1-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 978732b8eeb63ff5bc40c432b523e5a16c26f6b24915e3de1e465c8ef93f9fdb
MD5 3ac13aefcaa6141d71afdf1fe1df5a35
BLAKE2b-256 bd6d228da743c5498405068f4f05040d75f96ed6a0665328ad8d59ff145a14c4

See more details on using hashes here.

File details

Details for the file vowpalwabbit-8.7.0.post1-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: vowpalwabbit-8.7.0.post1-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 2.9 MB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.1 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for vowpalwabbit-8.7.0.post1-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 2d920087c4fbc95eca61b3bc8e93362006205010676bd670ad7eaec40cfe469d
MD5 73ff52f3eb00dd1317888e232181c19e
BLAKE2b-256 82aba230de319cd4b721d1ed30fa432732279612a2b959488728a40367a24dd9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page