erroranalysis 0.5.4__tar.gz → 0.5.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {erroranalysis-0.5.4/erroranalysis.egg-info → erroranalysis-0.5.5}/PKG-INFO +2 -2
- {erroranalysis-0.5.4 → erroranalysis-0.5.5}/erroranalysis/_internal/surrogate_error_tree.py +13 -2
- {erroranalysis-0.5.4 → erroranalysis-0.5.5}/erroranalysis/version.py +1 -1
- {erroranalysis-0.5.4 → erroranalysis-0.5.5/erroranalysis.egg-info}/PKG-INFO +2 -2
- {erroranalysis-0.5.4 → erroranalysis-0.5.5}/erroranalysis.egg-info/requires.txt +1 -1
- {erroranalysis-0.5.4 → erroranalysis-0.5.5}/requirements.txt +1 -1
- {erroranalysis-0.5.4 → erroranalysis-0.5.5}/tests/test_surrogate_error_tree.py +106 -2
- {erroranalysis-0.5.4 → erroranalysis-0.5.5}/LICENSE +0 -0
- {erroranalysis-0.5.4 → erroranalysis-0.5.5}/MANIFEST.in +0 -0
- {erroranalysis-0.5.4 → erroranalysis-0.5.5}/README.md +0 -0
- {erroranalysis-0.5.4 → erroranalysis-0.5.5}/erroranalysis/__init__.py +0 -0
- {erroranalysis-0.5.4 → erroranalysis-0.5.5}/erroranalysis/_internal/__init__.py +0 -0
- {erroranalysis-0.5.4 → erroranalysis-0.5.5}/erroranalysis/_internal/cohort_filter.py +0 -0
- {erroranalysis-0.5.4 → erroranalysis-0.5.5}/erroranalysis/_internal/constants.py +0 -0
- {erroranalysis-0.5.4 → erroranalysis-0.5.5}/erroranalysis/_internal/error_analyzer/__init__.py +0 -0
- {erroranalysis-0.5.4 → erroranalysis-0.5.5}/erroranalysis/_internal/error_report/__init__.py +0 -0
- {erroranalysis-0.5.4 → erroranalysis-0.5.5}/erroranalysis/_internal/matrix_filter.py +0 -0
- {erroranalysis-0.5.4 → erroranalysis-0.5.5}/erroranalysis/_internal/metrics.py +0 -0
- {erroranalysis-0.5.4 → erroranalysis-0.5.5}/erroranalysis/_internal/process_categoricals.py +0 -0
- {erroranalysis-0.5.4 → erroranalysis-0.5.5}/erroranalysis/_internal/utils.py +0 -0
- {erroranalysis-0.5.4 → erroranalysis-0.5.5}/erroranalysis/_internal/version_checker.py +0 -0
- {erroranalysis-0.5.4 → erroranalysis-0.5.5}/erroranalysis/analyzer/__init__.py +0 -0
- {erroranalysis-0.5.4 → erroranalysis-0.5.5}/erroranalysis/analyzer/error_analyzer.py +0 -0
- {erroranalysis-0.5.4 → erroranalysis-0.5.5}/erroranalysis/error_correlation_methods/__init__.py +0 -0
- {erroranalysis-0.5.4 → erroranalysis-0.5.5}/erroranalysis/error_correlation_methods/ebm.py +0 -0
- {erroranalysis-0.5.4 → erroranalysis-0.5.5}/erroranalysis/error_correlation_methods/gbm.py +0 -0
- {erroranalysis-0.5.4 → erroranalysis-0.5.5}/erroranalysis/report/__init__.py +0 -0
- {erroranalysis-0.5.4 → erroranalysis-0.5.5}/erroranalysis/report/error_report.py +0 -0
- {erroranalysis-0.5.4 → erroranalysis-0.5.5}/erroranalysis.egg-info/SOURCES.txt +0 -0
- {erroranalysis-0.5.4 → erroranalysis-0.5.5}/erroranalysis.egg-info/dependency_links.txt +0 -0
- {erroranalysis-0.5.4 → erroranalysis-0.5.5}/erroranalysis.egg-info/top_level.txt +0 -0
- {erroranalysis-0.5.4 → erroranalysis-0.5.5}/requirements-object-detection.txt +0 -0
- {erroranalysis-0.5.4 → erroranalysis-0.5.5}/setup.cfg +0 -0
- {erroranalysis-0.5.4 → erroranalysis-0.5.5}/setup.py +0 -0
- {erroranalysis-0.5.4 → erroranalysis-0.5.5}/tests/test_cohort_filter.py +0 -0
- {erroranalysis-0.5.4 → erroranalysis-0.5.5}/tests/test_error_report.py +0 -0
- {erroranalysis-0.5.4 → erroranalysis-0.5.5}/tests/test_importances.py +0 -0
- {erroranalysis-0.5.4 → erroranalysis-0.5.5}/tests/test_matrix_filter.py +0 -0
- {erroranalysis-0.5.4 → erroranalysis-0.5.5}/tests/test_metrics.py +0 -0
- {erroranalysis-0.5.4 → erroranalysis-0.5.5}/tests/test_pyspark_surrogate_error_tree.py +0 -0
- {erroranalysis-0.5.4 → erroranalysis-0.5.5}/tests/test_root_stats.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: erroranalysis
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.5
|
|
4
4
|
Summary: Core error analysis APIs
|
|
5
5
|
Home-page: https://github.com/microsoft/responsible-ai-widgets
|
|
6
6
|
Author: Roman Lutz, Ilya Matiach, Ke Xu
|
|
@@ -16,7 +16,7 @@ Classifier: Development Status :: 3 - Alpha
|
|
|
16
16
|
Requires-Python: >=3.7
|
|
17
17
|
Description-Content-Type: text/markdown
|
|
18
18
|
License-File: LICENSE
|
|
19
|
-
Requires-Dist: numpy
|
|
19
|
+
Requires-Dist: numpy<2.0.0,>=1.17.2
|
|
20
20
|
Requires-Dist: pandas<2.0.0,>=0.25.1
|
|
21
21
|
Requires-Dist: scipy>=1.4.1
|
|
22
22
|
Requires-Dist: scikit-learn>=0.22.1
|
|
@@ -53,6 +53,7 @@ DEFAULT_NUM_LEAVES = 31
|
|
|
53
53
|
DEFAULT_MIN_CHILD_SAMPLES = 20
|
|
54
54
|
CACHED_SUBTREE_FEATURES = 'cache_subtree_features'
|
|
55
55
|
LEAF_VALUE = 'leaf_value'
|
|
56
|
+
OBJECT = 'object'
|
|
56
57
|
PREDICTION = 'prediction'
|
|
57
58
|
RAW_PREDICTION = 'rawPrediction'
|
|
58
59
|
PROBABILITY = 'probability'
|
|
@@ -341,10 +342,20 @@ def get_surrogate_booster_local(filtered_df, analyzer, is_model_analyzer,
|
|
|
341
342
|
diff = pred_y - true_y
|
|
342
343
|
if not isinstance(diff, np.ndarray):
|
|
343
344
|
diff = np.array(diff)
|
|
345
|
+
|
|
346
|
+
# Note: if direct conversion fails, for more complex data scenarios like
|
|
347
|
+
# object detection we need to convert to an object type for newer versions
|
|
348
|
+
# of numpy>=1.26.0
|
|
344
349
|
if not isinstance(pred_y, np.ndarray):
|
|
345
|
-
|
|
350
|
+
try:
|
|
351
|
+
pred_y = np.array(pred_y)
|
|
352
|
+
except ValueError:
|
|
353
|
+
pred_y = np.array(pred_y, dtype=OBJECT)
|
|
346
354
|
if not isinstance(true_y, np.ndarray):
|
|
347
|
-
|
|
355
|
+
try:
|
|
356
|
+
true_y = np.array(true_y)
|
|
357
|
+
except ValueError:
|
|
358
|
+
true_y = np.array(true_y, dtype=OBJECT)
|
|
348
359
|
if is_pandas:
|
|
349
360
|
input_data = input_data.to_numpy(copy=True)
|
|
350
361
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: erroranalysis
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.5
|
|
4
4
|
Summary: Core error analysis APIs
|
|
5
5
|
Home-page: https://github.com/microsoft/responsible-ai-widgets
|
|
6
6
|
Author: Roman Lutz, Ilya Matiach, Ke Xu
|
|
@@ -16,7 +16,7 @@ Classifier: Development Status :: 3 - Alpha
|
|
|
16
16
|
Requires-Python: >=3.7
|
|
17
17
|
Description-Content-Type: text/markdown
|
|
18
18
|
License-File: LICENSE
|
|
19
|
-
Requires-Dist: numpy
|
|
19
|
+
Requires-Dist: numpy<2.0.0,>=1.17.2
|
|
20
20
|
Requires-Dist: pandas<2.0.0,>=0.25.1
|
|
21
21
|
Requires-Dist: scipy>=1.4.1
|
|
22
22
|
Requires-Dist: scikit-learn>=0.22.1
|
|
@@ -9,6 +9,7 @@ import numpy as np
|
|
|
9
9
|
import pandas as pd
|
|
10
10
|
import pytest
|
|
11
11
|
from common_utils import replicate_dataset
|
|
12
|
+
from ml_wrappers import wrap_model
|
|
12
13
|
|
|
13
14
|
from erroranalysis._internal.cohort_filter import filter_from_cohort
|
|
14
15
|
from erroranalysis._internal.constants import (ARG, COLUMN, COMPOSITE_FILTERS,
|
|
@@ -16,8 +17,9 @@ from erroranalysis._internal.constants import (ARG, COLUMN, COMPOSITE_FILTERS,
|
|
|
16
17
|
OPERATION, PRED_Y, ROW_INDEX,
|
|
17
18
|
SPLIT_FEATURE, SPLIT_INDEX,
|
|
18
19
|
TRUE_Y, CohortFilterMethods,
|
|
19
|
-
CohortFilterOps,
|
|
20
|
-
ModelTask,
|
|
20
|
+
CohortFilterOps, ImageColumns,
|
|
21
|
+
Metrics, ModelTask,
|
|
22
|
+
regression_metrics)
|
|
21
23
|
from erroranalysis._internal.error_analyzer import (ModelAnalyzer,
|
|
22
24
|
PredictionsAnalyzer)
|
|
23
25
|
from erroranalysis._internal.surrogate_error_tree import (
|
|
@@ -28,12 +30,22 @@ from rai_test_utils.datasets.tabular import (
|
|
|
28
30
|
create_adult_census_data, create_binary_classification_dataset,
|
|
29
31
|
create_cancer_data, create_diabetes_data, create_iris_data,
|
|
30
32
|
create_simple_titanic_data)
|
|
33
|
+
from rai_test_utils.datasets.vision import (
|
|
34
|
+
get_images, load_fridge_object_detection_dataset)
|
|
31
35
|
from rai_test_utils.models.model_utils import create_models_classification
|
|
32
36
|
from rai_test_utils.models.sklearn import (
|
|
33
37
|
create_kneighbors_classifier, create_sklearn_random_forest_regressor,
|
|
34
38
|
create_titanic_pipeline)
|
|
39
|
+
from rai_test_utils.models.torch import get_object_detection_fridge_model
|
|
35
40
|
from raiutils.exceptions import UserConfigValidationException
|
|
36
41
|
|
|
42
|
+
try:
|
|
43
|
+
import torch # noqa: F401
|
|
44
|
+
import torchvision # noqa: F401
|
|
45
|
+
pytorch_installed = True
|
|
46
|
+
except ImportError:
|
|
47
|
+
pytorch_installed = False
|
|
48
|
+
|
|
37
49
|
SIZE = 'size'
|
|
38
50
|
PARENTID = 'parentId'
|
|
39
51
|
ERROR = 'error'
|
|
@@ -65,6 +77,71 @@ class DummyInvalidShapeModel:
|
|
|
65
77
|
return np.zeros((X.shape[0], 1))
|
|
66
78
|
|
|
67
79
|
|
|
80
|
+
class SimplifiedWrappedIndexPredictorModel:
|
|
81
|
+
"""Wraps model that uses index to retrieve image data for making
|
|
82
|
+
predictions. Simplified version of the one in responsibleai-vision
|
|
83
|
+
package."""
|
|
84
|
+
|
|
85
|
+
def __init__(self, model, dataset, image_mode):
|
|
86
|
+
"""Initialize the WrappedIndexPredictorModel.
|
|
87
|
+
|
|
88
|
+
:param model: The model to wrap.
|
|
89
|
+
:type model: object
|
|
90
|
+
:param dataset: The dataset to use for making predictions.
|
|
91
|
+
:type dataset: pandas.DataFrame
|
|
92
|
+
:param image_mode: The mode to open the image in.
|
|
93
|
+
See pillow documentation for all modes:
|
|
94
|
+
https://pillow.readthedocs.io/en/stable/handbook/concepts.html
|
|
95
|
+
:type image_mode: str
|
|
96
|
+
"""
|
|
97
|
+
self.model = model
|
|
98
|
+
self.dataset = dataset
|
|
99
|
+
self.image_mode = image_mode
|
|
100
|
+
test = get_images(self.dataset, self.image_mode, None)
|
|
101
|
+
self.predictions = self.model.predict(test)
|
|
102
|
+
self.predict_proba = self.model.predict_proba(test)
|
|
103
|
+
|
|
104
|
+
def index_predictions(self, index, predictions):
|
|
105
|
+
"""Index the predictions.
|
|
106
|
+
|
|
107
|
+
:param index: The index to use.
|
|
108
|
+
:type index: list
|
|
109
|
+
:param predictions: The predictions to index.
|
|
110
|
+
:type predictions: list
|
|
111
|
+
"""
|
|
112
|
+
if not isinstance(index, list):
|
|
113
|
+
index = list(index)
|
|
114
|
+
if isinstance(predictions, list):
|
|
115
|
+
predictions = [predictions[i] for i in index]
|
|
116
|
+
else:
|
|
117
|
+
predictions = predictions[index]
|
|
118
|
+
return predictions
|
|
119
|
+
|
|
120
|
+
def predict(self, X):
|
|
121
|
+
"""Predict the class labels for the provided data.
|
|
122
|
+
|
|
123
|
+
:param X: Data to predict the labels for.
|
|
124
|
+
:type X: pandas.DataFrame
|
|
125
|
+
:return: Predicted class labels.
|
|
126
|
+
:rtype: list
|
|
127
|
+
"""
|
|
128
|
+
index = X.index
|
|
129
|
+
predictions = self.index_predictions(index, self.predictions)
|
|
130
|
+
return predictions
|
|
131
|
+
|
|
132
|
+
def predict_proba(self, X):
|
|
133
|
+
"""Predict the class probabilities for the provided data.
|
|
134
|
+
|
|
135
|
+
:param X: Data to predict the probabilities for.
|
|
136
|
+
:type X: pandas.DataFrame
|
|
137
|
+
:return: Predicted class probabilities.
|
|
138
|
+
:rtype: list[list]
|
|
139
|
+
"""
|
|
140
|
+
index = X.index
|
|
141
|
+
pred_proba = self.index_predictions(index, self.predict_proba)
|
|
142
|
+
return pred_proba
|
|
143
|
+
|
|
144
|
+
|
|
68
145
|
class TestSurrogateErrorTree(object):
|
|
69
146
|
|
|
70
147
|
@pytest.mark.parametrize('analyzer_type', [AnalyzerType.MODEL,
|
|
@@ -319,6 +396,33 @@ class TestSurrogateErrorTree(object):
|
|
|
319
396
|
run_error_analyzer(model, X_test, y_test, feature_names,
|
|
320
397
|
AnalyzerType.MODEL)
|
|
321
398
|
|
|
399
|
+
@pytest.mark.skipif(not pytorch_installed,
|
|
400
|
+
reason="requires torch/torchvision")
|
|
401
|
+
def test_surrogate_error_tree_object_detection(self):
|
|
402
|
+
model_task = ModelTask.OBJECT_DETECTION
|
|
403
|
+
model = get_object_detection_fridge_model()
|
|
404
|
+
|
|
405
|
+
dataset = load_fridge_object_detection_dataset()
|
|
406
|
+
dataset = dataset.iloc[:3]
|
|
407
|
+
X_test = dataset[[ImageColumns.IMAGE]]
|
|
408
|
+
y_test = dataset[[ImageColumns.LABEL]]
|
|
409
|
+
feature_names = [ImageColumns.IMAGE]
|
|
410
|
+
image_mode = 'RGB'
|
|
411
|
+
model = wrap_model(model, X_test, model_task)
|
|
412
|
+
model = SimplifiedWrappedIndexPredictorModel(model, X_test, image_mode)
|
|
413
|
+
extracted_feature_names = ["mean_pixel_value", "is_cool_image"]
|
|
414
|
+
dummy_data = [[141, True], [54, False], [212, True]]
|
|
415
|
+
ext_dataset = pd.DataFrame(data=dummy_data,
|
|
416
|
+
columns=extracted_feature_names)
|
|
417
|
+
|
|
418
|
+
run_error_analyzer(model,
|
|
419
|
+
ext_dataset,
|
|
420
|
+
y_test,
|
|
421
|
+
feature_names,
|
|
422
|
+
AnalyzerType.MODEL,
|
|
423
|
+
categorical_features=[],
|
|
424
|
+
model_task=model_task)
|
|
425
|
+
|
|
322
426
|
|
|
323
427
|
def run_error_analyzer(model, X_test, y_test, feature_names,
|
|
324
428
|
analyzer_type, categorical_features=None,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{erroranalysis-0.5.4 → erroranalysis-0.5.5}/erroranalysis/_internal/error_analyzer/__init__.py
RENAMED
|
File without changes
|
{erroranalysis-0.5.4 → erroranalysis-0.5.5}/erroranalysis/_internal/error_report/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{erroranalysis-0.5.4 → erroranalysis-0.5.5}/erroranalysis/error_correlation_methods/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|