Skip to content

Commit

Permalink
chore: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
crismunoz committed Nov 8, 2024
1 parent 8d2306a commit 4d4b36c
Show file tree
Hide file tree
Showing 37 changed files with 140 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
unconventional_numeric_config,
)

from holisticai.bias.metrics import frequency_matrix, multiclass_statistical_parity
from holistic.bias.metrics import frequency_matrix, multiclass_statistical_parity

#######################
# 1 entrada + p_attr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
unconventional_numeric_config,
)

from holisticai.bias.metrics import confusion_matrix
from holistic.bias.metrics import confusion_matrix

##################################################################################################################
# 2 inputs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
unconventional_numeric_config,
)

from holisticai.bias.metrics import (
from holistic.bias.metrics import (
accuracy_matrix,
confusion_tensor,
multiclass_average_odds,
Expand Down
4 changes: 2 additions & 2 deletions tests/bias/metrics/test_bias_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from numpy.testing import assert_approx_equal

# Classification
from holisticai.bias.metrics import (
from holistic.bias.metrics import (
abroca,
accuracy_diff,
average_odds_diff,
Expand All @@ -22,7 +22,7 @@
)

# Formatting
from holisticai.utils import extract_columns
from holistic.utils import extract_columns

# Dataset
from tests.bias.utils import load_bias_classification_data
Expand Down
2 changes: 1 addition & 1 deletion tests/bias/metrics/test_bias_clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from numpy.testing import assert_approx_equal

# Clustering
from holisticai.bias.metrics import (
from holistic.bias.metrics import (
cluster_balance,
cluster_dist_entropy,
cluster_dist_kl,
Expand Down
2 changes: 1 addition & 1 deletion tests/bias/metrics/test_bias_multiclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from numpy.testing import assert_approx_equal, assert_array_almost_equal

# Multiclass
from holisticai.bias.metrics import (
from holistic.bias.metrics import (
accuracy_matrix,
confusion_tensor,
frequency_matrix,
Expand Down
4 changes: 2 additions & 2 deletions tests/bias/metrics/test_bias_recommender.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from numpy.testing import assert_approx_equal

# Recommender
from holisticai.bias.metrics import (
from holistic.bias.metrics import (
aggregate_diversity,
avg_f1_ratio,
avg_precision_ratio,
Expand All @@ -20,7 +20,7 @@
)

# Formatting
from holisticai.utils import extract_columns
from holistic.utils import extract_columns
from tests.bias.utils import load_bias_recommender_data

# Dataset
Expand Down
4 changes: 2 additions & 2 deletions tests/bias/metrics/test_bias_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from numpy.testing import assert_approx_equal

# Regression
from holisticai.bias.metrics import (
from holistic.bias.metrics import (
avg_score_diff,
avg_score_ratio,
correlation_diff,
Expand All @@ -22,7 +22,7 @@
)

# Formatting
from holisticai.utils import extract_columns
from holistic.utils import extract_columns
from tests.bias.utils import load_bias_regression_data

# Dataset
Expand Down
34 changes: 17 additions & 17 deletions tests/bias/mitigation/test_inprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import numpy as np
from sklearn.linear_model import LogisticRegression, LinearRegression

from holisticai.pipeline import Pipeline
from holisticai.bias.metrics import classification_bias_metrics, regression_bias_metrics, multiclass_bias_metrics, clustering_bias_metrics, recommender_bias_metrics
from holistic.pipeline import Pipeline
from holistic.bias.metrics import classification_bias_metrics, regression_bias_metrics, multiclass_bias_metrics, clustering_bias_metrics, recommender_bias_metrics
from tests.bias.mitigation.utils import (
check_results,
categorical_dataset,
Expand All @@ -18,20 +18,20 @@

seed = 42

from holisticai.bias.mitigation import MITIGATOR_NAME
from holisticai.bias.mitigation import ExponentiatedGradientReduction
from holisticai.bias.mitigation import GridSearchReduction
from holisticai.bias.mitigation import MetaFairClassifier
from holisticai.bias.mitigation import PrejudiceRemover
from holisticai.bias.mitigation import FairKCenterClustering
from holisticai.bias.mitigation import FairKMedianClustering
from holisticai.bias.mitigation import FairletClustering
from holisticai.bias.mitigation import VariationalFairClustering
from holisticai.bias.mitigation import PopularityPropensityMF
from holisticai.bias.mitigation import BlindSpotAwareMF
from holisticai.bias.mitigation import FairRec
from holisticai.bias.mitigation import DebiasingLearningMF
from holisticai.bias.mitigation import AdversarialDebiasing
from holistic.bias.mitigation import MITIGATOR_NAME
from holistic.bias.mitigation import ExponentiatedGradientReduction
from holistic.bias.mitigation import GridSearchReduction
from holistic.bias.mitigation import MetaFairClassifier
from holistic.bias.mitigation import PrejudiceRemover
from holistic.bias.mitigation import FairKCenterClustering
from holistic.bias.mitigation import FairKMedianClustering
from holistic.bias.mitigation import FairletClustering
from holistic.bias.mitigation import VariationalFairClustering
from holistic.bias.mitigation import PopularityPropensityMF
from holistic.bias.mitigation import BlindSpotAwareMF
from holistic.bias.mitigation import FairRec
from holistic.bias.mitigation import DebiasingLearningMF
from holistic.bias.mitigation import AdversarialDebiasing

def get_inprocessor(mitigator_name : MITIGATOR_NAME = "CalibratedEqualizedOdds", parameters: dict = {}):
if mitigator_name == "ExponentiatedGradientReduction":
Expand All @@ -45,7 +45,7 @@ def get_inprocessor(mitigator_name : MITIGATOR_NAME = "CalibratedEqualizedOdds",
elif mitigator_name == "PrejudiceRemover":
return PrejudiceRemover(**parameters)
elif mitigator_name == "FairScoreClassifier":
from holisticai.bias.mitigation import FairScoreClassifier
from holistic.bias.mitigation import FairScoreClassifier
return FairScoreClassifier(**parameters)
elif mitigator_name == "FairKCenterClustering":
return FairKCenterClustering(**parameters)
Expand Down
32 changes: 16 additions & 16 deletions tests/bias/mitigation/test_postprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from sklearn.linear_model import LogisticRegression, LinearRegression
from sklearn.cluster import KMeans

from holisticai.pipeline import Pipeline
from holisticai.bias.metrics import classification_bias_metrics, regression_bias_metrics, multiclass_bias_metrics, clustering_bias_metrics
from holisticai.datasets.synthetic.recruitment import generate_rankings
from holisticai.bias.mitigation.postprocessing.debiasing_exposure.algorithm_utils import exposure_metric
from holistic.pipeline import Pipeline
from holistic.bias.metrics import classification_bias_metrics, regression_bias_metrics, multiclass_bias_metrics, clustering_bias_metrics
from holistic.datasets.synthetic.recruitment import generate_rankings
from holistic.bias.mitigation.postprocessing.debiasing_exposure.algorithm_utils import exposure_metric
from tests.bias.mitigation.utils import (
check_results,
categorical_dataset,
Expand All @@ -19,18 +19,18 @@

seed = 42

from holisticai.bias.mitigation import MITIGATOR_NAME
from holisticai.bias.mitigation import CalibratedEqualizedOdds
from holisticai.bias.mitigation import EqualizedOdds
from holisticai.bias.mitigation import RejectOptionClassification
from holisticai.bias.mitigation import LPDebiaserBinary
from holisticai.bias.mitigation import MLDebiaser
from holisticai.bias.mitigation import LPDebiaserMulticlass
from holisticai.bias.mitigation import PluginEstimationAndCalibration
from holisticai.bias.mitigation import WassersteinBarycenter
from holisticai.bias.mitigation import MCMF
from holisticai.bias.mitigation import DebiasingExposure
from holisticai.bias.mitigation import FairTopK
from holistic.bias.mitigation import MITIGATOR_NAME
from holistic.bias.mitigation import CalibratedEqualizedOdds
from holistic.bias.mitigation import EqualizedOdds
from holistic.bias.mitigation import RejectOptionClassification
from holistic.bias.mitigation import LPDebiaserBinary
from holistic.bias.mitigation import MLDebiaser
from holistic.bias.mitigation import LPDebiaserMulticlass
from holistic.bias.mitigation import PluginEstimationAndCalibration
from holistic.bias.mitigation import WassersteinBarycenter
from holistic.bias.mitigation import MCMF
from holistic.bias.mitigation import DebiasingExposure
from holistic.bias.mitigation import FairTopK

def get_postprocessor(mitigator_name : MITIGATOR_NAME = "CalibratedEqualizedOdds", parameters: dict = {}):
if mitigator_name == "CalibratedEqualizedOdds":
Expand Down
20 changes: 10 additions & 10 deletions tests/bias/mitigation/test_preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from sklearn.preprocessing import StandardScaler
from sklearn.cluster import KMeans

from holisticai.pipeline import Pipeline
from holisticai.bias.metrics import classification_bias_metrics, regression_bias_metrics, multiclass_bias_metrics, clustering_bias_metrics
from holisticai.datasets.synthetic.recruitment import generate_rankings
from holisticai.bias.mitigation.postprocessing.debiasing_exposure.algorithm_utils import exposure_metric
from holistic.pipeline import Pipeline
from holistic.bias.metrics import classification_bias_metrics, regression_bias_metrics, multiclass_bias_metrics, clustering_bias_metrics
from holistic.datasets.synthetic.recruitment import generate_rankings
from holistic.bias.mitigation.postprocessing.debiasing_exposure.algorithm_utils import exposure_metric

from tests.bias.mitigation.utils import (
check_results,
Expand All @@ -22,12 +22,12 @@

seed = 42

from holisticai.bias.mitigation import MITIGATOR_NAME
from holisticai.bias.mitigation import CorrelationRemover
from holisticai.bias.mitigation import Reweighing
from holisticai.bias.mitigation import LearningFairRepresentation
from holisticai.bias.mitigation import FairletClusteringPreprocessing
from holisticai.bias.mitigation import DisparateImpactRemoverRS
from holistic.bias.mitigation import MITIGATOR_NAME
from holistic.bias.mitigation import CorrelationRemover
from holistic.bias.mitigation import Reweighing
from holistic.bias.mitigation import LearningFairRepresentation
from holistic.bias.mitigation import FairletClusteringPreprocessing
from holistic.bias.mitigation import DisparateImpactRemoverRS

def get_preprocessor(mitigator_name : MITIGATOR_NAME = "CorrelationRemover", parameters: dict = {}):
if mitigator_name == "CorrelationRemover":
Expand Down
2 changes: 1 addition & 1 deletion tests/bias/mitigation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from sklearn import metrics


from holisticai.datasets import load_dataset
from holistic.datasets import load_dataset

metrics_dict = {
"Accuracy": metrics.accuracy_score,
Expand Down
2 changes: 1 addition & 1 deletion tests/commons/test_feature_importance.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np
from holisticai.utils import Importances
from holistic.utils import Importances

def test_compute_ranked_feature_importance():
# Create a sample feature importance dataframe
Expand Down
8 changes: 4 additions & 4 deletions tests/commons/test_feature_importance_strategies.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from sklearn.linear_model import LogisticRegression
from holisticai.inspection import SurrogateFeatureImportanceCalculator, PermutationFeatureImportanceCalculator
from holisticai.utils import Importances
from holisticai.datasets import load_dataset
from holisticai.utils import BinaryClassificationProxy
from holistic.inspection import SurrogateFeatureImportanceCalculator, PermutationFeatureImportanceCalculator
from holistic.utils import Importances
from holistic.datasets import load_dataset
from holistic.utils import BinaryClassificationProxy
import pytest
import numpy as np
from numpy.random import RandomState
Expand Down
6 changes: 3 additions & 3 deletions tests/commons/test_local_feature_importance.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from holisticai.utils import LocalImportances
from holistic.utils import LocalImportances
import pandas as pd
import numpy as np

Expand All @@ -24,8 +24,8 @@ def test_local_feature_importance_to_global():
assert len(local_importance.to_global().values)==4

def test_partial_dependence():
from holisticai.utils import PartialDependence, Importances
from holisticai.explainability.metrics.global_feature_importance import xai_ease_score
from holistic.utils import PartialDependence, Importances
from holistic.explainability.metrics.global_feature_importance import xai_ease_score

partial_dependence = [[
{'average': [[0.1, 0.2, 0.3, 0.1, 0.2, 0.3, 0.1, 0.2, 0.3]], 'grid_values': [[1,2,3,4,5,6,7,8,9]]},
Expand Down
8 changes: 4 additions & 4 deletions tests/commons/test_partial_dependence.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from holisticai.datasets import load_dataset
from holistic.datasets import load_dataset
import numpy as np
from sklearn.linear_model import LogisticRegression
from numpy.random import RandomState
Expand All @@ -19,9 +19,9 @@ def input_data():

def test_get_partial_dependence_results_binary_classification(input_data):
test,model = input_data
from holisticai.utils import RegressionProxy
from holisticai.inspection import compute_permutation_importance
from holisticai.inspection import compute_partial_dependence
from holistic.utils import RegressionProxy
from holistic.inspection import compute_permutation_importance
from holistic.inspection import compute_partial_dependence

proxy = RegressionProxy(predict=model.predict)
importances = compute_permutation_importance(proxy=proxy, X=test['X'], y=test['y'])
Expand Down
8 changes: 4 additions & 4 deletions tests/commons/test_xai_ease_score.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
import pandas as pd
import pytest
from holisticai.explainability.metrics.global_feature_importance._xai_ease_score import XAIEaseScore, XAIEaseAnnotator, compare_tangents
from holistic.explainability.metrics.global_feature_importance._xai_ease_score import XAIEaseScore, XAIEaseAnnotator, compare_tangents
from collections import namedtuple

@pytest.fixture
Expand All @@ -13,7 +13,7 @@ def xai_ease_score():
return XAIEaseScore()

def test_compute_xai_ease_score_data(xai_ease_annotator):
from holisticai.utils import PartialDependence
from holistic.utils import PartialDependence
partial_dependence = PartialDependence( values = [[
{'average': [[0.1, 0.2, 0.3, 0.1, 0.2, 0.3, 0.1, 0.2, 0.3]]},
{'average': [[0.4, 0.5, 0.6, 0.6, 0.5, 0.4, 0.4, 0.5, 0.6]]},
Expand All @@ -30,7 +30,7 @@ def test_compute_xai_ease_score(xai_ease_score):
assert xai_ease_score.compute_xai_ease_score(score_data) == 0.75

def test_xai_feature_ease_score(xai_ease_score):
from holisticai.utils import PartialDependence
from holistic.utils import PartialDependence
partial_dependence = PartialDependence( values = [[
{'average': [[0.1, 0.2, 0.3, 0.1, 0.2, 0.3, 0.1, 0.2, 0.3]]},
{'average': [[0.4, 0.5, 0.6, 0.6, 0.5, 0.4, 0.4, 0.5, 0.6]]},
Expand All @@ -40,7 +40,7 @@ def test_xai_feature_ease_score(xai_ease_score):
assert xai_ease_score(partial_dependence, ranked_feature_importance) == 0.5

def test_xai_ease_score(xai_ease_score):
from holisticai.utils import PartialDependence, Importances
from holistic.utils import PartialDependence, Importances
partial_dependence = [[
{'average': [[0.1, 0.2, 0.3, 0.1, 0.2, 0.3, 0.1, 0.2, 0.3]], 'grid_values': [[1,2,3,4,5,6,7,8,9]]},
{'average': [[0.4, 0.5, 0.6, 0.6, 0.5, 0.4, 0.4, 0.5, 0.6]], 'grid_values': [[1,2,3,4,5,6,7,8,9]]},
Expand Down
2 changes: 1 addition & 1 deletion tests/datasets/test_load_datasets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from holisticai.datasets import load_dataset
from holistic.datasets import load_dataset

def test_load_dataset():
SHARD_SIZE = 50
Expand Down
4 changes: 2 additions & 2 deletions tests/explainability/metrics/test_global_importance.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
import pandas as pd
from holisticai.explainability.metrics.global_feature_importance import fluctuation_ratio
from holisticai.utils import PartialDependence, Importances
from holistic.explainability.metrics.global_feature_importance import fluctuation_ratio
from holistic.utils import PartialDependence, Importances

def test_fluctuation_ratio_unweighted_aggregated():
partial_dependence = PartialDependence(values=[[
Expand Down
4 changes: 2 additions & 2 deletions tests/explainability/metrics/test_local_importance.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

import numpy as np
import pandas as pd
from holisticai.explainability.metrics.local_feature_importance import feature_stability
from holisticai.explainability.metrics.local_feature_importance import rank_consistency
from holistic.explainability.metrics.local_feature_importance import feature_stability
from holistic.explainability.metrics.local_feature_importance import rank_consistency

def test_rank_consistency_unweighted_aggregated():
local_importances_values = np.array([
Expand Down
Loading

0 comments on commit 4d4b36c

Please sign in to comment.