Skip to content

Commit 5d5a018

Browse files
committed
chore: rm bagging operation
1 parent 0cd7f05 commit 5d5a018

File tree

15 files changed

+417
-20
lines changed

15 files changed

+417
-20
lines changed

docs/source/introduction/fedot_features/automation_features.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,13 @@ FEDOT supports bunch of dimensionality preprocessing operations that can be be a
7070
`label_encoding`,Label Encoder, Feature encoding
7171
`resample`,Imbalanced binary class transformation in classification, Data transformation
7272
`topological_features`,Calculation of topological features,Time series transformation
73+
`dummy`,Simple forwarding operator in pipeline, Data forwarding
7374

7475

7576
.. csv-table:: Feature transformation operations implementations
7677
:header: "API name","Model used","Presets"
7778

78-
`rfe_lin_reg`,`sklearn.feature_selection.RFE`,
79+
`rfe_lin_reg`,`sklearn.feature_selection.RFE`,
7980
`rfe_non_lin_reg`,`sklearn.feature_selection.RFE`,
8081
`rfe_lin_class`,`sklearn.feature_selection.RFE`,
8182
`rfe_non_lin_class`,`sklearn.feature_selection.RFE`,
@@ -107,13 +108,14 @@ FEDOT supports bunch of dimensionality preprocessing operations that can be be a
107108
`resample`,`FEDOT model using sklearn.utils.resample`,
108109
`topological_features`,FEDOT model,`ts`,
109110
`fast_topological_features`,FEDOT model,`ts`
111+
`dummy`,FEDOT model,`fast_train` `*tree`
110112

111113

112114
Models used
113115
^^^^^^^^^^^
114116

115117
Using the parameter ``preset`` of the :doc:`main API </api/api>` you can specify
116-
what models are available during the learning process.
118+
what models are available during the learning process.
117119

118120
It influences:
119121

@@ -135,6 +137,7 @@ Apart from that there are other options whose names speak for themselves: ``'sta
135137
:header: "API name","Definition","Problem"
136138

137139
`adareg`,AdaBoost regressor,Regression
140+
`blendreg`, Weighted Average Blending,Regression
138141
`catboostreg`,Catboost regressor,Regression
139142
`dtreg`,Decision Tree regressor,Regression
140143
`gbr`,Gradient Boosting regressor,Regression
@@ -149,6 +152,7 @@ Apart from that there are other options whose names speak for themselves: ``'sta
149152
`treg`,Extra Trees regressor,Regression
150153
`xgboostreg`,Extreme Gradient Boosting regressor,Regression
151154
`bernb`,Naive Bayes classifier (multivariate Bernoulli),Classification
155+
`blending`, Weighted Average Blending,Classification
152156
`catboost`,Catboost classifier,Classification
153157
`cnn`,Convolutional Neural Network,Classification
154158
`dt`,Decision Tree classifier,Classification
@@ -179,6 +183,7 @@ Apart from that there are other options whose names speak for themselves: ``'sta
179183
:header: "API name","Model used","Presets"
180184

181185
`adareg`,`sklearn.ensemble.AdaBoostRegressor`,`fast_train` `ts` `*tree`
186+
`blendreg`, `FEDOT model`, `*tree`
182187
`catboostreg`,`catboost.CatBoostRegressor`,`*tree`
183188
`dtreg`,`sklearn.tree.DecisionTreeRegressor`,`fast_train` `ts` `*tree`
184189
`gbr`,`sklearn.ensemble.GradientBoostingRegressor`,`*tree`
@@ -193,6 +198,7 @@ Apart from that there are other options whose names speak for themselves: ``'sta
193198
`treg`,`sklearn.ensemble.ExtraTreesRegressor`,`*tree`
194199
`xgboostreg`,`xgboost.XGBRegressor`,`*tree`
195200
`bernb`,`sklearn.naive_bayes.BernoulliNB`,`fast_train`
201+
`blending`, `FEDOT model`, `*tree`
196202
`catboost`,`catboost.CatBoostClassifier`,`*tree`
197203
`cnn`,`FEDOT model`,
198204
`dt`,`sklearn.tree.DecisionTreeClassifier`,`fast_train` `*tree`

