FeaturizationConfig 类
定义 Azure 机器学习中自动化机器学习试验的功能工程配置。
在类的参数featurization中使用 AutoMLConfig FeaturizationConfig 类。 有关详细信息,请参阅 配置自动化 ML 试验。
创建 FeaturizationConfig。
构造函数
FeaturizationConfig(blocked_transformers: List[str] | None = None, column_purposes: Dict[str, str] | None = None, transformer_params: Dict[str, List[Tuple[List[str], Dict[str, Any]]]] | None = None, drop_columns: List[str] | None = None, dataset_language: str | None = None, prediction_transform_type: str | None = None)
参数
| 名称 | 说明 |
|---|---|
|
blocked_transformers
|
在特征化期间要阻止的转换器名称列表。 默认值: None
|
|
column_purposes
|
用于更新列用途的列名称和功能类型的字典。 默认值: None
|
|
transformer_params
|
转换器字典和相应的自定义参数。 默认值: None
|
|
drop_columns
|
要在特征化过程中忽略的列的列表。 此设置已弃用。 在向 AutoML 提供数据集之前,请将数据集中的列作为数据准备过程的一部分删除。 默认值: None
|
|
prediction_transform_type
|
要用于强制转换目标列类型的目标转换类型的 str。 默认值: None
|
|
blocked_transformers
必需
|
在特征化期间要阻止的转换器名称列表。 |
|
column_purposes
必需
|
用于更新列用途的列名称和功能类型的字典。 |
|
transformer_params
必需
|
转换器字典和相应的自定义参数。 |
|
drop_columns
必需
|
要在特征化过程中忽略的列的列表。 此设置已弃用。 在向 AutoML 提供数据集之前,请将数据集中的列作为数据准备过程的一部分删除。 |
|
dataset_language
|
数据集中包含的语言的三个字符 ISO 639-3 代码。 仅当使用启用了 GPU 的计算时,才支持英语以外的语言。 如果数据集包含多种语言,则应使用langugage_code“mul”。 若要查找不同语言的 ISO 639-3 代码,请参阅 https://en.wikipedia.org/wiki/List_of_ISO_639-3_codes。 默认值: None
|
|
prediction_transform_type
必需
|
要用于强制转换目标列类型的目标转换类型的 str。 |
注解
特征化自定义具有允许你:
添加或删除列用途。
add_column_purpose使用和remove_column_purpose方法可以替代指定列的功能类型,例如,当列的功能类型无法正确反映其用途时。 add 方法支持添加类的 FULL_SET 属性 FeatureType 中提供的所有功能类型。添加或删除转换器参数。
add_transformer_params使用和remove_transformer_params方法可以更改可自定义转换器的参数,如 Imputer、HashOneHotEncoder 和 TfIdf。 可自定义转换器列在类CUSTOMIZABLE_TRANSFORMERS属性中 SupportedTransformers 。get_transformer_params使用查找自定义参数。块转换器。 用于采用该方法的特征化过程的
add_blocked_transformers块转换器。 转换器必须是类BLOCKED_TRANSFORMERS属性中列出的 SupportedTransformers 转换器之一。使用该方法添加删除列以忽略特征化和训练
add_drop_columns。 例如,可以删除不包含有用信息的列。添加或删除预测转换类型。 使用
add_prediction_transform_type和
remove_prediction_transform_type 方法可以重写现有的目标列类型。
预测转换类型列在 PredictionTransformTypes 属性中。
下面的代码示例演示如何在自动化 ML 中自定义特征化以用于预测。 在示例代码中,将显示删除列并添加转换参数。
featurization_config = FeaturizationConfig()
# Force the CPWVOL5 feature to be numeric type.
featurization_config.add_column_purpose("CPWVOL5", "Numeric")
# Fill missing values in the target column, Quantity, with zeros.
featurization_config.add_transformer_params(
"Imputer", ["Quantity"], {"strategy": "constant", "fill_value": 0}
)
# Fill missing values in the INCOME column with median value.
featurization_config.add_transformer_params(
"Imputer", ["INCOME"], {"strategy": "median"}
)
# Fill missing values in the Price column with forward fill (last value carried forward).
featurization_config.add_transformer_params("Imputer", ["Price"], {"strategy": "ffill"})
下一个示例演示如何使用硬件性能数据集在回归问题中自定义特征化。 在示例代码中,定义了阻止的转换器、添加列用途以及添加转换器参数。
featurization_config = FeaturizationConfig()
featurization_config.blocked_transformers = ["LabelEncoder"]
# featurization_config.drop_columns = ['MMIN']
featurization_config.add_column_purpose("MYCT", "Numeric")
featurization_config.add_column_purpose("VendorName", "CategoricalHash")
# default strategy mean, add transformer param for for 3 columns
featurization_config.add_transformer_params("Imputer", ["CACH"], {"strategy": "median"})
featurization_config.add_transformer_params(
"Imputer", ["CHMIN"], {"strategy": "median"}
)
featurization_config.add_transformer_params(
"Imputer", ["PRP"], {"strategy": "most_frequent"}
)
# featurization_config.add_transformer_params('HashOneHotEncoder', [], {"number_of_bits": 3})
然后,上述代码示例中定义的 FeaturizationConfig 可以在自动化 ML 试验的配置中使用,如下一个代码示例所示。
automl_settings = {
"enable_early_stopping": True,
"experiment_timeout_hours": 0.25,
"max_concurrent_iterations": 4,
"max_cores_per_iteration": -1,
"n_cross_validations": 5,
"primary_metric": "normalized_root_mean_squared_error",
"verbosity": logging.INFO,
}
automl_config = AutoMLConfig(
task="regression",
debug_log="automl_errors.log",
compute_target=compute_target,
featurization=featurization_config,
training_data=train_data,
label_column_name=label,
**automl_settings,
)
方法
| add_blocked_transformers |
添加要阻止的转换器。 |
| add_column_purpose |
为指定列添加特征类型。 |
| add_drop_columns |
添加要忽略的列名或列名列表。 |
| add_prediction_transform_type |
为目标列添加预测转换类型。 PredictionTransformTypes 类。 :type prediction_transform_type: str |
| add_transformer_params |
将自定义转换器参数添加到自定义转换器参数列表。 如果列列表为空,则应用于所有列。 |
| get_transformer_params |
检索列的转换器自定义参数。 |
| remove_column_purpose |
删除指定列的功能类型。 如果未为列指定任何功能,则使用检测到的默认功能。 |
| remove_prediction_transform_type |
将预测转换类型还原为目标列的默认值。 |
| remove_transformer_params |
删除特定列或所有列的转换器自定义参数。 |
add_blocked_transformers
添加要阻止的转换器。
add_blocked_transformers(transformers: str | List[str]) -> None
参数
| 名称 | 说明 |
|---|---|
|
transformers
必需
|
转换器名称或转换器名称列表。 转换器名称必须是类BLOCKED_TRANSFORMERS属性 SupportedTransformers 中列出的转换器之一。 |
add_column_purpose
为指定列添加特征类型。
add_column_purpose(column_name: str, feature_type: str) -> None
参数
| 名称 | 说明 |
|---|---|
|
column_name
必需
|
要更新的列名。 |
|
feature_type
必需
|
要用于列的功能类型。 特征类型必须是类的 FULL_SET 属性 FeatureType 中的一个。 |
add_drop_columns
add_prediction_transform_type
为目标列添加预测转换类型。
PredictionTransformTypes 类。 :type prediction_transform_type: str
add_prediction_transform_type(prediction_transform_type: str) -> None
参数
| 名称 | 说明 |
|---|---|
|
prediction_transform_type
必需
|
要用于转换目标列的预测转换类型。
功能类型必须是 |
add_transformer_params
将自定义转换器参数添加到自定义转换器参数列表。
如果列列表为空,则应用于所有列。
add_transformer_params(transformer: str, cols: List[str], params: Dict[str, Any]) -> None
参数
| 名称 | 说明 |
|---|---|
|
transformer
必需
|
转换器名称。 转换器名称必须是类中列出的 SupportedTransformers CUSTOMIZABLE_TRANSFORMERS之一。 |
|
cols
必需
|
指定转换器的输入列。 某些转换器可以将多个列作为指定列表的输入。 |
|
params
必需
|
关键字和参数的字典。 |
注解
下面的代码示例演示如何在自动化 ML 中自定义特征化以用于预测。 在示例代码中,将显示删除列并添加转换参数。
featurization_config = FeaturizationConfig()
# Force the CPWVOL5 feature to be numeric type.
featurization_config.add_column_purpose("CPWVOL5", "Numeric")
# Fill missing values in the target column, Quantity, with zeros.
featurization_config.add_transformer_params(
"Imputer", ["Quantity"], {"strategy": "constant", "fill_value": 0}
)
# Fill missing values in the INCOME column with median value.
featurization_config.add_transformer_params(
"Imputer", ["INCOME"], {"strategy": "median"}
)
# Fill missing values in the Price column with forward fill (last value carried forward).
featurization_config.add_transformer_params("Imputer", ["Price"], {"strategy": "ffill"})
get_transformer_params
检索列的转换器自定义参数。
get_transformer_params(transformer: str, cols: List[str]) -> Dict[str, Any]
参数
| 名称 | 说明 |
|---|---|
|
transformer
必需
|
转换器名称。 转换器名称必须是类中列出的 SupportedTransformers CUSTOMIZABLE_TRANSFORMERS之一。 |
|
cols
必需
|
要获取其信息的列名。 使用空列表指定所有列。 |
返回
| 类型 | 说明 |
|---|---|
|
转换器参数设置。 |
remove_column_purpose
删除指定列的功能类型。
如果未为列指定任何功能,则使用检测到的默认功能。
remove_column_purpose(column_name: str) -> None
参数
| 名称 | 说明 |
|---|---|
|
column_name
必需
|
要更新的列名。 |
remove_prediction_transform_type
将预测转换类型还原为目标列的默认值。
remove_prediction_transform_type() -> None
remove_transformer_params
删除特定列或所有列的转换器自定义参数。
remove_transformer_params(transformer: str, cols: List[str] | None = None) -> None
参数
| 名称 | 说明 |
|---|---|
|
transformer
必需
|
转换器名称。 转换器名称必须是类中列出的 SupportedTransformers CUSTOMIZABLE_TRANSFORMERS之一。 |
|
cols
|
要从中删除自定义参数的列名。 指定 None (默认值)以删除指定转换器的所有自定义参数。 默认值: None
|