Skip to content

Commit

Permalink
Update by adding notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
zyliang2001 committed Jan 14, 2024
1 parent ae5a3d9 commit 9364e74
Show file tree
Hide file tree
Showing 3 changed files with 261 additions and 4 deletions.
8 changes: 4 additions & 4 deletions feature_importance/01_run_importance_local_simulations.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ def compare_estimators(estimators: List[ModelConfig],
imp_vals[imp_vals == float("inf")] = sys.maxsize - 1
if fi_est.ascending:
imp_vals[np.isnan(imp_vals)] = -sys.maxsize - 1
metric_results[met_name + " group1"] = met(support_group1, imp_vals)
metric_results[met_name + "_group1"] = met(support_group1, imp_vals)
else:
imp_vals[np.isnan(imp_vals)] = sys.maxsize - 1
metric_results[met_name+ " group1"] = met(support_group1, -imp_vals)
metric_results[met_name+ "_group1"] = met(support_group1, -imp_vals)


if np.max(support_group2) != np.min(support_group2):
Expand All @@ -138,10 +138,10 @@ def compare_estimators(estimators: List[ModelConfig],
imp_vals[imp_vals == float("inf")] = sys.maxsize - 1
if fi_est.ascending:
imp_vals[np.isnan(imp_vals)] = -sys.maxsize - 1
metric_results[met_name+ " group2"] = met(support_group2, imp_vals)
metric_results[met_name+ "_group2"] = met(support_group2, imp_vals)
else:
imp_vals[np.isnan(imp_vals)] = sys.maxsize - 1
metric_results[met_name+ " group2"] = met(support_group2, -imp_vals)
metric_results[met_name+ "_group2"] = met(support_group2, -imp_vals)
metric_results['time'] = end - start

# initialize results with metadata and metric results
Expand Down
236 changes: 236 additions & 0 deletions feature_importance/local_MDI_plus_visulization.ipynb

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions feature_importance/scripts/competing_methods_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,27 @@ def MDI_local(X, y, fit):
num_samples, num_features = X.shape


result = None

# Convert the array to a DataFrame
result_table = pd.DataFrame(result, columns=[f'Feature_{i}' for i in range(num_features)])

return result_table

def LIME(X, y, fit):
"""
Compute LIME local importance for each feature and sample.
:param X: design matrix
:param y: response
:param fit: fitted model of interest (tree-based)
:return: dataframe of shape: (n_samples, n_features)
"""

## To Do for Zach: Please add the implementation of local MDI below
num_samples, num_features = X.shape


result = None

# Convert the array to a DataFrame
Expand Down

0 comments on commit 9364e74

Please sign in to comment.