component_graph#

管道的组件图,表示为有向无环图(DAG)。

模块内容#

类摘要#

ComponentGraph

管道的组件图,表示为有向无环图(DAG)。

属性摘要#

目录#

class evalml.pipelines.component_graph.ComponentGraph(component_dict=None, cached_data=None, random_seed=0)[source]#

管道的组件图,表示为有向无环图(DAG)。

参数
  • component_dict (dict) – 一个字典,指定用于创建组件图的组件及其之间的连接。默认为 None。

  • cached_data (dict) – 嵌套缓存数据的字典。如果哈希值和组件在此缓存中,则跳过这些组件的拟合。预期格式为 {hash1: {组件名称: 已训练组件, …}, hash2: {…}, …}。默认为 None。

  • random_seed (int) – 随机数生成器的种子。默认为 0。

示例

>>> component_dict = {'Imputer': ['Imputer', 'X', 'y'],
...                   'Logistic Regression': ['Logistic Regression Classifier', 'Imputer.x', 'y']}
>>> component_graph = ComponentGraph(component_dict)
>>> assert component_graph.compute_order == ['Imputer', 'Logistic Regression']
...
...
>>> component_dict = {'Imputer': ['Imputer', 'X', 'y'],
...                   'OHE': ['One Hot Encoder', 'Imputer.x', 'y'],
...                   'estimator_1': ['Random Forest Classifier', 'OHE.x', 'y'],
...                   'estimator_2': ['Decision Tree Classifier', 'OHE.x', 'y'],
...                   'final': ['Logistic Regression Classifier', 'estimator_1.x', 'estimator_2.x', 'y']}
>>> component_graph = ComponentGraph(component_dict)

组件图中每个组件的默认参数。

>>> assert component_graph.default_parameters == {
...     'Imputer': {'categorical_impute_strategy': 'most_frequent',
...                 'numeric_impute_strategy': 'mean',
...                 'boolean_impute_strategy': 'most_frequent',
...                 'categorical_fill_value': None,
...                 'numeric_fill_value': None,
...                 'boolean_fill_value': None},
...     'One Hot Encoder': {'top_n': 10,
...                         'features_to_encode': None,
...                         'categories': None,
...                         'drop': 'if_binary',
...                         'handle_unknown': 'ignore',
...                         'handle_missing': 'error'},
...     'Random Forest Classifier': {'n_estimators': 100,
...                                  'max_depth': 6,
...                                  'n_jobs': -1},
...     'Decision Tree Classifier': {'criterion': 'gini',
...                                  'max_features': 'sqrt',
...                                  'max_depth': 6,
...                                  'min_samples_split': 2,
...                                  'min_weight_fraction_leaf': 0.0},
...     'Logistic Regression Classifier': {'penalty': 'l2',
...                                        'C': 1.0,
...                                        'n_jobs': -1,
...                                        'multi_class': 'auto',
...                                        'solver': 'lbfgs'}}

方法

compute_order

组件将被计算或调用的顺序。

default_parameters

此管道的默认参数字典。

describe

输出组件图详细信息,包括组件参数。

fit

拟合图中的每个组件。

fit_and_transform_all_but_final

拟合并转换除最后一个组件(通常是估计器)外的所有组件。

fit_transform

如果所有组件都是 Transformer,则拟合并转换组件图中的所有组件。

generate_order

重新生成图的拓扑排序顺序。

get_component

从图中检索单个组件对象。

get_component_input_logical_types

获取传递给给定组件的逻辑类型。

get_estimators

获取此图中的所有估计器组件列表。

get_inputs

检索给定组件的所有输入。

get_last_component

检索图中最后计算的组件,通常是最终估计器。

graph

生成表示组件图的图像。

has_dfs

此组件图是否包含 DFSTransformer。

instantiate

使用给定的参数实例化图中所有未实例化的组件。如果组件已实例化但参数字典包含该组件的参数,则会引发错误。

inverse_transform

按逆序将组件的 inverse_transform 方法应用于估计器预测结果。

last_component_input_logical_types

获取传递给管道中最后一个组件的逻辑类型。

predict

使用选定的特征进行预测。

transform

使用组件图转换输入。

transform_all_but_final

转换除最后一个组件外的所有组件,并从任意数量的父组件收集数据,以获取应馈送给最后一个组件的所有信息。

property compute_order(self)#

组件将被计算或调用的顺序。

property default_parameters(self)#

此管道的默认参数字典。

返回

所有组件默认参数的字典。

返回类型

dict

describe(self, return_dict=False)[source]#

输出组件图详细信息,包括组件参数。

参数

return_dict (bool) – 如果为 True,则返回关于组件图信息的字典。默认为 False。

返回

如果 return_dict 为 True,则返回所有组件参数的字典,否则返回 None

返回类型

dict

抛出

ValueError – 如果组件图未实例化

fit(self, X, y)[source]#

拟合图中的每个组件。

