|View source on GitHub|
Configuration for feature trusts in TFL canned estimators.
tfl.configs.TrustConfig( feature_name, trust_type='edgeworth', direction='positive' )
Used in the notebooks
|Used in the tutorials|
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.
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
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
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', ), ... ])
feature_name: Name of the "main" feature for the trust constraint.
trust_type: Type of trust constraint. Either
direction: Direction of the trust. Should be:
'negative', 1 or -1.