mlm_insights.tests.test_types.predicate_based_tests package

Subpackages

Submodules

mlm_insights.tests.test_types.predicate_based_tests.test_deviation module

class mlm_insights.tests.test_types.predicate_based_tests.test_deviation.DeviationInfo(value: int | float, deviation: float)

Bases: object

deviation: float
to_string() str
value: int | float
class mlm_insights.tests.test_types.predicate_based_tests.test_deviation.TestDeviation(user_defined_tags: ~typing.Dict[str, str] = <factory>, lhs: ~mlm_insights.tests.selectors.interfaces.selector_base.SelectorBase | int | str | float | bool | ~typing.List[~typing.Any] | ~typing.Tuple[int, int] | None = None, rhs: ~mlm_insights.tests.selectors.interfaces.selector_base.SelectorBase | int | str | float | bool | ~typing.List[~typing.Any] | ~typing.Tuple[int, int] | None = None, deviation_threshold: float = 0.1)

Bases: PredicateBasedTestBase

Test if the deviation between two values is within threshold. Both lhs and rhs must be either a numerical value (float, int) or a selector that must return a numerical value.

Configuration

deviation_thresholdfloat

The threshold value that should be used to compare. By default, this 10% or 0.1.

Example - Using Insights Test Builder API

test_builder = InsightsTestBuilder()
    .with_context(test_context=get_test_context())
    .add_test(TestDeviation(
        lhs=FeatureMetricSelector(
            profile_source=ProfileSource.CURRENT, feature_name="LotArea", metric_key="Mean"),
        rhs=100),
        deviation_threshold = 0.3)
test_runner = test_builder.build()
test_result = test_runner.run()

Example - Using Insights Configuration

