AutoML Algorithm Upgrade: fit-caching
- Vorherrschende Sprache
- Python
- Sterne
- 850
- Forks
- 96
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
https://alteryx.quip.com/CDiuAtU8WpUc/AutoML-Upgrade-Design-Doc
* Add fit-caching to component graph (2 weeks)
* training data validation through ww schema or pandas data frame hashing (joblib.hash)
* add to fit method of ComponentGraph
* potentially use _post_evaluation_callback for parallel case
* not added to search yet
* demonstrate performance impact through testing (notebook will suffice)
Potential implementation:
Add component_cache to AutoMLSearch and then pass down to the engine and its methods as part of automl_config
```
def train_and_score_pipeline(pipeline, automl_config, full_X_train, full_y_train, logger):
...
for i, (train, valid) in enumerate(automl_config.data_splitter.split(full_X_train, full_y_train)): try:
logger.debug(f"\t\t\tFold {i}: starting training")
cv_pipeline = train_pipeline(pipeline,
X_train,
y_train,
automl_config.optimize_thresholds,
automl_config.objective,
automl_config.component_cache)
for component in cv_pipeline:
if component.name not in automl_config.component_cache:
automl_config.component_cache[component.name] = component
...
return {"scores": {'cv_data': cv_data, 'training_time': training_time, 'cv_scores': cv_scores, 'cv_score_mean': cv_score_mean},
"pipeline": cv_pipeline,
"logger": logger}
```
```
class ComponentGraph:
def fit(self, X, y, component_cache=None):
X = infer_feature_types(X)
self._compute_features(self.compute_order, X, y,
fit=True, component_cache=component_cache)
self._feature_provenance = self._get_feature_provenance(X.columns)
return self
def _in_component_cache(self, X=None, y=None, component_cache=None):
# if all none:
return None
# check if X and y is same as cache
if not:
return None
# check if component in cache:
if not:
return None
else:
return component_cache[component]
def _compute_features(self, component_list, X, y=None, fit=False):
"""Transforms the data by applying the given components.
Arguments:
component_list (list): The list of component names to compute.
X (pd.DataFrame): Input data to the pipeline to transform.
y (pd.Series): The target training data of length [n_samples]
fit (bool): Whether to fit the estimators as well as transform it.
Defaults to False.
Returns:
dict: Outputs from each component
"""
X = infer_feature_types(X)
most_recent_y = y
if len(component_list) == 0:
return X
output_cache = {}
for component_name in component_list:
...
cached_component = self._in_component_cache()
if isinstance(component_instance, Transformer):
if fit and not cached_component:
output = component_instance.fit_transform(input_x, input_y)
elif fit and cached_component:
output = cached_component.transform(input_x, input_y)
else:
output = component_instance.transform(input_x, input_y)
if isinstance(output, tuple):
output_x, output_y = output[0], output[1]
most_recent_y = output_y
else:
output_x = output
output_y = None
output_cache[f"{component_name}.x"] = output_x
output_cache[f"{component_name}.y"] = output_y
else:
if fit and not cached_component:
component_instance.fit(input_x, input_y)
component_instance = cached_component if cached_component else component_instance
if not (fit and component_name == self.compute_order[-1]): # Don't call predict on the final component during fit
output = component_instance.predict(input_x)
else:
output = None
output_cache[component_name] = output
return output_cache
```
Beitragsleitfaden
Bewertung
Dieses Issue wurde noch nicht bewertet.