One important use of trained predictors is as attributes for new relations.

Suppose an online flower retailer wanted to automatically classify irises it had in its stock database using the predictor constructed above. It could do so by joining one of its data set’s attributes to the predictor, provided that the attribute emits values that the predictor accepts.

The online flower retailer’s database has sepal and petal measurements for its irises but these are accessed through the following attribute (note that, unlike other examples in this guide, this domain exists, but does not host a PSI service):

GET http://flowers.com/data/irises/dimensions
200 OK
{
    "psiType":        "attribute",
    "uri":            "http://flowers.com/data/irises/dimensions",
    "description":    "Petal and sepal dimensions as [ sepal length, sepal width, petal length, petal width ]",
    "relation":        "http://flowers.com/data/irises",
    "emits":    {
        "$array": { "items": [ "$number", "$number", "$number", "$number" ] }
    },
    "subattributes": [
        "http://flowers.com/data/irises/dimensions/1",
        "http://flowers.com/data/irises/dimensions/2",
        "http://flowers.com/data/irises/dimensions/3",
        "http://flowers.com/data/irises/dimensions/4"
    ]
}

This attribute is conveniently already compatible with the values that the predictor accepts. The following join request connects the attribute to the knn predictor we trained earlier:

POST http://flowers.com/data/irises/vector
{
    "psiType":     "composition",
    "join":        "http://example.org/infer/knn_iris_20130802180742606",
    "description": "Predicted species"
}

201 OK
Location: http://flowers.com/irises/example.org/infer/knn_iris_20130802180742606

The new attribute can predict the species of irises in the retailer’s database:

GET http://flowers.com/irises/example.org/infer/knn_iris_20130802180742606
200 OK
{
    "psiType":      "attribute",
    "uri":          "http://flowers.com/irises/example.org/infer/knn_iris_20130802180742606",
    "description":  "Predicted species",
    "relation":     "http://flowers.com/data/irises"
    "emits":        { "$string" { "enum": [ "setosa", "versicolor", "virginica" ] } },
}

Next steps

Perhaps training and prediction using numerical feature vectors is a bit pedestrian for your tastes. What if Sir R.A. Fisher had taken photos of the 150 irises he collated and we wanted to train and predict using images instead?

Updating a predictor Training and prediction on rich values