Skip to content

Commit dc8dfe9

Browse files
authored
Merge pull request #19 from alteryx/tempo-env-checkmates-refactoring
Tempo env checkmates refactoring
2 parents 514b3cd + 3711bbd commit dc8dfe9

17 files changed

+2348
-6
lines changed

checkmates/exceptions/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@
55
ValidationErrorCode,
66
ObjectiveCreationError,
77
ObjectiveNotFoundError,
8+
MethodPropertyNotFoundError,
9+
ComponentNotYetFittedError,
810
)

checkmates/exceptions/exceptions.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ class ObjectiveNotFoundError(Exception):
1414
pass
1515

1616

17+
class MethodPropertyNotFoundError(Exception):
18+
"""Exception to raise when a class is does not have an expected method or property."""
19+
20+
pass
21+
22+
23+
class ComponentNotYetFittedError(Exception):
24+
"""An exception to be raised when predict/predict_proba/transform is called on a component without fitting first."""
25+
26+
pass
27+
28+
1729
class ObjectiveCreationError(Exception):
1830
"""Exception when get_objective tries to instantiate an objective and required args are not provided."""
1931

checkmates/objectives/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
from checkmates.objectives.objective_base import ObjectiveBase
44
from checkmates.objectives.regression_objective import RegressionObjective
55

6-
from checkmates.objectives.utils import get_objective
7-
from checkmates.objectives.utils import get_default_primary_search_objective
8-
from checkmates.objectives.utils import get_non_core_objectives
9-
from checkmates.objectives.utils import get_core_objectives
6+
from checkmates.objectives.utils import (
7+
get_objective,
8+
get_default_primary_search_objective,
9+
get_non_core_objectives,
10+
get_core_objectives,
11+
get_problem_type,
12+
)
1013

1114

1215
from checkmates.objectives.standard_metrics import RootMeanSquaredLogError

checkmates/objectives/utils.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
"""Utility methods for CheckMates objectives."""
2+
from typing import Optional
3+
4+
import pandas as pd
5+
26
from checkmates import objectives
37
from checkmates.exceptions import ObjectiveCreationError, ObjectiveNotFoundError
48
from checkmates.objectives.objective_base import ObjectiveBase
5-
from checkmates.problem_types import handle_problem_types
9+
from checkmates.problem_types import ProblemTypes, handle_problem_types
610
from checkmates.utils.gen_utils import _get_subclasses
11+
from checkmates.utils.logger import get_logger
12+
13+
logger = get_logger(__file__)
714

815

916
def get_non_core_objectives():
@@ -90,6 +97,35 @@ def get_objective(objective, return_instance=False, **kwargs):
9097
return objective_class
9198

9299

100+
def get_problem_type(
101+
input_problem_type: Optional[str],
102+
target_data: pd.Series,
103+
) -> ProblemTypes:
104+
"""Helper function to determine if classification problem is binary or multiclass dependent on target variable values."""
105+
if not input_problem_type:
106+
raise ValueError("problem type is required")
107+
if input_problem_type.lower() == "classification":
108+
values: pd.Series = target_data.value_counts()
109+
if values.size == 2:
110+
return ProblemTypes.BINARY
111+
elif values.size > 2:
112+
return ProblemTypes.MULTICLASS
113+
else:
114+
message: str = "The target field contains less than two unique values. It cannot be used for modeling."
115+
logger.error(message, exc_info=True)
116+
raise ValueError(message)
117+
118+
if input_problem_type.lower() == "regression":
119+
return ProblemTypes.REGRESSION
120+
121+
if input_problem_type.lower() == "time series regression":
122+
return ProblemTypes.TIME_SERIES_REGRESSION
123+
124+
message = f"Unexpected problem type provided in configuration: {input_problem_type}"
125+
logger.error(message, exc_info=True)
126+
raise ValueError(message)
127+
128+
93129
def get_default_primary_search_objective(problem_type):
94130
"""Get the default primary search objective for a problem type.
95131

checkmates/pipelines/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""General CheckMates pipelines."""
2+
3+
from checkmates.pipelines.component_base_meta import ComponentBaseMeta
4+
from checkmates.pipelines.component_base import ComponentBase
5+
from checkmates.pipelines.transformers import Transformer
6+
from checkmates.pipelines.components import ( # noqa: F401
7+
DropColumns,
8+
DropRowsTransformer,
9+
PerColumnImputer,
10+
TargetImputer,
11+
TimeSeriesImputer,
12+
TimeSeriesRegularizer,
13+
)
14+
from checkmates.pipelines.utils import (
15+
_make_component_list_from_actions,
16+
split_data,
17+
drop_infinity,
18+
)
19+
from checkmates.pipelines.training_validation_split import TrainingValidationSplit

0 commit comments

Comments
 (0)