fedot/api/builder.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,13 @@ def setup_pipeline_structure(
274274
- ``arima`` -> ARIMA
275275
- ``cgru`` -> Convolutional Gated Recurrent Unit
276276
- ``bernb`` -> Naive Bayes Classifier (multivariate Bernoulli)
277+
- ``blending`` -> Weighted Average Blending Classifier
278+
- ``blendreg`` -> Weighted Average Blending Regressor
277279
- ``catboost`` -> Catboost Classifier
278280
- ``catboostreg`` -> Catboost Regressor
279281
- ``dt`` -> Decision Tree Classifier
280282
- ``dtreg`` -> Decision Tree Regressor
283+
- ``dummy`` -> Data Forwarding Operator in Pipeline
281284
- ``gbr`` -> Gradient Boosting Regressor
282285
- ``kmeans`` -> K-Means clustering
283286
- ``knn`` -> K-nearest neighbors Classifier
@@ -305,7 +308,7 @@ def setup_pipeline_structure(
305308
- ``svr`` -> Linear Support Vector Regressor
306309
- ``treg`` -> Extra Trees Regressor
307310
- ``xgboost`` -> Extreme Gradient Boosting Classifier
308-
- ``xgbreg`` -> Extreme Gradient Boosting Regressor
311+
- ``xgboostreg`` -> Extreme Gradient Boosting Regressor
309312
- ``cnn`` -> Convolutional Neural Network
310313
- ``scaling`` -> Scaling
311314
- ``normalization`` -> Normalization

fedot/core/operations/evaluation/boostings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ def predict(self, trained_operation, predict_data: InputData) -> OutputData:
6969
is_multi_output_target = is_multi_output_task(predict_data)
7070

7171
prediction = trained_operation.predict_proba(predict_data)
72+
if isinstance(prediction, OutputData):
73+
prediction = prediction.predict
7274
is_prediction_correct = self._check_prediction_correctness(prediction)
7375

7476
if n_classes < 2:

fedot/core/operations/evaluation/common_preprocessing.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
from fedot.core.operations.evaluation.operation_implementations. \
1212
data_operations.topological.fast_topological_extractor import \
1313
TopologicalFeaturesImplementation
14+
from fedot.core.operations.evaluation.operation_implementations.data_operations.data_forward import \
15+
DummyOperationImplementation
1416
from fedot.core.operations.operation_parameters import OperationParameters
1517
from fedot.utilities.random import ImplementationRandomStateHandler
1618

@@ -34,6 +36,7 @@ class FedotPreprocessingStrategy(EvaluationStrategy):
3436
- ``one_hot_encoding``-> OneHotEncodingImplementation,
3537
- ``label_encoding``-> LabelEncodingImplementation,
3638
- ``fast_ica``-> FastICAImplementation
39+
- ``dummy`` -> DummyOperationImplementation
3740
3841
params: hyperparameters to fit the operation with
3942
@@ -50,7 +53,8 @@ class FedotPreprocessingStrategy(EvaluationStrategy):
5053
'one_hot_encoding': OneHotEncodingImplementation,
5154
'label_encoding': LabelEncodingImplementation,
5255
'fast_ica': FastICAImplementation,
53-
'topological_features': TopologicalFeaturesImplementation
56+
'topological_features': TopologicalFeaturesImplementation,
57+
'dummy': DummyOperationImplementation
5458
}
5559

5660
def __init__(self, operation_type: str, params: Optional[OperationParameters] = None):
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import numpy as np
2+
from typing import Optional
3+
from abc import abstractmethod
4+
5+
from fedot.core.data.data import InputData, OutputData
6+
from fedot.core.operations.evaluation.operation_implementations.models.blending import (
7+
BlendingClassifier, BlendingRegressor
8+
)
9+
from fedot.core.operations.evaluation.evaluation_interfaces import EvaluationStrategy
10+
from fedot.core.operations.operation_parameters import OperationParameters
11+
from fedot.core.operations.evaluation.evaluation_interfaces import is_multi_output_task
12+
from fedot.utilities.custom_errors import AbstractMethodNotImplementError
13+
from fedot.utilities.random import ImplementationRandomStateHandler
14+
15+
16+
class EnsembleStrategy(EvaluationStrategy):
17+
"""This class defines the certain operation implementation for the ensemble methods
18+
19+
Args:
20+
operation_type: ``str`` of the operation defined in operation or
21+
data operation repositories
22+
23+
.. details:: possible operations:
24+
25+
- ``blending`` -> BlendingClassifier
26+
- ``blendreg`` -> BlendingRegressor
27+
28+
params: hyperparameters to fit the operation with
29+
"""
30+
_operations_by_types = {
31+
'blending': BlendingClassifier,
32+
'blendreg': BlendingRegressor
33+
}
34+
35+
def __init__(self, operation_type: str, params: Optional[OperationParameters] = None):
36+
self.operation_impl = self._convert_to_operation(operation_type)
37+
super().__init__(operation_type, params)
38+
39+
def fit(self, train_data: InputData):
40+
if is_multi_output_task(train_data):
41+
raise ValueError('Ensemble methods temporary do not support multi-output tasks.')
42+
43+
operation_implementation = self.operation_impl(self.params_for_fit)
44+
45+
with ImplementationRandomStateHandler(implementation=operation_implementation):
46+
operation_implementation.fit(train_data)
47+
48+
return operation_implementation
49+
50+
@abstractmethod
51+
def predict(self, trained_operation, predict_data: InputData) -> OutputData:
52+
"""This method used for prediction of the target data
53+
54+
Args:
55+
trained_operation: operation object
56+
predict_data: data to predict
57+
58+
Returns:
59+
passed data with new predicted target
60+
"""
61+
raise AbstractMethodNotImplementError
62+
63+
64+
class EnsembleClassificationStrategy(EnsembleStrategy):
65+
def __init__(self, operation_type: str, params: Optional[OperationParameters] = None):
66+
super().__init__(operation_type, params)
67+
68+
def predict(self, trained_operation, predict_data: InputData) -> OutputData:
69+
if self.output_mode == 'labels':
70+
prediction = trained_operation.predict(predict_data)
71+
elif self.output_mode in ['probs', 'full_probs', 'default']:
72+
n_classes = len(trained_operation.classes_)
73+
prediction = trained_operation.predict_proba(predict_data).predict
74+
# Full probs for binary classification
75+
if self.output_mode == 'full_probs' and n_classes == 2 and prediction.shape[1] == 1:
76+
prediction = np.hstack([1 - prediction, prediction])
77+
else:
78+
raise ValueError(f'Output mode {self.output_mode} is not supported')
79+
80+
return self._convert_to_output(prediction, predict_data)
81+
82+
83+
class EnsembleRegressionStrategy(EnsembleStrategy):
84+
def __init__(self, operation_type: str, params: Optional[OperationParameters] = None):
85+
super().__init__(operation_type, params)
86+
87+
def predict(self, trained_operation, predict_data: InputData, **kwargs) -> OutputData:
88+
prediction = trained_operation.predict(predict_data, **kwargs)
89+
return self._convert_to_output(prediction, predict_data)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from typing import Optional
2+
3+
from fedot.core.data.data import InputData, OutputData
4+
from fedot.core.operations.evaluation.operation_implementations. \
5+
implementation_interfaces import DataOperationImplementation
6+
from fedot.core.operations.operation_parameters import OperationParameters
7+
8+
9+
class DummyOperationImplementation(DataOperationImplementation):
10+
""" Dummy class for data forwarding """
11+
12+
def __init__(self, params: Optional[OperationParameters]):
13+
super().__init__(params)
14+
15+
def fit(self, input_data: InputData):
16+
"""
17+
Dummy operation doesn't support fit method
18+
"""
19+
pass
20+
21+
def transform(self, input_data: InputData) -> OutputData:
22+
"""
23+
Method for forwarding input_data's features
24+
:param input_data: data with features, target and ids
25+
26+
:return input_data: data with the same features
27+
"""
28+
features = input_data.features
29+
output_data = self._convert_to_output(input_data, features)
30+
return output_data

fedot/core/operations/evaluation/operation_implementations/data_operations/topological/fast_topological_extractor.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import logging
23
from itertools import chain
34
from typing import Optional
@@ -7,9 +8,12 @@
78
try:
89
from gph import ripser_parallel as ripser
910
except ModuleNotFoundError:
10-
logging.log(100,
11-
"Topological features operation requires extra dependencies for time series forecasting, which are not"
12-
" installed. It can infuence the performance. Please install it by 'pip install fedot[extra]'")
11+
if not os.environ.get('FEDOT_RIPSER_WARNING_SHOWN'):
12+
logging.log(100,
13+
"Topological features operation requires extra dependencies for time series forecasting, "
14+
"which are not installed. It can influence the performance. "
15+
"Please install it by 'pip install fedot[extra]'")
16+
os.environ['FEDOT_RIPSER_WARNING_SHOWN'] = '1'
1317

1418
from joblib import Parallel, delayed
1519

0 commit comments

Comments
 (0)