BETTER-NMA 1.0.0__py3-none-any.whl → 1.0.1__py3-none-any.whl
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.
- BETTER_NMA-1.0.1.dist-info/METADATA +174 -0
- {BETTER_NMA-1.0.0.dist-info → BETTER_NMA-1.0.1.dist-info}/RECORD +4 -4
- BETTER_NMA-1.0.0.dist-info/METADATA +0 -11
- {BETTER_NMA-1.0.0.dist-info → BETTER_NMA-1.0.1.dist-info}/WHEEL +0 -0
- {BETTER_NMA-1.0.0.dist-info → BETTER_NMA-1.0.1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,174 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: BETTER_NMA
|
3
|
+
Version: 1.0.1
|
4
|
+
Summary: NMA: Dendrogram-based model analysis, white-box testing, and adversarial detection
|
5
|
+
Author: BETTER_XAI
|
6
|
+
Author-email: BETTERXAI2025@gmail.com
|
7
|
+
Classifier: Development Status :: 4 - Beta
|
8
|
+
Classifier: Intended Audience :: Developers
|
9
|
+
Classifier: Intended Audience :: Science/Research
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
11
|
+
Classifier: Operating System :: OS Independent
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
19
|
+
Requires-Python: >=3.8
|
20
|
+
Description-Content-Type: text/markdown
|
21
|
+
Requires-Dist: tensorflow>=2.10.0
|
22
|
+
Requires-Dist: pandas>=1.3.0
|
23
|
+
Requires-Dist: python-igraph>=0.10.0
|
24
|
+
Requires-Dist: numpy>=1.21.0
|
25
|
+
Requires-Dist: scikit-learn>=1.0.0
|
26
|
+
Requires-Dist: matplotlib>=3.5.0
|
27
|
+
Requires-Dist: nltk>=3.7
|
28
|
+
Requires-Dist: keras>=2.10.0
|
29
|
+
Requires-Dist: Pillow>=8.0.0
|
30
|
+
|
31
|
+
|
32
|
+
---
|
33
|
+
|
34
|
+
# NMA – Near Misses Analysis
|
35
|
+
|
36
|
+
NMA (**Near Misses Analysis**) is a Python package for analyzing machine learning models through **dendrogram-based hierarchical clustering**, **white-box testing**, and **adversarial attack detection**.
|
37
|
+
|
38
|
+
It provides visualization, explanation, and diagnostic tools to help developers and researchers understand their models’ decision boundaries, identify vulnerabilities, and detect adversarial inputs.
|
39
|
+
|
40
|
+
---
|
41
|
+
|
42
|
+
## ✨ Features
|
43
|
+
|
44
|
+
* 📊 **Dendrogram construction & visualization**
|
45
|
+
|
46
|
+
* Build hierarchical trees from model predictions.
|
47
|
+
* Plot full dendrograms or **sub-dendrograms** for specific labels.
|
48
|
+
|
49
|
+
* 🧪 **White-box testing**
|
50
|
+
|
51
|
+
* Identify problematic training samples likely to cause misclassification.
|
52
|
+
* Run structured analysis across source/target label pairs.
|
53
|
+
|
54
|
+
* 🛡 **Adversarial attack detection**
|
55
|
+
|
56
|
+
* Train a logistic regression adversarial detector.
|
57
|
+
* Detect adversarial images and compute adversarial scores.
|
58
|
+
|
59
|
+
* 🔎 **Model querying & explanations**
|
60
|
+
|
61
|
+
* Query images for predictions with hierarchical context.
|
62
|
+
* Generate **verbal explanations** of model predictions.
|
63
|
+
|
64
|
+
* 🧩 **Cluster analysis tools**
|
65
|
+
|
66
|
+
* Find lowest common ancestors (LCA) in the dendrogram.
|
67
|
+
* Rename clusters for more meaningful interpretation.
|
68
|
+
|
69
|
+
---
|
70
|
+
|
71
|
+
## 📦 Installation
|
72
|
+
|
73
|
+
```bash
|
74
|
+
pip install BETTER_NMA
|
75
|
+
```
|
76
|
+
|
77
|
+
---
|
78
|
+
|
79
|
+
## 🚀 Quickstart
|
80
|
+
|
81
|
+
```python
|
82
|
+
from BETTER_NMA import NMA
|
83
|
+
import numpy as np
|
84
|
+
|
85
|
+
# Example data (replace with your dataset/model)
|
86
|
+
x_train = np.random.rand(100, 32, 32, 3)
|
87
|
+
y_train = np.random.randint(0, 2, size=100)
|
88
|
+
labels = ["cat", "dog"]
|
89
|
+
|
90
|
+
# Your pre-trained model (e.g., Keras, PyTorch wrapper with predict)
|
91
|
+
model = my_model
|
92
|
+
|
93
|
+
# Initialize NMA
|
94
|
+
nma = NMA(
|
95
|
+
x_train=x_train,
|
96
|
+
y_train=y_train,
|
97
|
+
labels=labels,
|
98
|
+
model=model,
|
99
|
+
explanation_method="similarity",
|
100
|
+
save_connections=True
|
101
|
+
)
|
102
|
+
|
103
|
+
# Plot dendrogram
|
104
|
+
nma.plot(title="Model Decision Hierarchy")
|
105
|
+
|
106
|
+
# Run white-box testing
|
107
|
+
issues = nma.white_box_testing(["cat"], ["dog"], analyze_results=True)
|
108
|
+
|
109
|
+
# Train adversarial detector
|
110
|
+
nma.train_adversarial_detector(authentic_images, adversarial_images)
|
111
|
+
|
112
|
+
# Detect if a new image is adversarial
|
113
|
+
result = nma.detect_attack(test_image)
|
114
|
+
|
115
|
+
# Get verbal explanation of an image
|
116
|
+
explanation = nma.verbal_explanation(test_image)
|
117
|
+
print(explanation)
|
118
|
+
```
|
119
|
+
|
120
|
+
---
|
121
|
+
|
122
|
+
## 📚 API Overview
|
123
|
+
|
124
|
+
### Dendrogram & Visualization
|
125
|
+
|
126
|
+
* `plot(sub_labels=None, ...)` – plot full or partial dendrogram.
|
127
|
+
* `plot_sub_dendrogram(sub_labels, ...)` – zoom into specific classes.
|
128
|
+
|
129
|
+
### White-box Testing
|
130
|
+
|
131
|
+
* `white_box_testing(source_labels, target_labels, ...)` – find problematic images.
|
132
|
+
* `get_white_box_analysis(source_labels, target_labels, ...)` – detailed analysis.
|
133
|
+
|
134
|
+
### Adversarial Detection
|
135
|
+
|
136
|
+
* `train_adversarial_detector(authentic_images, attacked_images)` – train detector.
|
137
|
+
* `detect_attack(image, plot_result=False)` – detect adversarial samples.
|
138
|
+
* `adversarial_score(image, top_k=5)` – compute adversarial score.
|
139
|
+
|
140
|
+
### Query & Explanation
|
141
|
+
|
142
|
+
* `query_image(image, top_k=5)` – get predictions & explanation.
|
143
|
+
* `verbal_explanation(image)` – generate natural language explanation.
|
144
|
+
|
145
|
+
### Cluster Analysis
|
146
|
+
|
147
|
+
* `find_lca(label1, label2)` – lowest common ancestor.
|
148
|
+
* `change_cluster_name(cluster_id, new_name)` – rename clusters.
|
149
|
+
|
150
|
+
---
|
151
|
+
|
152
|
+
## 🛠 Requirements
|
153
|
+
|
154
|
+
* Python ≥ 3.8
|
155
|
+
* NumPy, Pandas, Matplotlib, Scikit-learn
|
156
|
+
* (Optional) PyTorch / TensorFlow for model support
|
157
|
+
|
158
|
+
---
|
159
|
+
|
160
|
+
## 📖 Use Cases
|
161
|
+
|
162
|
+
* **Research** – interpret model predictions via hierarchical clustering.
|
163
|
+
* **Robustness testing** – identify adversarial vulnerabilities.
|
164
|
+
* **Explainability** – provide visual + verbal explanations.
|
165
|
+
* **Debugging** – detect mislabeled or problematic training samples.
|
166
|
+
|
167
|
+
---
|
168
|
+
|
169
|
+
## 📜 License
|
170
|
+
|
171
|
+
MIT License – free to use and modify.
|
172
|
+
|
173
|
+
---
|
174
|
+
|
@@ -32,7 +32,7 @@ BETTER_NMA/utilss/classes/preprocessing/z_builder.py,sha256=T8ETfL7mMOgEj7oYNsw6
|
|
32
32
|
BETTER_NMA/utilss/enums/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
33
33
|
BETTER_NMA/utilss/enums/explanation_method.py,sha256=Ang-rjvxO4AJ1IH4mwS8sNpSwt9jn3PlqFbPPT-R9I8,150
|
34
34
|
BETTER_NMA/utilss/enums/heap_types.py,sha256=0z1d2qu1ZCbpWRXKD1dTopn3M4G1CxRQW9HWxVxyPIA,88
|
35
|
-
BETTER_NMA-1.0.
|
36
|
-
BETTER_NMA-1.0.
|
37
|
-
BETTER_NMA-1.0.
|
38
|
-
BETTER_NMA-1.0.
|
35
|
+
BETTER_NMA-1.0.1.dist-info/METADATA,sha256=F4ZFsCJpeZVeYLJ2sMlDEC1c-gZTdvyfJvUxGxEQ2HQ,5100
|
36
|
+
BETTER_NMA-1.0.1.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
37
|
+
BETTER_NMA-1.0.1.dist-info/top_level.txt,sha256=SVRNqWPvCnynWVyXNAYnf9CSQIvMAvE6iyyiGHodQgY,11
|
38
|
+
BETTER_NMA-1.0.1.dist-info/RECORD,,
|
@@ -1,11 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.1
|
2
|
-
Name: BETTER_NMA
|
3
|
-
Version: 1.0.0
|
4
|
-
Requires-Dist: tensorflow
|
5
|
-
Requires-Dist: pandas
|
6
|
-
Requires-Dist: igraph
|
7
|
-
Requires-Dist: numpy
|
8
|
-
Requires-Dist: scikit-learn
|
9
|
-
Requires-Dist: matplotlib
|
10
|
-
Requires-Dist: nltk
|
11
|
-
Requires-Dist: keras
|
File without changes
|
File without changes
|