-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add MetaLearningApproach and its children
- Loading branch information
1 parent
d83aeaa
commit 111ec03
Showing
8 changed files
with
227 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .meta_learning_approach import MetaLearningApproach | ||
from .advise_models_by_nearest_datasets import AdviseModelsByNearestDatasets | ||
from .advise_fedot_pipelines_by_nearest_openml_datasets import AdviseFedotPipelinesByNearestOpenmlDatasets |
66 changes: 66 additions & 0 deletions
66
meta_automl/approaches/advise_fedot_pipelines_by_nearest_openml_datasets.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
from dataclasses import dataclass, field | ||
from typing import Dict | ||
|
||
from golem.core.optimisers.opt_history_objects.opt_history import OptHistory | ||
|
||
from meta_automl.approaches import AdviseModelsByNearestDatasets | ||
from meta_automl.data_preparation.dataset import DatasetBase | ||
from meta_automl.data_preparation.datasets_loaders import OpenMLDatasetsLoader | ||
from meta_automl.data_preparation.meta_features_extractors import PymfeExtractor | ||
from meta_automl.data_preparation.models_loaders import FedotHistoryLoader | ||
from meta_automl.meta_algorithm.datasets_similarity_assessors import KNeighborsBasedSimilarityAssessor | ||
from meta_automl.meta_algorithm.model_advisors import DiverseFEDOTPipelineAdvisor | ||
|
||
|
||
class AdviseFedotPipelinesByNearestOpenmlDatasets(AdviseModelsByNearestDatasets): | ||
@dataclass | ||
class Parameters: | ||
n_best_dataset_models_to_memorize: int | ||
mf_extractor_params: dict = field(default_factory=dict) | ||
assessor_params: dict = field(default_factory=dict) | ||
advisor_params: dict = field(default_factory=dict) | ||
advisor_class = DiverseFEDOTPipelineAdvisor | ||
|
||
@dataclass | ||
class Components: | ||
datasets_loader: OpenMLDatasetsLoader = None | ||
models_loader: FedotHistoryLoader = None | ||
meta_features_extractor: PymfeExtractor = None | ||
datasets_similarity_assessor: KNeighborsBasedSimilarityAssessor = None | ||
model_advisor: DiverseFEDOTPipelineAdvisor = None | ||
|
||
def __init__(self, n_best_dataset_models_to_memorize: int, | ||
mf_extractor_params: dict, assessor_params: dict, advisor_params: dict): | ||
super().__init__( | ||
n_best_dataset_models_to_memorize=n_best_dataset_models_to_memorize, | ||
mf_extractor_params=mf_extractor_params, | ||
assessor_params=assessor_params, | ||
advisor_params=advisor_params, | ||
) | ||
self.components.datasets_loader = OpenMLDatasetsLoader() | ||
|
||
def fit(self, histories_per_dataset: Dict[DatasetBase, OptHistory]): | ||
params = self.parameters | ||
self.load_datasets_and_models(histories_per_dataset) | ||
self.extract_train_meta_features(**params.mf_extractor_params) | ||
self.fit_datasets_similarity_assessor(**params.assessor_params) | ||
self.fit_model_advisor(**params.advisor_params) | ||
|
||
def load_datasets_and_models(self, histories_per_dataset): | ||
self.data.datasets = list(histories_per_dataset.keys()) | ||
self.components.models_loader = FedotHistoryLoader() | ||
best_models = self.components.models_loader.load( | ||
*zip(*histories_per_dataset.items()), | ||
self.parameters.n_best_dataset_models_to_memorize | ||
) | ||
best_models_per_dataset_id = {dataset.id_: models for dataset, models in | ||
zip(histories_per_dataset.keys(), best_models)} | ||
self.data.best_models_per_dataset_id = best_models_per_dataset_id | ||
|
||
def extract_train_meta_features(self, **mf_extractor_params): | ||
self.components.meta_features_extractor = PymfeExtractor(extractor_params=mf_extractor_params, | ||
datasets_loader=self.components.datasets_loader) | ||
meta_features_train = self.components.meta_features_extractor.extract( | ||
self.data.datasets, fill_input_nans=True) | ||
meta_features_train = meta_features_train.fillna(0) | ||
self.data.meta_features = meta_features_train |
Oops, something went wrong.