Skip to content

Commit

Permalink
Change names of primitive types
Browse files Browse the repository at this point in the history
  • Loading branch information
roquelopez committed Mar 15, 2024
1 parent b98d41a commit d71eecc
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 38 deletions.
16 changes: 1 addition & 15 deletions alpha_automl/builtin_primitives/semisupervised_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
from sklearn.preprocessing import FunctionTransformer
from sklearn.semi_supervised import (
LabelPropagation,
LabelSpreading,
SelfTrainingClassifier,
LabelSpreading
)

from alpha_automl.base_primitive import BasePrimitive
Expand All @@ -19,19 +18,6 @@
logger = logging.getLogger(__name__)


class SkSelfTrainingClassifier(BasePrimitive):
sdg_params = dict(alpha=1e-5, penalty="l2", loss="log_loss")
model = SelfTrainingClassifier(SGDClassifier(**sdg_params), verbose=True)

def fit(self, X, y=None):
self.model.fit(X, y)

def predict(self, X):
pred = self.model.predict(X)

return np.array(pred)


def make_label_pipeline(method, X):
step = None
if method == "LabelSpreading":
Expand Down
8 changes: 4 additions & 4 deletions alpha_automl/pipeline_synthesis/pipeline_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ def change_default_hyperparams(primitive_object):
def extract_estimators(pipeline_primitives, all_primitives):
estimators = []
classifier_name, classifier_obj = pipeline_primitives.pop()
primitive_type_tmp = all_primitives[classifier_name]['type']
current_primitive_type = all_primitives[classifier_name]['type']
counter = 0

while primitive_type_tmp == 'CLASSIFIER':
while current_primitive_type == 'CLASSIFIER':
estimators.append((f'{classifier_name}-{counter}', classifier_obj))
classifier_name, classifier_obj = pipeline_primitives.pop()
primitive_type_tmp = all_primitives[classifier_name]['type']
current_primitive_type = all_primitives[classifier_name]['type']
counter += 1

return estimators
Expand Down Expand Up @@ -88,7 +88,7 @@ def make_primitive_objects(self, primitives):
for primitive_name in primitives:
primitive_type = self.all_primitives[primitive_name]['type']

