JSON/YAML as Features#

Objectives#

  • Definitions & Understanding of what JSON (JavaScript Object Notation) and YAML (Yet Another Markup Language) features are and how they can be used.

Prerequisites#

Notebook Recipe#

This user guide has its content outlined in the JSON as a Feature Notebook

Concepts & Terminology#

This guide focuses primarily on the concept of JSON/YAML objects as features. We additionally recommend being familiar with the following concepts:

How-To Guide#

Howso Engine can accept JSON and YAML objects as feature values, treating them like any other feature. This can allow more complex objects to be represented than just numbers or strings.

Declaring a Feature as JSON/YAML#

When calling howso.utilities.infer_../basics/feature_attributes(), a feature can be declared as JSON or YAML by setting its data_type attribute.

Replace "json" with "yaml" to use YAML for your feature.#
features = infer_../basics/feature_attributes(
    data,
    features={"inventory": {"type": "continuous", "data_type": "json"}}
)

Note that the feature’s type attribute is set normally to either "continuous" or "nominal". For ones marked as continuous, distance will be computed using a form of edit distance. Otherwise, the normal nominal distance computation is used.

Once a feature is set as JSON properly, it can be used as if it were any other feature.

Reacting to JSON/YAML Features#

Below are a few code snippets that show how JSON/YAML features can be used in a react:

Using level and class, predict inventory (a JSON feature).#
t.react(
    contexts=[[15, "Warlock"]], context_features=["level", "class"],
    action_features=["inventory"],
)
Using level and class, generate inventory (a JSON feature).#
t.react(
    contexts=[[15, "Warlock"]], context_features=["level", "class"],
    action_features=["inventory"],
    desired_conviction=25,
)
Using inventory (a JSON feature) and level, predict class.#
t.react(
    contexts=[["{\"sword\": 1, \"lute\": 1, \"potion\": 2}", 15]],
    context_features=["inventory", "level"],
    action_features=["class"],
)

Note

Note that, in the above example, the entire JSON is contained within a string and contained quotes within that are escaped.

API References#