This tutorial is a quick introduction to training and testing your model with Vowpal Wabbit using Python. We explore passing some data to Vowpal Wabbit to learn a model and get a prediction.
For more advanced Vowpal Wabbit tutorials, including how to format data and understand results, see Tutorials.
To install Vowpal Wabbit see Get Started.
First, import the Vowpal Wabbit Python package for this tutorial:
from vowpalwabbit import pyvw
Next, we create an instance of Vowpal Wabbit, and pass the
quiet=True option to avoid diagnostic information output to
model = pyvw.vw(quiet=True)
For this tutorial scenario, we want Vowpal Wabbit to help us predict whether or not our house will require a new roof in the next 10 years.
To create some examples, we use the Vowpal Wabbit text format and then learn on them:
train_examples = [ "0 | price:.23 sqft:.25 age:.05 2006", "1 | price:.18 sqft:.15 age:.35 1976", "0 | price:.53 sqft:.32 age:.87 1924", ] for example in train_examples: model.learn(example)
Note: For more details on Vowpal Wabbit input format and feature hashing techniques see the Linear Regression Tutorial.
Now, we create a
test_example to use for prediction:
test_example = "| price:.46 sqft:.4 age:.10 1924" prediction = model.predict(test_example) print(prediction)
The model predicted a value of 0. According to our learning model, our house will not need a new roof in the next 10 years (at least that is the result from just three examples we used in our training dataset).