proxyml 0.1.0__tar.gz → 0.1.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: proxyml
3
- Version: 0.1.0
3
+ Version: 0.1.2
4
4
  Summary: Python SDK for calling the ProxyML API
5
5
  Author-email: ProxyML <contact@proxyml.ai>
6
6
  License: Apache License
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "proxyml"
7
- version = "0.1.0"
7
+ version = "0.1.2"
8
8
  description = "Python SDK for calling the ProxyML API"
9
9
  readme = "README.md"
10
10
  license = {file = "LICENSE"}
@@ -5,6 +5,7 @@ from proxyml.client import (
5
5
  predict,
6
6
  find_counterfactual,
7
7
  interpret_counterfactual,
8
+ get_feature_importances,
8
9
  )
9
10
  from proxyml.schema import (
10
11
  get_schema,
@@ -44,6 +44,15 @@ def put(endpoint: str, payload: dict) -> requests.models.Response:
44
44
  return r
45
45
 
46
46
 
47
+ def get(endpoint: str, params: dict) -> requests.models.Response:
48
+ r = requests.get(
49
+ url=f'{PROXYML_BASE_URL}{endpoint}',
50
+ headers=_headers(),
51
+ params=params
52
+ )
53
+ return r
54
+
55
+
47
56
  def put_schema(schema: dict):
48
57
  r = put(endpoint='/schema', payload=schema)
49
58
  if r.status_code == 200:
@@ -127,10 +136,10 @@ def predict(samples: list, version: int | None): # Defaults to latest version i
127
136
  def find_counterfactual(sample, target, n_neighbors: int = 10000, perturbation_scale: float = 0.1, version: int | None = None, as_df: bool = True):
128
137
  payload = {
129
138
  'instance': sample,
130
- 'target_label': target,
139
+ 'target_label': target.item() if hasattr(target, 'item') else target, # handle numpy scalars
131
140
  'n_neighbors': n_neighbors,
132
141
  'perturbation_scale': perturbation_scale,
133
- }
142
+ }
134
143
  if version: # Also rejects version 0 (versions start at 1)
135
144
  payload['version'] = version
136
145
  r = post(endpoint='/explain/counterfactual', payload=payload)
@@ -188,3 +197,16 @@ def interpret_counterfactual(
188
197
  f"This may indicate the surrogate model does not fully capture "
189
198
  f"the original model's decision boundary in this region."
190
199
  )
200
+
201
+
202
+ def get_feature_importances(version: int | None = None, ):
203
+ params = {'version': version} if version else {}
204
+ r = get(endpoint='/explain/importance', params=params)
205
+ if r.status_code == 200:
206
+ return r.json()
207
+ logger.error(
208
+ "Feature importances failed with status %s: %s",
209
+ r.status_code,
210
+ r.text,
211
+ )
212
+ return None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: proxyml
3
- Version: 0.1.0
3
+ Version: 0.1.2
4
4
  Summary: Python SDK for calling the ProxyML API
5
5
  Author-email: ProxyML <contact@proxyml.ai>
6
6
  License: Apache License
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes