tfl.configs.TrustConfig
Stay organized with collections
Save and categorize content based on your preferences.
Configuration for feature trusts in TFL canned estimators.
tfl.configs.TrustConfig(
feature_name,
trust_type='edgeworth',
direction='positive'
)
Used in the notebooks
You can specify how a feature reflects trust in another feature. Supported
trust types (see tfl.layers.Lattice
for details):
'edgeworth'
: Edgeworth trust constrains the function to be more
responsive to a main feature as a secondary conditional feature increases
or decreases. For example, we may want the model to rely more on average
rating (main feature) when the number of reviews (conditional feature) is
high. In particular, the constraint guarantees that a given change in the
main feature's value will change the model output by more when a secondary
feature indicates higher trust in the main feature. Note that the
constraint only works when the model is monotonic in the main feature.
'trapezoid'
: Trapezoid trust is conceptually similar to edgeworth trust,
but this constraint guarantees that the range of possible outputs along
the main feature dimension, when a conditional feature indicates low
trust, is a subset of the range of outputs when a conditional feature
indicates high trust. When lattices have 2 vertices in each constrained
dimension, this implies edgeworth trust (which only constrains the size of
the relevant ranges). With more than 2 lattice vertices per dimension, the
two constraints diverge and are not necessarily 'weaker' or 'stronger'
than each other - edgeworth trust acts throughout the lattice interior on
delta shifts in the main feature, while trapezoid trust only acts on the
min and max extremes of the main feature, constraining the overall range
of outputs across the domain of the main feature. The two types of trust
constraints can be applied jointly.
Trust constraints only affect lattices. When using trapezoid constraints in
ensemble models, note that if a conditional feature is used in a lattice
without the main feature also being used in the same lattice, then the
trapezoid constraint might be violated for the ensemble function.
Exampes:
One feature reflecting trust in another:
model_config = tfl.configs.CalibratedLatticeConfig(
feature_configs=[
tfl.configs.FeatureConfig(
name='num_reviews',
reflects_trust_in=[
configs.TrustConfig(
feature_name='average_rating', trust_type='edgeworth'),
],
),
tfl.configs.FeatureConfig(
name='average_rating',
),
])
Features can reflect positive or negative trust in other features. For example
if the task is to estimate a property price in a neighborhood given two
average prices for commercial and residential properties, you can use a trust
feature percentage_commercial_properties
to indicate that the model should
more responsive to commercial estimate if more properties are commercial in
the neighborhood. You can simultaneously have a negative trust constratins for
residential properties, since higher commercial land usage indicates fewer
houses, hence less market influence and less accurate estimate for residential
property prices.
model_config = tfl.configs.CalibratedLatticeConfig(
feature_configs=[
tfl.configs.FeatureConfig(
name='percentage_commercial_properties',
reflects_trust_in=[
configs.TrustConfig(
feature_name='average_commercial_property_price',
direction='positive'),
configs.TrustConfig(
feature_name='average_residential_property_price',
direction='negative'),
],
),
tfl.configs.FeatureConfig(
name='average_commercial_property_price',
),
tfl.configs.FeatureConfig(
name='average_residential_property_price',
),
tfl.configs.FeatureConfig(
name='square_footage',
),
...
])
Args |
feature_name
|
Name of the "main" feature for the trust constraint.
|
trust_type
|
Type of trust constraint. Either 'edgeworth' or
'trapezoid' .
|
direction
|
Direction of the trust. Should be: 'positive' , 'negative' ,
1 or -1.
|
Methods
deserialize_nested_configs
View source
@classmethod
deserialize_nested_configs(
config, custom_objects=None
)
Returns a deserialized configuration dictionary.
from_config
View source
@classmethod
from_config(
config, custom_objects=None
)
get_config
View source
get_config()
Returns a configuration dictionary.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-08-02 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-08-02 UTC."],[],[],null,["# tfl.configs.TrustConfig\n\n\u003cbr /\u003e\n\n|----------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/lattice/blob/v2.1.1/tensorflow_lattice/python/configs.py#L938-L1048) |\n\nConfiguration for feature trusts in TFL canned estimators. \n\n tfl.configs.TrustConfig(\n feature_name,\n trust_type='edgeworth',\n direction='positive'\n )\n\n### Used in the notebooks\n\n| Used in the tutorials |\n|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| - [Shape Constraints with Tensorflow Lattice](https://www.tensorflow.org/lattice/tutorials/shape_constraints) - [TF Lattice Aggregate Function Models](https://www.tensorflow.org/lattice/tutorials/aggregate_function_models) |\n\nYou can specify how a feature reflects trust in another feature. Supported\ntrust types (see [`tfl.layers.Lattice`](../../tfl/layers/Lattice) for details):\n\n- `'edgeworth'`: Edgeworth trust constrains the function to be more responsive to a main feature as a secondary conditional feature increases or decreases. For example, we may want the model to rely more on average rating (main feature) when the number of reviews (conditional feature) is high. In particular, the constraint guarantees that a given change in the main feature's value will change the model output by more when a secondary feature indicates higher trust in the main feature. Note that the constraint only works when the model is monotonic in the main feature.\n- `'trapezoid'`: Trapezoid trust is conceptually similar to edgeworth trust, but this constraint guarantees that the range of possible outputs along the main feature dimension, when a conditional feature indicates low trust, is a *subset* of the range of outputs when a conditional feature indicates high trust. When lattices have 2 vertices in each constrained dimension, this implies edgeworth trust (which only constrains the size of the relevant ranges). With more than 2 lattice vertices per dimension, the two constraints diverge and are not necessarily 'weaker' or 'stronger' than each other - edgeworth trust acts throughout the lattice interior on delta shifts in the main feature, while trapezoid trust only acts on the min and max extremes of the main feature, constraining the overall range of outputs across the domain of the main feature. The two types of trust constraints can be applied jointly.\n\nTrust constraints only affect lattices. When using trapezoid constraints in\nensemble models, note that if a conditional feature is used in a lattice\nwithout the main feature also being used in the same lattice, then the\ntrapezoid constraint might be violated for the ensemble function.\n\n#### Exampes:\n\nOne feature reflecting trust in another: \n\n model_config = tfl.configs.CalibratedLatticeConfig(\n feature_configs=[\n tfl.configs.FeatureConfig(\n name='num_reviews',\n reflects_trust_in=[\n configs.TrustConfig(\n feature_name='average_rating', trust_type='edgeworth'),\n ],\n ),\n tfl.configs.FeatureConfig(\n name='average_rating',\n ),\n ])\n\nFeatures can reflect positive or negative trust in other features. For example\nif the task is to estimate a property price in a neighborhood given two\naverage prices for commercial and residential properties, you can use a trust\nfeature `percentage_commercial_properties` to indicate that the model should\nmore responsive to commercial estimate if more properties are commercial in\nthe neighborhood. You can simultaneously have a negative trust constratins for\nresidential properties, since higher commercial land usage indicates fewer\nhouses, hence less market influence and less accurate estimate for residential\nproperty prices. \n\n model_config = tfl.configs.CalibratedLatticeConfig(\n feature_configs=[\n tfl.configs.FeatureConfig(\n name='percentage_commercial_properties',\n reflects_trust_in=[\n configs.TrustConfig(\n feature_name='average_commercial_property_price',\n direction='positive'),\n configs.TrustConfig(\n feature_name='average_residential_property_price',\n direction='negative'),\n ],\n ),\n tfl.configs.FeatureConfig(\n name='average_commercial_property_price',\n ),\n tfl.configs.FeatureConfig(\n name='average_residential_property_price',\n ),\n tfl.configs.FeatureConfig(\n name='square_footage',\n ),\n ...\n ])\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|----------------|-------------------------------------------------------------------------|\n| `feature_name` | Name of the \"main\" feature for the trust constraint. |\n| `trust_type` | Type of trust constraint. Either `'edgeworth'` or `'trapezoid'`. |\n| `direction` | Direction of the trust. Should be: `'positive'`, `'negative'`, 1 or -1. |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `deserialize_nested_configs`\n\n[View source](https://github.com/tensorflow/lattice/blob/v2.1.1/tensorflow_lattice/python/configs.py#L124-L158) \n\n @classmethod\n deserialize_nested_configs(\n config, custom_objects=None\n )\n\nReturns a deserialized configuration dictionary.\n\n### `from_config`\n\n[View source](https://github.com/tensorflow/lattice/blob/v2.1.1/tensorflow_lattice/python/configs.py#L1045-L1048) \n\n @classmethod\n from_config(\n config, custom_objects=None\n )\n\n### `get_config`\n\n[View source](https://github.com/tensorflow/lattice/blob/v2.1.1/tensorflow_lattice/python/configs.py#L93-L122) \n\n get_config()\n\nReturns a configuration dictionary."]]