-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add common features validation in Feature Selector component (#2073)
* add validation for no common columns * use spark functions on dataframe * add unit test for feature selector * remove whitespace * add feature selector test in data drift signal e2e test * spacing * fix style changes * fix comments * update spec version
- Loading branch information
Showing
10 changed files
with
159 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...ents/tests/e2e/resources/mltable_iris_preprocessed_model_inputs_no_common_columns/MLTable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
type: mltable | ||
|
||
paths: | ||
- pattern: ./*.csv | ||
transformations: | ||
- read_delimited: | ||
delimiter: ',' | ||
encoding: ascii | ||
header: all_files_same_headers |
76 changes: 76 additions & 0 deletions
76
.../e2e/resources/mltable_iris_preprocessed_model_inputs_no_common_columns/iris_baseline.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,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.8 | ||
6.1,3,4.9,1.8 | ||
6.4,2.8,5.6,2.1 | ||
7.2,3,5.8,1.6 | ||
7.4,2.8,6.1,1.9 | ||
7.9,3.8,6.4,2 | ||
6.4,2.8,5.6,2.2 | ||
6.3,2.8,5.1,1.5 | ||
6.1,2.6,5.6,1.4 | ||
7.7,3,6.1,2.3 | ||
6.3,3.4,5.6,2.4 | ||
6.4,3.1,5.5,1.8 | ||
6,3,4.8,1.8 | ||
6.9,3.1,5.4,2.1 | ||
6.7,3.1,5.6,2.4 | ||
6.9,3.1,5.1,2.3 | ||
5.8,2.7,5.1,1.9 | ||
6.8,3.2,5.9,2.3 | ||
6.7,3.3,5.7,2.5 | ||
6.7,3,5.2,2.3 | ||
6.3,2.5,5,1.9 | ||
6.5,3,5.2,2 | ||
6.2,3.4,5.4,2.3 | ||
5.9,3,5.1,1.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
assets/model_monitoring/components/tests/unit/test_feature_selector_all.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
|
||
"""This file contains unit tests for the FeatureSelectorAll class.""" | ||
|
||
import pytest | ||
from pyspark.sql.types import StructType, StructField, DoubleType, FloatType | ||
from src.model_monitor_feature_selector.selectors.feature_selector_all import FeatureSelectorAll | ||
from tests.e2e.utils.io_utils import create_pyspark_dataframe | ||
|
||
|
||
@pytest.mark.unit | ||
class TestFeatureSelectorAll: | ||
"""Test class for feature selector component.""" | ||
|
||
def test_feature_selector_all_select_expect_succeed(self): | ||
"""Test feature selector scenarios.""" | ||
feature_selector = FeatureSelectorAll() | ||
|
||
# Test with two dataframes that have common columns but datatype is not in the same type | ||
float_data = [(3.55,), (6.88,), (7.99,)] | ||
schema = StructType([ | ||
StructField("target", FloatType(), True)]) | ||
baseline_df = create_pyspark_dataframe(float_data, schema) | ||
double_data = [(3.55,), (6.88,), (7.99,)] | ||
schema = StructType([ | ||
StructField("target", DoubleType(), True)]) | ||
production_df = create_pyspark_dataframe(double_data, schema) | ||
features = feature_selector.select(baseline_df, production_df) | ||
assert features.count() == 1 | ||
|
||
def test_feature_selector_all_select_no_common_columns_expect_failure(self): | ||
"""Test feature selector scenarios.""" | ||
feature_selector = FeatureSelectorAll() | ||
|
||
# Test with two dataframes that have no common columns | ||
baseline_df = create_pyspark_dataframe([(1, "a"), (2, "b")], | ||
["id", "name"]) | ||
production_df = create_pyspark_dataframe([(3, "c"), (4, "d")], | ||
["age", "gender"]) | ||
try: | ||
feature_selector.select(baseline_df, production_df) | ||
except Exception as e: | ||
assert "Found no common columns between input datasets." in e.args[0] |