-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from SCAI-BIO/update-shap-viisualization
feat: add persistence to shap plots and add unit test
- Loading branch information
Showing
2 changed files
with
52 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import unittest | ||
import pandas as pd | ||
import numpy as np | ||
import os | ||
|
||
from syndat import plot_shap_discrimination | ||
|
||
|
||
class TestPlotShapDiscrimination(unittest.TestCase): | ||
|
||
def setUp(self): | ||
# Create sample data for testing | ||
self.real = pd.DataFrame(np.random.normal(size=(100, 5)), columns=[f"feature_{i}" for i in range(5)]) | ||
self.synthetic = pd.DataFrame(np.random.normal(size=(100, 5)), columns=[f"feature_{i}" for i in range(5)]) | ||
|
||
# Define the path where the plot will be temporarily saved | ||
self.save_path = "test_shap_plot.png" | ||
|
||
def test_plot_shap_discrimination(self): | ||
# Call the function with test data and save_path | ||
plot_shap_discrimination(self.real, self.synthetic, save_path=self.save_path) | ||
|
||
# Check if the plot file was created | ||
self.assertTrue(os.path.exists(self.save_path), "SHAP plot file was not created.") | ||
|
||
def tearDown(self): | ||
# Remove the file if it exists after the test | ||
if os.path.exists(self.save_path): | ||
os.remove(self.save_path) | ||
|