component_graph

Component graph for a pipeline as a directed acyclic graph (DAG).

Module Contents

Classes Summary

ComponentGraph

Component graph for a pipeline as a directed acyclic graph (DAG).

Attributes Summary

logger

Contents

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

Component graph for a pipeline as a directed acyclic graph (DAG).

Parameters
  • component_dict (dict) – A dictionary which specifies the components and edges between components that should be used to create the component graph. Defaults to None.

  • random_seed (int) – Seed for the random number generator. Defaults to 0.

Example

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

Methods

compute_final_component_features

Transform all components save the final one, and gathers the data from any number of parents to get all the information that should be fed to the final component.

compute_order

The order that components will be computed or called in.

default_parameters

The default parameter dictionary for this pipeline.

describe

Outputs component graph details including component parameters.

fit

Fit each component in the graph.

fit_features

Fit all components save the final one, usually an estimator.

generate_order

Regenerated the topologically sorted order of the graph.

get_component

Retrieves a single component object from the graph.

get_estimators

Gets a list of all the estimator components within this graph.

get_inputs

Retrieves all inputs for a given component.

get_last_component

Retrieves the component that is computed last in the graph, usually the final estimator.

graph

Generate an image representing the component graph.

instantiate

Instantiates all uninstantiated components within the graph using the given parameters. An error will be raised if a component is already instantiated but the parameters dict contains arguments for that component.

inverse_transform

Apply component inverse_transform methods to estimator predictions in reverse order.

predict

Make predictions using selected features.

transform

Transform the input using the component graph.

compute_final_component_features(self, X, y=None)[source]

Transform all components save the final one, and gathers the data from any number of parents to get all the information that should be fed to the final component.

Parameters
  • X (pd.DataFrame) – Data of shape [n_samples, n_features].

  • y (pd.Series) – The target training data of length [n_samples]. Defaults to None.

Returns

Transformed values.

Return type

pd.DataFrame

property compute_order(self)

The order that components will be computed or called in.

property default_parameters(self)

The default parameter dictionary for this pipeline.

Returns

Dictionary of all component default parameters.

Return type

dict

describe(self, return_dict=False)[source]

Outputs component graph details including component parameters.

Parameters

return_dict (bool) – If True, return dictionary of information about component graph. Defaults to False.

Returns

Dictionary of all component parameters if return_dict is True, else None

Return type

dict

fit(self, X, y)[source]

Fit each component in the graph.

Parameters
  • X (pd.DataFrame) – The input training data of shape [n_samples, n_features].

  • y (pd.Series) – The target training data of length [n_samples].

Returns

self

fit_features(self, X, y)[source]

Fit all components save the final one, usually an estimator.

Parameters
  • X (pd.DataFrame) – The input training data of shape [n_samples, n_features].

  • y (pd.Series) – The target training data of length [n_samples].

Returns

Transformed features and target.

Return type

Tuple (pd.DataFrame, pd.Series)

classmethod generate_order(cls, component_dict)[source]

Regenerated the topologically sorted order of the graph.

get_component(self, component_name)[source]

Retrieves a single component object from the graph.

Parameters

component_name (str) – Name of the component to retrieve

Returns

ComponentBase object

Raises

ValueError – If the component is not in the graph.

get_estimators(self)[source]

Gets a list of all the estimator components within this graph.

Returns

All estimator objects within the graph.

Return type

list

Raises

ValueError – If the component graph is not yet instantiated.

get_inputs(self, component_name)[source]

Retrieves all inputs for a given component.

Parameters

component_name (str) – Name of the component to look up.

Returns

List of inputs for the component to use.

Return type

list[str]

Raises

ValueError – If the component is not in the graph.

get_last_component(self)[source]

Retrieves the component that is computed last in the graph, usually the final estimator.

Returns

ComponentBase object

Raises

ValueError – If the component graph has no edges.

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

Generate an image representing the component graph.

Parameters
  • name (str) – Name of the graph. Defaults to None.

  • graph_format (str) – file format to save the graph in. Defaults to None.

Returns

Graph object that can be directly displayed in Jupyter notebooks.

Return type

graphviz.Digraph

Raises

RuntimeError – If graphviz is not installed.

instantiate(self, parameters=None)[source]

Instantiates all uninstantiated components within the graph using the given parameters. An error will be raised if a component is already instantiated but the parameters dict contains arguments for that component.

Parameters

parameters (dict) – Dictionary with component names as keys and dictionary of that component’s parameters as values. An empty dictionary {} or None implies using all default values for component parameters. If a component in the component graph is already instantiated, it will not use any of its parameters defined in this dictionary. Defaults to None.

Returns

self

Raises

ValueError – If component graph is already instantiated or if a component errored while instantiating.

inverse_transform(self, y)[source]

Apply component inverse_transform methods to estimator predictions in reverse order.

Components that implement inverse_transform are PolynomialDetrender, LabelEncoder (tbd).

Parameters

y – (pd.Series): Final component features.

Returns

The target with inverse transformation applied.

Return type

pd.Series

predict(self, X)[source]

Make predictions using selected features.

Parameters

X (pd.DataFrame) – Input features of shape [n_samples, n_features].

Returns

Predicted values.

Return type

pd.Series

Raises

ValueError – If final component is not an Estimator.

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

Transform the input using the component graph.

Parameters
  • X (pd.DataFrame) – Input features of shape [n_samples, n_features].

  • y (pd.Series) – The target data of length [n_samples]. Defaults to None.

Returns

Transformed output.

Return type

pd.DataFrame

Raises

ValueError – If final component is not a Transformer.

evalml.pipelines.component_graph.logger