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

fix indexing error when creating a filtered error analysis tree view with a dataset that contains categoricals #2026

Merged
merged 1 commit into from
Apr 5, 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
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,6 @@ def get_surrogate_booster_local(filtered_df, analyzer, is_model_analyzer,
scored dataset.
:rtype: (Booster, pandas.DataFrame, (list[str], list[int]))
"""
row_index = filtered_df[ROW_INDEX]
true_y = filtered_df[TRUE_Y]
dropped_cols = [TRUE_Y, ROW_INDEX]
if not is_model_analyzer:
Expand Down Expand Up @@ -330,7 +329,7 @@ def get_surrogate_booster_local(filtered_df, analyzer, is_model_analyzer,
else:
string_indexed_data = analyzer.string_indexed_data
for idx, c_i in enumerate(analyzer.categorical_indexes):
input_data[:, c_i] = string_indexed_data[row_index, idx]
input_data[:, c_i] = string_indexed_data[:, idx]
dataset_sub_features = input_data[:, indexes]

categorical_info = get_categorical_info(analyzer,
Expand Down
14 changes: 13 additions & 1 deletion erroranalysis/tests/test_surrogate_error_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,24 @@ def test_surrogate_error_tree_iris(self, analyzer_type):
def test_surrogate_error_tree_int_categorical(self, analyzer_type):
X_train, X_test, y_train, y_test, categorical_features = \
create_adult_census_data()

model = create_kneighbors_classifier(X_train, y_train)

run_error_analyzer(model, X_test, y_test, list(X_train.columns),
analyzer_type, categorical_features)

@pytest.mark.parametrize('analyzer_type', [AnalyzerType.MODEL,
AnalyzerType.PREDICTIONS])
def test_surrogate_error_tree_categorical_filtered(self, analyzer_type):
X_train, X_test, y_train, y_test, categorical_features = \
create_adult_census_data()
model = create_kneighbors_classifier(X_train, y_train)
filters = [{'arg': [40],
'column': 'Age',
'method': 'less and equal'}]
run_error_analyzer(model, X_test, y_test, list(X_train.columns),
analyzer_type, categorical_features,
filters=filters)

def test_large_data_surrogate_error_tree(self):
# validate tree trains quickly for large data
X_train, y_train, X_test, y_test, _ = \
Expand Down