if primitive_type == 'SEMISUPERVISED_CLASSIFIER':
if primitive_type == 'SEMISUPERVISED_SELFTRAINER':
classifier_obj = pipeline_primitives.pop()[1]
primitive_object = create_object(primitive_name, {'base_estimator': classifier_obj})
elif primitive_type == 'SINGLE_ENSEMBLER':
Expand Down
11 changes: 6 additions & 5 deletions alpha_automl/resource/base_grammar.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ S -> CLASSIFICATION_TASK | REGRESSION_TASK | CLUSTERING_TASK | TIME_SERIES_FOREC
CLASSIFICATION_TASK -> IMPUTER ENCODERS FEATURE_SCALER FEATURE_SELECTOR CLASSIFIER ENSEMBLER
REGRESSION_TASK -> IMPUTER ENCODERS FEATURE_SCALER FEATURE_SELECTOR REGRESSOR
CLUSTERING_TASK -> IMPUTER ENCODERS FEATURE_SCALER FEATURE_SELECTOR CLUSTERER
TIME_SERIES_FORECAST_TASK -> REGRESSION_TASK | IMPUTER TIME_SERIES_FORECAST
SEMISUPERVISED_TASK -> IMPUTER ENCODERS FEATURE_SCALER CLASSIFIER SEMISUPERVISED_CLASSIFIER | IMPUTER ENCODERS FEATURE_SCALER LABELPROPAGATION_CLASSIFIER
TIME_SERIES_FORECAST_TASK -> IMPUTER TIME_SERIES_FORECASTER | REGRESSION_TASK
SEMISUPERVISED_TASK -> IMPUTER ENCODERS FEATURE_SCALER SEMISUPERVISED_CLASSIFIER
NA_TASK -> CLASSIFICATION_TASK | REGRESSION_TASK | SEMISUPERVISED_TASK
ENCODERS -> TEXT_ENCODER DATETIME_ENCODER CATEGORICAL_ENCODER IMAGE_ENCODER
ENSEMBLER -> SINGLE_ENSEMBLER | CLASSIFIER CLASSIFIER MULTI_ENSEMBLER | E
SEMISUPERVISED_CLASSIFIER -> CLASSIFIER SEMISUPERVISED_SELFTRAINER| SEMISUPERVISED_LABELPROPAGATOR
IMPUTER -> 'primitive_terminal'
FEATURE_SCALER -> 'primitive_terminal' | 'E'
FEATURE_SELECTOR -> 'primitive_terminal' | 'E'
Expand All @@ -19,6 +20,6 @@ MULTI_ENSEMBLER -> 'primitive_terminal'
CLASSIFIER -> 'primitive_terminal'
REGRESSOR -> 'primitive_terminal'
CLUSTERER -> 'primitive_terminal'
TIME_SERIES_FORECAST -> 'primitive_terminal'
SEMISUPERVISED_CLASSIFIER -> 'primitive_terminal'
LABELPROPAGATION_CLASSIFIER -> 'primitive_terminal'
TIME_SERIES_FORECASTER -> 'primitive_terminal'
SEMISUPERVISED_SELFTRAINER -> 'primitive_terminal'
SEMISUPERVISED_LABELPROPAGATOR -> 'primitive_terminal'
6 changes: 3 additions & 3 deletions alpha_automl/resource/primitives_hierarchy.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,17 @@
"COLUMN_TRANSFORMER": [
"sklearn.compose.ColumnTransformer"
],
"TIME_SERIES_FORECAST": [
"TIME_SERIES_FORECASTER": [
"alpha_automl.builtin_primitives.time_series_forecasting.ArimaEstimator",
"alpha_automl.builtin_primitives.time_series_forecasting.DeeparEstimator",
"alpha_automl.builtin_primitives.time_series_forecasting.NBEATSEstimator",
"alpha_automl.builtin_primitives.time_series_forecasting.NHITSEstimator"
],
"SEMISUPERVISED_CLASSIFIER": [
"SEMISUPERVISED_SELFTRAINER": [
"alpha_automl.builtin_primitives.semisupervised_classifier.AutonBox",
"sklearn.semi_supervised.SelfTrainingClassifier"
],
"LABELPROPAGATION_CLASSIFIER": [
"SEMISUPERVISED_LABELPROPAGATOR": [
"alpha_automl.builtin_primitives.semisupervised_classifier.SkLabelSpreading",
"alpha_automl.builtin_primitives.semisupervised_classifier.SkLabelPropagation"
],
Expand Down
2 changes: 1 addition & 1 deletion alpha_automl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def make_d3m_pipelines(pipelines, new_primitives, metric, ordering_sign, source_
cur_step_idx = add_d3m_step(steps_in_type, cur_step_idx, prev_list, new_prev_list, new_pipeline)
prev_list = new_prev_list

if all_primitive_types[step_id] == 'SEMISUPERVISED_CLASSIFIER':
if all_primitive_types[step_id] == 'SEMISUPERVISED_SELFTRAINER':
classifier_object = step_object.base_estimator
classifier_path = f'classifier.{classifier_object.__class__.__name__}'
for primitive_name, primitive_type in all_primitive_types.items():
Expand Down
11 changes: 1 addition & 10 deletions tests/test_semisupervised.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
from alpha_automl.builtin_primitives.semisupervised_classifier import (
AutonBox,
SkLabelPropagation,
SkLabelSpreading,
SkSelfTrainingClassifier,
SkLabelSpreading
)


Expand Down Expand Up @@ -50,14 +49,6 @@ class TestSemiSupervisedClassifier:
)
X = st_pipeline.fit_transform(X)

def test_self_training_classifier(self):
encoder = SkSelfTrainingClassifier()

encoder.fit(self.X, self.y)
pred = encoder.predict(self.X)
print(pred, self.y)
assert pred[0] == 0

def test_label_spreading(self):
encoder = SkLabelSpreading()
encoder.fit(self.X, self.y)
Expand Down

0 comments on commit d71eecc

Please sign in to comment.