Published in

Vowpal Wabbit on Azure ML

Example to run Vowpal Wabbit on Azure ML



pip install vowpalwabbit
import pandas as pd
import sklearn
import sklearn.model_selection
import sklearn.datasets
import vowpalwabbit
iris_dataset = sklearn.datasets.load_iris()
iris_dataframe = pd.DataFrame(, columns=iris_dataset.feature_names
# vw expects labels starting from 1
iris_dataframe["y"] = + 1
training_data, testing_data = sklearn.model_selection.train_test_split(
iris_dataframe, test_size=0.2
def to_vw_format(row):
res = f"{int(row.y)} |"
for idx, value in row.drop(["y"]).iteritems():
feature_name = idx.replace(" ", "_").replace("(", "").replace(")", "")
res += f" {feature_name}:{value}"
return res
for ex in training_data.head(10).apply(to_vw_format, axis=1):
vw = vowpalwabbit.Workspace("--oaa 3 --quiet")# learn from training set with multiple passes
for example in training_data.apply(to_vw_format, axis=1):
# predict from the testing set
predictions = []
for example in testing_data.apply(to_vw_format, axis=1):
predicted_class = vw.predict(example)
accuracy = len(testing_data[testing_data.y == predictions]) / len(testing_data)print(f"Model accuracy {accuracy}")
Model accuracy 0.7333333333333333



Data Scientists must think like an artist when finding a solution when creating a piece of code. ⚪️ Artists enjoy working on interesting problems, even if there is no obvious answer ⚪️ 🔵 Follow to join our 28K+ Unique DAILY Readers 🟠

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store