Customizing your Model Schema
There can be occasions when the fdl.ModelSchema
object generated by fdl.Model.from_data
infers a column's data type differently than the type intended by the model developer. In these cases you can modify the ModelSchema columns as needed prior to creating the model in Fiddler.
Let's walk through an example of how to do this.
Suppose you've loaded in a dataset as a pandas DataFrame.
Below is an example of what is displayed upon inspection.
![](https://docs.fiddler.ai/~gitbook/image?url=https%3A%2F%2F1798616019-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FmtRqRYN3Dch4wlduXsol%252Fuploads%252Fgit-blob-2b65a69b89f3a93eef0150f188afca5c88165bca%252F3ffd956-example_df_1.png%3Falt%3Dmedia&width=768&dpr=4&quality=100&sign=2b9f24fe&sv=1)
You then create a fdl.Model
object by inferring the column schema details from this DataFrame.
Below is an example of what is displayed upon inspection of model.schema
.
![](https://docs.fiddler.ai/~gitbook/image?url=https%3A%2F%2F1798616019-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FmtRqRYN3Dch4wlduXsol%252Fuploads%252Fgit-blob-caa16e09b7d515b8f455d18e74a18d60cb608b89%252F8be7229-Screen_Shot_2024-04-22_at_2.26.13_PM.png%3Falt%3Dmedia&width=768&dpr=4&quality=100&sign=876854e7&sv=1)
Upon inspection you may notice that a few things are off:
The value range of
output_column
is set to[0.01, 0.99]
, when it should really be[0.0, 1.0]
.There are no possible values set for
feature_3
.The data type of
feature_3
is set tofdl.DataType.STRING
, when it should really befdl.DataType.CATEGORY
.
What's the downside of not making sure that ranges and categories are reviewed and properly set? A production traffic event that encodes a number outside of the specified value range or a category value that is not in the set of valid category values will further down the line be flagged as a so-called Data Integrity violation. Depending on the alerting config, this may result in an alert. It's also worth noting however that an event which has a violation in its columns is still processed, and metrics that can be generated are still generated.
The below examples demonstrate how to address each of the issues noted:
Modifying a Column’s Value Range
Let's say we want to modify the range of output_column
in the above fdl.Model
object to be [0.0, 1.0]
.
You can do this by setting the min
and max
of the output_column
column.
Modifying a Column’s Possible Values
Let's say we want to modify the possible values of feature_3
to be ['Yes', 'No']
.
You can do this by setting the categories
of the feature_3
column.
Modifying a Column’s Data Type
Let's say we want to modify the data type of feature_3
to be fdl.DataType.CATEGORY
.
You can do this by setting the data_type
of the feature_3
column.
🚧 Note when modifying a column's data type to Category:
It is also required to set the column's possible_values to the list of unique possible values for that column. This is done automatically when a String column is inferred as a Category.
model.schema['feature_3'].data_type = fdl.DataType.CATEGORY model.schema['feature_3'].possible_values = ['Yes', 'No']
Last updated