Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tempo env checkmates refactoring #19

Merged
merged 3 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions checkmates/exceptions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
ValidationErrorCode,
ObjectiveCreationError,
ObjectiveNotFoundError,
MethodPropertyNotFoundError,
ComponentNotYetFittedError,
)
12 changes: 12 additions & 0 deletions checkmates/exceptions/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ class ObjectiveNotFoundError(Exception):
pass


class MethodPropertyNotFoundError(Exception):
"""Exception to raise when a class is does not have an expected method or property."""

pass


class ComponentNotYetFittedError(Exception):
"""An exception to be raised when predict/predict_proba/transform is called on a component without fitting first."""

pass


class ObjectiveCreationError(Exception):
"""Exception when get_objective tries to instantiate an objective and required args are not provided."""

Expand Down
11 changes: 7 additions & 4 deletions checkmates/objectives/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
from checkmates.objectives.objective_base import ObjectiveBase
from checkmates.objectives.regression_objective import RegressionObjective

from checkmates.objectives.utils import get_objective
from checkmates.objectives.utils import get_default_primary_search_objective
from checkmates.objectives.utils import get_non_core_objectives
from checkmates.objectives.utils import get_core_objectives
from checkmates.objectives.utils import (
get_objective,
get_default_primary_search_objective,
get_non_core_objectives,
get_core_objectives,
get_problem_type,
)


from checkmates.objectives.standard_metrics import RootMeanSquaredLogError
Expand Down
38 changes: 37 additions & 1 deletion checkmates/objectives/utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
"""Utility methods for CheckMates objectives."""
from typing import Optional

import pandas as pd

from checkmates import objectives
from checkmates.exceptions import ObjectiveCreationError, ObjectiveNotFoundError
from checkmates.objectives.objective_base import ObjectiveBase
from checkmates.problem_types import handle_problem_types
from checkmates.problem_types import ProblemTypes, handle_problem_types
from checkmates.utils.gen_utils import _get_subclasses
from checkmates.utils.logger import get_logger

logger = get_logger(__file__)


def get_non_core_objectives():
Expand Down Expand Up @@ -90,6 +97,35 @@ def get_objective(objective, return_instance=False, **kwargs):
return objective_class


def get_problem_type(
input_problem_type: Optional[str],
target_data: pd.Series,
) -> ProblemTypes:
"""Helper function to determine if classification problem is binary or multiclass dependent on target variable values."""
if not input_problem_type:
raise ValueError("problem type is required")
if input_problem_type.lower() == "classification":
values: pd.Series = target_data.value_counts()
if values.size == 2:
return ProblemTypes.BINARY
elif values.size > 2:
return ProblemTypes.MULTICLASS
else:
message: str = "The target field contains less than two unique values. It cannot be used for modeling."
logger.error(message, exc_info=True)
raise ValueError(message)

if input_problem_type.lower() == "regression":
return ProblemTypes.REGRESSION

if input_problem_type.lower() == "time series regression":
return ProblemTypes.TIME_SERIES_REGRESSION

message = f"Unexpected problem type provided in configuration: {input_problem_type}"
logger.error(message, exc_info=True)
raise ValueError(message)


def get_default_primary_search_objective(problem_type):
"""Get the default primary search objective for a problem type.

Expand Down
19 changes: 19 additions & 0 deletions checkmates/pipelines/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""General CheckMates pipelines."""

from checkmates.pipelines.component_base_meta import ComponentBaseMeta
from checkmates.pipelines.component_base import ComponentBase
from checkmates.pipelines.transformers import Transformer
from checkmates.pipelines.components import ( # noqa: F401
DropColumns,
DropRowsTransformer,
PerColumnImputer,
TargetImputer,
TimeSeriesImputer,
TimeSeriesRegularizer,
)
from checkmates.pipelines.utils import (
_make_component_list_from_actions,
split_data,
drop_infinity,
)
from checkmates.pipelines.training_validation_split import TrainingValidationSplit
Loading
Loading