我想从头开始创建一个新的 TensorFlow 数据验证 模式,并具有固定的功能名称、类型和存在。
import tensorflow_data_validation as tfdv
from tensorflow_metadata.proto.v0 import schema_pb2
# Initialisation
my_schem=schema_pb2.Schema()
# New features (one per available type)
for k in schema_pb2.FeatureType.items():
my_schem.feature.add(name=f'feat_{k[1]}', type=k[0])
tfdv.display_schema(schema=my_schem)
上面的代码返回以下模式:
功能名称 | 类型 | 存在 | 化合价 | 域名 |
---|---|---|---|---|
'feat_0' | 类型_未知 | - | ||
'feat_1' | 字节 | - | ||
'feat_2' | INT | - | ||
'feat_3' | 浮动 | - | ||
'feat_4' | 结构 | - |
如何为我的功能设置“存在”属性?
如 FeaturePresence 文档中所述,可能有两个参数:
min_fraction
:具有此功能的示例的最小比例min_count
:具有此功能的最小示例数量如果
min_fraction=1
,则100%的示例需要具有此功能,即该功能是必需的。
如果没有,该功能是可选。
import tensorflow_data_validation as tfdv
from tensorflow_metadata.proto.v0 import schema_pb2
# Initialisation
my_schem=schema_pb2.Schema()
# A new required feature
my_schem.feature.add(name='required_feat', type='INT', presence=schema_pb2.FeaturePresence(min_fraction=1))
# A new optional feature
my_schem.feature.add(name='optional_feat', type='INT', presence=schema_pb2.FeaturePresence(min_fraction=0.5))
tfdv.display_schema(schema=my_schem)
上面的代码返回以下模式: |功能名称 |类型 |存在 |化合价|域名 | | --- | --- | --- | --- |--- | | 'required_feat' | 'required_feat' | INT |必填| | - | | '可选壮举' | INT |可选 | | - |