Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
6c590d6
chore(add): Base class for numerical perturbation detector
Kranium2002 Oct 13, 2024
4e21ed9
fix: minor issues with base class
Kranium2002 Oct 17, 2024
f51e560
add: detector file with default values
Kranium2002 Oct 17, 2024
13d543f
add: mock models for test
Kranium2002 Oct 17, 2024
fe0e2b0
add: tests for numerical perturbation detector
Kranium2002 Oct 17, 2024
a44bca4
Merge branch 'main' into main
henchaves Oct 18, 2024
d1b240b
Merge branch 'main' into main
kevinmessiaen Oct 29, 2024
f9cceda
Merge branch 'main' into main
henchaves Oct 31, 2024
ae9323c
Format files
henchaves Oct 31, 2024
dd04ec7
Merge branch 'main' into main
henchaves Nov 4, 2024
ce3f39f
Merge branch 'main' into main
mattbit Nov 15, 2024
32ff226
Merge branch 'Giskard-AI:main' into main
Kranium2002 Nov 22, 2024
df252f3
fix: check datatype using column_types
Kranium2002 Nov 23, 2024
41bcef7
fix: add metric and metric_value
Kranium2002 Nov 23, 2024
272ee33
fix: add domain and deviation for scan widget
Kranium2002 Nov 23, 2024
6c8b9ae
fix: add transformation_fn
Kranium2002 Nov 23, 2024
264c8d3
Merge branch 'Giskard-AI:main' into main
Kranium2002 Nov 23, 2024
74321ab
fix: tests
Kranium2002 Dec 1, 2024
4eee617
fix: base detector and meta data
Kranium2002 Dec 1, 2024
4973df2
fix: default transformations
Kranium2002 Dec 1, 2024
8e5c8f5
create: Transformations using TransformationFunction Base Class
Kranium2002 Dec 1, 2024
c620bf3
Merge branch 'main' into main
henchaves Dec 16, 2024
c466512
Merge branch 'main' into main
henchaves Jan 6, 2025
312c02d
Format files
henchaves Jan 6, 2025
f30c7b2
Move BaseNumericalPerturbationDetector to base_detector.py
henchaves Jan 6, 2025
eada50e
Create BasePerturbationDetector
henchaves Jan 6, 2025
6afbd2f
Fix import
henchaves Jan 6, 2025
f251bba
Remove params from _get_default_transformations
henchaves Jan 6, 2025
04356b0
Update _get_default_transformations from NumericalPerturbationDetector
henchaves Jan 6, 2025
52b1ae0
Create a base PerturbationFunction class
henchaves Jan 6, 2025
8628c4b
Fix Sonar issue
henchaves Jan 7, 2025
d58e38c
Add type hints to text_transformations.py methods
henchaves Jan 7, 2025
a395c68
Update import
henchaves Jan 7, 2025
dcbb88c
Merge branch 'main' into feature/gsk-3948-add-numerical-perturbation-…
kevinmessiaen Jan 29, 2025
9d05258
Merge branch 'main' into feature/gsk-3948-add-numerical-perturbation-…
kevinmessiaen Jan 30, 2025
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: minor issues with base class
  • Loading branch information
Kranium2002 committed Oct 17, 2024
commit 4e21ed947598ec655ca9668293c6afc845222036
15 changes: 9 additions & 6 deletions giskard/scanner/robustness/base_numerical_detector.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from typing import Optional, Sequence

import numpy as np
import pandas as pd

from ...datasets.base import Dataset
from ...models.base import BaseModel
from ..issues import Issue, IssueLevel, Robustness
Expand Down Expand Up @@ -81,10 +79,15 @@ def _detect_issues(
perturbed_data = perturbed_data.sample(n=num_samples, random_state=42)
original_data = dataset.df.loc[perturbed_data.index]

# Calculate predictions before and after perturbation
original_pred = model.predict(Dataset(original_data, dataset.target, dataset.column_types))
perturbed_pred = model.predict(Dataset(perturbed_data, dataset.target, dataset.column_types))
# Ensure column types are passed correctly as a dictionary
original_pred = model.predict(
Dataset(df=original_data, target=dataset.target, column_types=dict(dataset.column_types))
)
perturbed_pred = model.predict(
Dataset(df=perturbed_data, target=dataset.target, column_types=dict(dataset.column_types))
)

# Check model type and calculate pass/fail rate
if model.is_classification:
passed = original_pred.raw_prediction == perturbed_pred.raw_prediction
elif model.is_regression:
Expand All @@ -98,7 +101,7 @@ def _detect_issues(

logger.info("Testing `%s` perturbation\tFail rate: %.3f" % (feature, fail_rate))

issues = [] # Initialize issues list inside this method as well
issues = []
if fail_rate >= threshold:
# Severity
issue_level = IssueLevel.MAJOR if fail_rate >= 2 * threshold else IssueLevel.MEDIUM
Expand Down