# Before running the "jupyter notebook" command to bring up a notebook, install WIT
data_path = './bank-marketing.csv' # This was the CSV my auto ml regression model was trained on.
# Turn the dataset into a list of JSON dictionaries, as WIT accepts that format.
from witwidget.notebook.visualization import WitConfigBuilder
from witwidget.notebook.visualization import WitWidget
import requests
import json
# Custom prediction function to call to the served model.
# The AutoML tables model should be exported and then locally served
def custom_predict(examples):
# Send the predict request to the model served through docker.
request_data = {"instances": examples}
predictions = response.json()["predictions"]
# The served model seems to return predictions as a list if multiple examples are provided,
# but if only one example is provided in the examples list, then the predictions is a single
# value, instead of a list of length 1. In that case, we turn it into a list of length 1
# before returning it, since WIT's API is to return a list of numbers for regression models.
if not isinstance(predictions, list):
predictions = [predictions]
return predictions
# Display WIT - in this case on 1000 examples, for a regression model trying to predict the 'Balance' feature.
WitWidget(WitConfigBuilder(records[0:1000]).set_custom_predict_fn(custom_predict).set_model_type('regression').set_target_feature('Balance'), height=800)