Skip to main content

proxyml

Python SDK for the ProxyML API.

creditg_car_counterfactual

Why ProxyML?

Most explainability tools require sending your data to a third-party server. ProxyML never sees your training data. You generate synthetic data locally, score it with your own model, and only the surrogate model and summary statistics are uploaded — your data stays yours.

Installation

pip install proxyml

Want to train a challenger model locally, with no round-trip to the API? Install the local extra (adds scikit-learn and scipy):

pip install 'proxyml[local]'

Setup

ProxyML requires an API key. Set it as an environment variable before importing the package:

export PROXYML_API_KEY="your-api-key"

Optionally override the base URL (defaults to https://api.proxyml.ai/api/v1):

export PROXYML_BASE_URL="https://api.proxyml.ai/api/v1"

Quick Start

import pandas as pd
import proxyml
from proxyml import get_schema

# 1. Load your dataset and generate a schema
df = pd.read_csv("data.csv")
schema = get_schema(df, immutable_cols=["age", "gender"])

# 2. Upload the schema under a name — synthesis and training reference it by name
SCHEMA_NAME = "my_schema"
proxyml.put_schema(schema, name=SCHEMA_NAME)

# 3. Generate synthetic training data
synth_df = proxyml.synthesize_data(num_points=500, schema_name=SCHEMA_NAME)

# 4. Score synthetic data with your black-box model
predictions = my_model.predict(synth_df.values.tolist())

# 5. Train a surrogate model
proxyml.train_surrogate(
    samples=synth_df.values.tolist(),
    predictions=predictions,
    feature_names=list(synth_df.columns),
    schema_name=SCHEMA_NAME,
)

# 6. Find a counterfactual explanation
sample = df.iloc[0].tolist()
cf = proxyml.find_counterfactual(sample=sample, target=1, version=None)

if cf is not None:
    original = synth_df.iloc[0].to_dict()
    cf_dict = cf.iloc[0].to_dict()
    current_pred = my_model.predict([sample])[0]
    cf_pred = my_model.predict([cf.values.tolist()[0]])[0]

    explanation = proxyml.interpret_counterfactual(
        sample=original,
        counterfactual=cf_dict,
        prediction_changed=(current_pred != cf_pred),
    )
    print(explanation)

See docs/quickstart.md for a full walkthrough and docs/api.md for complete API reference.

Core Concepts

Surrogate model — A fast, interpretable model trained to approximate your black-box model's behavior on synthetic data. Once trained, it can be queried directly via the ProxyML API.

Challenger model — Trained the same way as a surrogate, but locally (proxyml.local, no round-trip to the API) and against either real ground-truth labels (a genuine challenger to compare against a champion model) or a black box's predictions (a surrogate/explainer). Its export is structurally identical to a server-trained surrogate's, so the two can be compared and scored with the exact same arithmetic.

Counterfactual explanation — Given a prediction, a counterfactual is the minimal change to input features that would produce a different prediction. It answers: "What would have to be different for the outcome to change?"

Schema — Describes the statistical properties of each feature (type, range, distribution). Used to generate realistic synthetic data and constrain counterfactual search.

API Reference

Function Description
get_schema(df, immutable_cols) Infer a FeatureSchema from a DataFrame
put_schema(schema, name) Upload a schema to the API under a name
synthesize_data(num_points, sample, as_df, schema_name) Generate synthetic data points
train_surrogate(samples, predictions, feature_names, task, test_size, schema_name) Train a surrogate model
train_auto_surrogate(data, target_col, ...) Load data + train a surrogate in one call, skipping synthesis
export_surrogate(version) Export a surrogate for offline scoring via predict_from_export
predict(sample, version) Score a single sample with the surrogate model
find_counterfactual(sample, target, ...) Find a counterfactual for a given sample
interpret_counterfactual(sample, counterfactual, ...) Generate a human-readable explanation
proxyml.local.train_challenger(df, target, schema, ...) Train a challenger model locally — no API round-trip (pip install 'proxyml[local]')
proxyml.local.train_auto_challenger(data, target_col, ...) Load data + train a local challenger in one call

Full documentation: docs/api.md

Examples

License

Apache 2.0 — see LICENSE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

proxyml-0.4.0.tar.gz (33.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

proxyml-0.4.0-py3-none-any.whl (23.1 kB view details)

Uploaded Python 3

File details

Details for the file proxyml-0.4.0.tar.gz.

File metadata

  • Download URL: proxyml-0.4.0.tar.gz
  • Upload date:
  • Size: 33.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for proxyml-0.4.0.tar.gz
Algorithm Hash digest
SHA256 48fec32cdeac9b5d1e996018683839e9d6f3c13f59142333ba4c11152c29d922
MD5 b03f62a0650be0e765c6b1f086e677d4
BLAKE2b-256 50a0c9925e7b4c4e642d0d61af614a41232cb0941beacaa21d54170ff5e567b4

See more details on using hashes here.

File details

Details for the file proxyml-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: proxyml-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 23.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for proxyml-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 30b3ae62c22bb60c076aa94cea5454d7bd246cfa5917cb276ce559030ffd8caf
MD5 2ad7ab72094157ba3642a5bc35ebe2d6
BLAKE2b-256 5ad8387fd139ca70518a39f5c47a327db27839ead8f4beeb1fd9235930fdbc8e

See more details on using hashes here.

Release history Release notifications | RSS feed

0.9.0

2 files

0.8.0

2 files

0.7.0

2 files

0.6.0

2 files

0.5.0

2 files

0.4.1

2 files

This release

0.4.0 This release

2 files

0.3.0

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.9

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page