FeaturizationConfig 类

为 Azure 机器学习中的自动化机器学习试验定义特征工程配置。

AutoMLConfig 类的 featurization 参数中使用 FeaturizationConfig 类。 有关详细信息,请参阅配置自动化 ML 试验

创建 FeaturizationConfig。

继承
builtins.object
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
list(str)
默认值: None

要在特征化期间阻止的转换器名称的列表。

column_purposes
dict
默认值: None

用于更新列用途的列名称和特征类型的字典。

transformer_params
dict
默认值: None

转换器和对应的自定义参数的字典。

drop_columns
list(str)
默认值: None

要在特征化过程中忽略的列的列表。 此设置即将弃用。 在将数据集提供给 AutoML 之前,请在数据准备过程中从数据集中删除列。

prediction_transform_type
str
默认值: None

要用于强制转换目标列类型的目标转换类型的 str。

blocked_transformers
list(str)
必需

要在特征化期间阻止的转换器名称的列表。

column_purposes
dict
必需

用于更新列用途的列名称和特征类型的字典。

transformer_params
dict
必需

转换器和对应的自定义参数的字典。

drop_columns
list(str)
必需

要在特征化过程中忽略的列的列表。 此设置即将弃用。 在将数据集提供给 AutoML 之前,请在数据准备过程中从数据集中删除列。

dataset_language
str
默认值: None

数据集中包含的语言 () 的三个字符 ISO 639-3 代码。 仅当使用启用了 GPU 的计算时,才支持英语以外的语言。 如果数据集包含多种语言,则应使用“mul”langugage_code。 若要查找不同语言的 ISO 639-3 代码,请参阅 https://en.wikipedia.org/wiki/List_of_ISO_639-3_codes

prediction_transform_type
str
必需

要用于强制转换目标列类型的目标转换类型的 str。

注解

特征化自定义提供了一些方法,使你能够:

  • 添加或删除列用途。 利用 add_column_purposeremove_column_purpose 方法,可以替代指定列的特征类型,例如,当列的特征类型未正确反映其用途时。 添加方法支持添加 FeatureType 类的 FULL_SET 特性中给定的所有特征类型。

  • 添加或删除转换器参数。 利用 add_transformer_paramsremove_transformer_params 方法,可以更改可自定义转换器的参数,如 Imputer、HashOneHotEncoder 和 TfIdf。 可自定义转换器列在 SupportedTransformers 类 CUSTOMIZABLE_TRANSFORMERS 特性中。 使用 get_transformer_params 查找自定义参数。

  • 阻止转换器。 使用 add_blocked_transformers 方法阻止要用于特征化过程的转换器。 转换器必须是 SupportedTransformers 类 BLOCKED_TRANSFORMERS 特性中列出的转换器之一。

  • 使用 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"})

完整示例可从 https://github.com/Azure/MachineLearningNotebooks/blob/master/how-to-use-azureml/automated-machine-learning/forecasting-orange-juice-sales/auto-ml-forecasting-orange-juice-sales.ipynb 获取

下一个示例演示使用硬件性能数据集在回归问题中自定义特征化。 在该示例代码中,定义了一个被阻止的转换器,添加了列用途,并添加了转换器参数。


   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})

完整示例可从 https://github.com/Azure/MachineLearningNotebooks/blob/master/how-to-use-azureml/automated-machine-learning/regression-explanation-featurization/auto-ml-regression-explanation-featurization.ipynb 获取

然后,上面的代码示例中定义的 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,
   )

完整示例可从 https://github.com/Azure/MachineLearningNotebooks/blob/master/how-to-use-azureml/automated-machine-learning/regression-explanation-featurization/auto-ml-regression-explanation-featurization.ipynb 获取

方法

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
strlist[str]
必需

转换器名称或转换器名称列表。 转换器名称必须是 SupportedTransformers 类的 BLOCKED_TRANSFORMERS 特性中列出的转换器之一。

add_column_purpose

添加指定列的特征类型。

add_column_purpose(column_name: str, feature_type: str) -> None

参数

column_name
str
必需

要更新的列名称。

feature_type
FeatureType
必需

要用于该列的特征类型。 特征类型必须是 FeatureType 类的 FULL_SET 特性中给定的一个。

add_drop_columns

添加要忽略的列名称或列名称的列表。

add_drop_columns(drop_columns: str | List[str]) -> None

参数

drop_columns
strlist[str]
必需

列名称或列名称的列表。

add_prediction_transform_type

为目标列添加预测转换类型。

PredictionTransformTypes 类。 :type prediction_transform_type: str

add_prediction_transform_type(prediction_transform_type: str) -> None

参数

prediction_transform_type
必需

用于强制转换目标列的预测转换类型。 特征类型必须是 FULL_SET 特性中给定的一个

add_transformer_params

将自定义转换器参数添加到自定义转换器参数的列表。

如果列列表为空,则应用于所有列。

add_transformer_params(transformer: str, cols: List[str], params: Dict[str, Any]) -> None

参数

transformer
str
必需

转换器名称。 转换器名称必须是 SupportedTransformers 类中列出的 CUSTOMIZABLE_TRANSFORMERS 之一。

cols
list(str)
必需

指定转换器的输入列。 某些转换器可以将多个列作为指定为列表的输入。

params
dict
必需

关键字和参数的字典。

注解

下面的代码示例演示如何在自动化 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"})

完整示例可从 https://github.com/Azure/MachineLearningNotebooks/blob/master/how-to-use-azureml/automated-machine-learning/forecasting-orange-juice-sales/auto-ml-forecasting-orange-juice-sales.ipynb 获取

get_transformer_params

检索列的转换器自定义参数。

get_transformer_params(transformer: str, cols: List[str]) -> Dict[str, Any]

参数

transformer
str
必需

转换器名称。 转换器名称必须是 SupportedTransformers 类中列出的 CUSTOMIZABLE_TRANSFORMERS 之一。

cols
list[str]
必需

要为其获取信息的列名称。 使用空列表指定所有列。

返回

转换器参数设置。

返回类型

remove_column_purpose

删除指定列的特征类型。

如果没有为列指定任何特征,则使用检测到的默认特征。

remove_column_purpose(column_name: str) -> None

参数

column_name
str
必需

要更新的列名称。

remove_prediction_transform_type

对于目标列,将预测转换类型还原为默认值。

remove_prediction_transform_type() -> None

remove_transformer_params

删除特定列或所有列的转换器自定义参数。

remove_transformer_params(transformer: str, cols: List[str] | None = None) -> None

参数

transformer
str
必需

转换器名称。 转换器名称必须是 SupportedTransformers 类中列出的 CUSTOMIZABLE_TRANSFORMERS 之一。

cols
list[str] 或 None
默认值: None

要从中删除自定义参数的列名称。 指定 None(默认)以删除指定转换器的所有自定义参数。

属性

blocked_transformers

column_purposes

dataset_language

drop_columns

prediction_transform_type

transformer_params