Skip to content

Introduction to Lightwood

Lightwood is a Pytorch based framework with two objectives:

  • Make it so simple that you can build predictive models with a line of code.
  • Make it so flexible that you can change and customize everything.

Lightwood was inspired on Keras+Ludwig but runs on Pytorch and gives you full control of what you can do.

Prerequisites

Python >=3.6 64bit version

Installing Lightwood

You can install Lightwood using pip:

pip3 install lightwood

If this fails, please report the bug on github and try installing the current master branch:

git clone git@github.com:mindsdb/lightwood.git;
cd lightwood;
pip install --no-cache-dir -e .

Please note that, depending on your os and python setup, you might want to use pip instead of pip3.

You need python 3.6 or higher.

Note on MacOS, you need to install libomp:

brew install libomp

Install using virtual environment

We suggest you to install Lightwood on a virtual environment to avoid dependency issues. Make sure your Python version is >=3.6. To set up a virtual environment:

Install on Windows

Install the latest version of pip:

python -m pip install --upgrade pip
pip --version

Activate your virtual environment and install lightwood:

py -m pip install --user virtualenv
.\env\Scripts\activate
pip install lightwood

You can also use python instead of py

Install on Linux or macOS

Before installing Lightwood in a virtual environment you need to first create and activate the venv:

python -m venv env
source env/bin/activate
pip install lightwood

Quick example

Assume that you have a training file (sensor_data.csv) such as this one.

sensor1 sensor2 sensor3
1 -1 -1
0 1 0
-1 -1 1
1 0 0
0 1 0
-1 1 -1
0 0 0
-1 -1 1
1 0 0

And you would like to learn to predict the values of sensor3 given the readings in sensor1 and sensor2.

Learn

You can train a Predictor as follows:

from lightwood import Predictor
import pandas

sensor3_predictor = Predictor(output=['sensor3'])
sensor3_predictor.learn(from_data=pandas.read_csv('sensor_data.csv'))

Predict

You can now be given new readings from sensor1 and sensor2 predict what sensor3 will be.

prediction = sensor3_predictor.predict(when={'sensor1':1, 'sensor2':-1})
print(prediction)

Of course, that example was just the tip of the iceberg, please read about the main concepts of lightwood, the API and then jump into examples.