参数
  • X (pd.DataFrame) – 输入训练数据,形状为 [n_samples, n_features]。

  • y (pd.Series) – 目标训练数据,长度为 [n_samples]。

返回

self

fit_and_transform_all_but_final(self, X, y)[source]#

拟合并转换除最后一个组件(通常是估计器)外的所有组件。

参数
  • X (pd.DataFrame) – 输入训练数据,形状为 [n_samples, n_features]。

  • y (pd.Series) – 目标训练数据,长度为 [n_samples]。

返回

转换后的特征和目标。

返回类型

Tuple (pd.DataFrame, pd.Series)

fit_transform(self, X, y)[source]#

如果所有组件都是 Transformer,则拟合并转换组件图中的所有组件。

参数
  • X (pd.DataFrame) – 输入特征,形状为 [n_samples, n_features]。

  • y (pd.Series) – 目标数据,长度为 [n_samples]。

返回

转换后的输出。

返回类型

pd.DataFrame

抛出

ValueError – 如果最后一个组件是估计器。

classmethod generate_order(cls, component_dict)[source]#

重新生成图的拓扑排序顺序。

get_component(self, component_name)[source]#

从图中检索单个组件对象。

参数

component_name (str) – 要检索的组件名称

返回

ComponentBase object

抛出

ValueError – 如果组件不在图中。

get_component_input_logical_types(self, component_name)[source]#

获取传递给给定组件的逻辑类型。

参数

component_name (str) – 图中的组件名称

返回

Dict - 将特征名称映射到逻辑类型实例。

抛出
  • ValueError – 如果组件不在图中。

  • ValueError – 如果组件图尚未拟合

get_estimators(self)[source]#

获取此图中的所有估计器组件列表。

返回

图中的所有估计器对象。

返回类型

list

抛出

ValueError – 如果组件图尚未实例化。

get_inputs(self, component_name)[source]#

检索给定组件的所有输入。

参数

component_name (str) – 要查找的组件名称。

返回

组件使用的输入列表。

返回类型

list[str]

抛出

ValueError – 如果组件不在图中。

get_last_component(self)[source]#

检索图中最后计算的组件,通常是最终估计器。

返回

ComponentBase object

抛出

ValueError – 如果组件图没有边。

graph(self, name=None, graph_format=None)[source]#

生成表示组件图的图像。

参数
  • name (str) – 图的名称。默认为 None。

  • graph_format (str) – 保存图的文件格式。默认为 None。

返回

可直接在 Jupyter notebook 中显示的图对象。

返回类型

graphviz.Digraph

抛出

RuntimeError – 如果未安装 graphviz。

property has_dfs(self)#

此组件图是否包含 DFSTransformer。

instantiate(self, parameters=None)[source]#

使用给定的参数实例化图中所有未实例化的组件。如果组件已实例化但参数字典包含该组件的参数,则会引发错误。

参数

parameters (dict) – 字典,以组件名称作为键,以该组件参数字典作为值。空字典 {} 或 None 表示使用组件参数的所有默认值。如果组件图中的组件已实例化,则它不会使用此字典中定义的任何参数。默认为 None。

返回

self

抛出

ValueError – 如果组件图已实例化或组件在实例化时出错。

inverse_transform(self, y)[source]#

按逆序将组件的 inverse_transform 方法应用于估计器预测结果。

实现 inverse_transform 的组件包括 PolynomialDecomposer、LogTransformer、LabelEncoder (待定)。

参数

y – (pd.Series):最终组件特征。

返回

应用逆转换后的目标。

返回类型

pd.Series

property last_component_input_logical_types(self)#

获取传递给管道中最后一个组件的逻辑类型。

返回

Dict - 将特征名称映射到逻辑类型实例。

抛出
  • ValueError – 如果组件不在图中。

  • ValueError – 如果组件图尚未拟合

predict(self, X)[source]#

使用选定的特征进行预测。

参数

X (pd.DataFrame) – 输入特征,形状为 [n_samples, n_features]。

返回

预测值。

返回类型

pd.Series

抛出

ValueError – 如果最后一个组件不是估计器。

transform(self, X, y=None)[source]#

使用组件图转换输入。

参数
  • X (pd.DataFrame) – 输入特征,形状为 [n_samples, n_features]。

  • y (pd.Series) – 目标数据,长度为 [n_samples]。默认为 None。

返回

转换后的输出。

返回类型

pd.DataFrame

抛出

ValueError – 如果最后一个组件不是 Transformer。

transform_all_but_final(self, X, y=None)[source]#

转换除最后一个组件外的所有组件,并从任意数量的父组件收集数据,以获取应馈送给最后一个组件的所有信息。

参数
  • X (pd.DataFrame) – 数据,形状为 [n_samples, n_features]。

  • y (pd.Series) – 目标训练数据,长度为 [n_samples]。默认为 None。

返回

转换后的值。

返回类型

pd.DataFrame

evalml.pipelines.component_graph.logger#