BigML Bindings: 101 - Using Association DiscoveryΒΆ

Following the schema described in the prediction workflow, document, this is the code snippet that shows the minimal workflow to create an association and produce association sets.

from bigml.api import BigML
# step 0: creating a connection to the service (default credentials)
api = BigML()
# step 1: creating a source from the data in your local "data/groceries.csv" file
source = api.create_source("data/groceries.csv")
# waiting for the source to be finished. Results will be stored in `source`
# step 3: creating a dataset from the previously created `source`
dataset = api.create_dataset(source)
# waiting for the dataset to be finished
# step 5: creating an association
association = api.create_association(dataset)
# waiting for the association to be finished
# the new input data to predict for
input_data = {"Products": "Fruit, Wine"}
# creating a single association set
association_set = api.create_association_set(association, input_data)

In the previous code, the api.ok method is used to wait for the resource to be finished before calling the next create method or accessing the resource properties. In the first case, we could skip that api.ok`call because the next `create method would internally do the waiting when needed.

You can also create association sets locally using the Association class in the association module. A simple example of that is:

from bigml.association import Association
local_association = Association("association/5968ec46983efc21b000001b")
# association set for some input data
local_association.association_set({"Products": "Fruit, Wine"})

Or you could store first your association information in a file and use that file to create the local Association object:

# downloading the association JSON to a local file
from bigml.api import BigML
api = BigML()
# creating the association from the file
from bigml.association import Association
local_association = Association("my_association.json")
# association set for some input data
local_association.association_set({"Products": "Fruit, Wine"})

Every modeling resource in BigML has its corresponding local class. Check the Local resources section of the documentation to learn more about them.