{
    "test_config": {
        "feature_metric_tests": [
            {
                "feature_name": "feature_a",
                "tests": [
                    {
                        "test_name": "TestDeviation",
                        "metric_key": "Min",
                        "threshold_value": 7500,
                        "config": {
                            "deviation_threshold": 0.3
                        }
                    }
                ]
            }
        ]
}
deviation_threshold: float = 0.1
execute(test_context: TestContext, *args: Any, **kwargs: Any) TestResult

Execute the test and return the TestResult. It uses TestContext to query required metric data.

Parameters

test_context : TestContext

Returns

TestResult

validate(test_context: TestContext, *args: Any, **kwargs: Any) TestValidationResult

Validate the test before executing.

Parameters

test_context : TestContext

Returns

TestValidationResult

mlm_insights.tests.test_types.predicate_based_tests.test_equal module

class mlm_insights.tests.test_types.predicate_based_tests.test_equal.TestEqual(user_defined_tags: ~typing.Dict[str, str] = <factory>, lhs: ~mlm_insights.tests.selectors.interfaces.selector_base.SelectorBase | int | str | float | bool | ~typing.List[~typing.Any] | ~typing.Tuple[int, int] | None = None, rhs: ~mlm_insights.tests.selectors.interfaces.selector_base.SelectorBase | int | str | float | bool | ~typing.List[~typing.Any] | ~typing.Tuple[int, int] | None = None)

Bases: PredicateBasedTestBase

Test if the left value is equal to the right value. Both lhs and rhs must be either a constant value (float, int or bool) or a selector that must return a float, int or bool value.

Configuration

None

Example - Using Insights Test Builder API

test_builder = InsightsTestBuilder()
    .with_context(test_context=get_test_context())
    .add_test(TestEqual(
        lhs=FeatureMetricSelector(
            profile_source=ProfileSource.CURRENT, feature_name="LotArea", metric_key="Mean"),
        rhs=100))
test_runner = test_builder.build()
test_result = test_runner.run()

Example - Using Insights Configuration

{
    "test_config": {
        "feature_metric_tests": [
            {
                "feature_name": "feature_a",
                "tests": [
                    {
                        "test_name": "TestEqual",
                        "metric_key": "Min",
                        "threshold_value": 7500
                    }
                ]
            }
        ]
}
execute(test_context: TestContext, *args: Any, **kwargs: Any) TestResult

Execute the test and return the TestResult. It uses TestContext to query required metric data.

Parameters

test_context : TestContext

Returns

TestResult

validate(test_context: TestContext, *args: Any, **kwargs: Any) TestValidationResult

Validate the test before executing.

Parameters

test_context : TestContext

Returns

TestValidationResult

mlm_insights.tests.test_types.predicate_based_tests.test_greater_than module

class mlm_insights.tests.test_types.predicate_based_tests.test_greater_than.TestGreaterThan(user_defined_tags: ~typing.Dict[str, str] = <factory>, lhs: ~mlm_insights.tests.selectors.interfaces.selector_base.SelectorBase | int | str | float | bool | ~typing.List[~typing.Any] | ~typing.Tuple[int, int] | None = None, rhs: ~mlm_insights.tests.selectors.interfaces.selector_base.SelectorBase | int | str | float | bool | ~typing.List[~typing.Any] | ~typing.Tuple[int, int] | None = None, strictly: bool = False)

Bases: PredicateBasedTestBase

Test if the left value is greater than right value. Both lhs and rhs must be either a numerical value (float, int) or a selector that must return a numerical value.

Configuration

strictlybool

When set to True, condition is >=, else condition is >. Default value is False

Example - Using Insights Test Builder API

test_builder = InsightsTestBuilder()
    .with_context(test_context=get_test_context())
    .add_test(TestGreaterThan(
        lhs=FeatureMetricSelector(profile_source=ProfileSource.CURRENT, feature_name="LotArea", metric_key="Mean"),
        rhs=100))
test_runner = test_builder.build()
test_result = test_runner.run()

Example - Using Insights Configuration

{
    "test_config": {
        "feature_metric_tests": [
            {
                "feature_name": "feature_a",
                "tests": [
                    {
                        "test_name": "TestGreaterThan",
                        "metric_key": "Min",
                        "threshold_value": 7500,
                        "config": {
                            "strictly": true
                        }
                    }
                ]
            }
        ]
}
execute(test_context: TestContext, *args: Any, **kwargs: Any) TestResult

Execute the test and return the TestResult. It uses TestContext to query required metric data.

Parameters

test_context : TestContext

Returns

TestResult

strictly: bool = False
validate(test_context: TestContext, *args: Any, **kwargs: Any) TestValidationResult

Validate the test before executing.

Parameters

test_context : TestContext

Returns

TestValidationResult

mlm_insights.tests.test_types.predicate_based_tests.test_is_between module

class mlm_insights.tests.test_types.predicate_based_tests.test_is_between.TestIsBetween(user_defined_tags: ~typing.Dict[str, str] = <factory>, lhs: ~mlm_insights.tests.selectors.interfaces.selector_base.SelectorBase | int | str | float | bool | ~typing.List[~typing.Any] | ~typing.Tuple[int, int] | None = None, rhs: ~mlm_insights.tests.selectors.interfaces.selector_base.SelectorBase | int | str | float | bool | ~typing.List[~typing.Any] | ~typing.Tuple[int, int] | None = None, strictly: bool = False)

Bases: PredicateBasedTestBase

A predicate-based test which tests if a numerical value is between a minimum and maximum value.

lhs (left value) must be a numerical value (int, float) or a selector that must return a numerical value. rhs (right value) must be a list of 2 values, each of which must be either a numerical value (float, int) or a selector that must return a numerical value.

Configuration

strictlybool

When set to True, condition is (minimum value <= test value <= maximum value), else condition is (minimum value < test value < maximum value). Default value is False

Example - Using Insights Test Builder API

test_builder = InsightsTestBuilder()
    .with_context(test_context=get_test_context())
    .add_test(TestIsBetween(
        lhs=FeatureMetricSelector(
            profile_source=ProfileSource.CURRENT, feature_name="LotArea", metric_key="Mean"),
        rhs=[100, 200]))
test_runner = test_builder.build()
test_result = test_runner.run()

Example - Using Insights Configuration

{
    "test_config": {
        "feature_metric_tests": [
            {
                "feature_name": "feature_a",
                "tests": [
                    {
                        "test_name": "TestIsBetween",
                        "metric_key": "Min",
                        "threshold_value": [7500, 8000],
                        "config": {
                            "strictly": true
                        }
                    }
                ]
            }
        ]
}
execute(test_context: TestContext, *args: Any, **kwargs: Any) TestResult

Execute the test and return the TestResult. It uses TestContext to query required metric data.

Parameters

test_context : TestContext

Returns

TestResult

strictly: bool = False
validate(test_context: TestContext, *args: Any, **kwargs: Any) TestValidationResult

Validate the test before executing.

Parameters

test_context : TestContext

Returns

TestValidationResult

mlm_insights.tests.test_types.predicate_based_tests.test_less_than module

class mlm_insights.tests.test_types.predicate_based_tests.test_less_than.TestLessThan(user_defined_tags: ~typing.Dict[str, str] = <factory>, lhs: ~mlm_insights.tests.selectors.interfaces.selector_base.SelectorBase | int | str | float | bool | ~typing.List[~typing.Any] | ~typing.Tuple[int, int] | None = None, rhs: ~mlm_insights.tests.selectors.interfaces.selector_base.SelectorBase | int | str | float | bool | ~typing.List[~typing.Any] | ~typing.Tuple[int, int] | None = None, strictly: bool = False)

Bases: PredicateBasedTestBase

Test if the left value is less than right value. Both lhs and rhs must be either a numerical value (float, int) or a selector that must return a numerical value.

Configuration

strictlybool

When set to True, condition is <=, else condition is <. Default value is False

Example - Using Insights Test Builder API

test_builder = InsightsTestBuilder()
    .with_context(test_context=get_test_context())
    .add_test(TestLessThan(
        lhs=FeatureMetricSelector(
            profile_source=ProfileSource.CURRENT, feature_name="LotArea", metric_key="Mean"),
        rhs=200))
test_runner = test_builder.build()
test_result = test_runner.run()

Example - Using Insights Configuration

{
    "test_config": {
        "feature_metric_tests": [
            {
                "feature_name": "feature_a",
                "tests": [
                    {
                        "test_name": "TestLessThan",
                        "metric_key": "Min",
                        "threshold_value": 8500,
                        "config": {
                            "strictly": true
                        }
                    }
                ]
            }
        ]
}
execute(test_context: TestContext, *args: Any, **kwargs: Any) TestResult

Execute the test and return the TestResult. It uses TestContext to query required metric data.

Parameters

test_context : TestContext

Returns

TestResult

strictly: bool = False
validate(test_context: TestContext, *args: Any, **kwargs: Any) TestValidationResult

Validate the test before executing.

Parameters

test_context : TestContext

Returns

TestValidationResult

mlm_insights.tests.test_types.predicate_based_tests.test_string_equals module

class mlm_insights.tests.test_types.predicate_based_tests.test_string_equals.TestStringEquals(user_defined_tags: ~typing.Dict[str, str] = <factory>, lhs: ~mlm_insights.tests.selectors.interfaces.selector_base.SelectorBase | int | str | float | bool | ~typing.List[~typing.Any] | ~typing.Tuple[int, int] | None = None, rhs: ~mlm_insights.tests.selectors.interfaces.selector_base.SelectorBase | int | str | float | bool | ~typing.List[~typing.Any] | ~typing.Tuple[int, int] | None = None)

Bases: PredicateBasedTestBase

Test if the left value is equal to right value. Both lhs and rhs must be either a single string value or a selector that returns a single string value.

Configuration

None

Example - Using Insights Test Builder API

test_builder = InsightsTestBuilder()
    .with_context(test_context=get_test_context())
    .add_test(TestStringEquals(
        lhs='100',
        rhs='200'))
test_runner = test_builder.build()
test_result = test_runner.run()

Example - Using Insights Configuration - N/A

execute(test_context: TestContext, *args: Any, **kwargs: Any) TestResult

Execute the test and return the TestResult. It uses TestContext to query required metric data.

Parameters

test_context : TestContext

Returns

TestResult

validate(test_context: TestContext, *args: Any, **kwargs: Any) TestValidationResult

Pre validated the test before executing. It can be used to validate all its parameters and test_context.

Parameters

test_context : TestContext args:

Additional arguments, implemented as per child class.

kwargs:

Key-value pair for dynamic arguments.

Returns

TestValidationResult

Module contents