What-If Analysis
The What-If Studio enables scenario-based model exploration. Create alternative scenarios by changing feature values and compare prediction outcomes side-by-side.
Overview
What-If Analysis lets you answer questions like:
“What would happen if this customer’s tenure increased from 3 to 24 months?”
“How does changing the contract type affect churn probability?”
“Which features have the most impact on the prediction?”
The workflow is:
Create a session tied to a deployed model and baseline input
Add scenarios with modified feature values
Run scenarios to get predictions
Compare all scenarios against the baseline
Creating a Session
A session is tied to a deployment and requires a baseline set of feature values (the “current state” you want to explore alternatives for):
resp = requests.post(f"{BASE_URL}/api/studio/sessions", headers=HEADERS, json={
"project_id": project_id,
"deployment_id": deployment_id,
"baseline_input": {
"tenure_months": 3,
"monthly_charges": 75.0,
"contract": "Month-to-month",
"payment_method": "Electronic check",
"internet_service": "Fiber optic",
"online_security": "No",
},
})
session_id = resp.json()["id"]
Getting the Feature Schema
Before creating sessions, retrieve the expected features for a deployment:
resp = requests.get(
f"{BASE_URL}/api/studio/deployments/{deployment_id}/schema",
headers=HEADERS,
)
schema = resp.json()
for feat in schema["features"]:
print(f" {feat['name']}: {feat['dtype']} (values: {feat.get('domain', 'numeric')})")
Adding Scenarios
Each scenario modifies one or more features from the baseline:
# Scenario 1: longer tenure
resp = requests.post(
f"{BASE_URL}/api/studio/sessions/{session_id}/scenarios",
headers=HEADERS,
json={
"name": "Longer tenure (24 months)",
"changes": {"tenure_months": 24},
},
)
scenario_1_id = resp.json()["id"]
# Scenario 2: switch to annual contract
resp = requests.post(
f"{BASE_URL}/api/studio/sessions/{session_id}/scenarios",
headers=HEADERS,
json={
"name": "Annual contract + security",
"changes": {
"contract": "One year",
"online_security": "Yes",
},
},
)
scenario_2_id = resp.json()["id"]
# Scenario 3: premium package
resp = requests.post(
f"{BASE_URL}/api/studio/sessions/{session_id}/scenarios",
headers=HEADERS,
json={
"name": "Premium package",
"changes": {
"contract": "Two year",
"monthly_charges": 110.0,
"online_security": "Yes",
"internet_service": "Fiber optic",
},
},
)
scenario_3_id = resp.json()["id"]
Running Scenarios
Execute each scenario to get predictions:
for sid in [scenario_1_id, scenario_2_id, scenario_3_id]:
requests.post(
f"{BASE_URL}/api/studio/scenarios/{sid}/run",
headers=HEADERS,
)
Comparing Results
Compare all scenarios against the baseline:
resp = requests.get(
f"{BASE_URL}/api/studio/sessions/{session_id}/compare",
headers=HEADERS,
)
comparison = resp.json()
baseline = comparison["baseline"]
print(f"Baseline prediction: {baseline['prediction']}")
print(f"Baseline probabilities: {baseline.get('probabilities', {})}")
for scenario in comparison["scenarios"]:
print(f"\n{scenario['name']}:")
print(f" Prediction: {scenario['prediction']}")
print(f" Probabilities: {scenario.get('probabilities', {})}")
print(f" Changed features: {scenario.get('changes', {})}")
Listing Sessions
View all What-If sessions for a project:
resp = requests.get(
f"{BASE_URL}/api/studio/sessions",
headers=HEADERS,
params={"project_id": project_id, "limit": 20},
)
for s in resp.json()["items"]:
print(f" {s['id']}: deployment={s['deployment_id']}, scenarios={s.get('scenario_count', 0)}")
SDK Example
from coreplexml import CorePlexMLClient
client = CorePlexMLClient(base_url=BASE_URL, api_key=API_KEY)
# Create session
session = client.studio.create_session(
project_id=project_id,
deployment_id=deployment_id,
baseline_input={"tenure_months": 3, "monthly_charges": 75.0},
)
# Add scenarios
s1 = client.studio.create_scenario(
session["id"],
name="Longer tenure",
changes={"tenure_months": 24},
)
client.studio.run_scenario(s1["id"])
# Compare
comparison = client.studio.compare(session["id"])
See also
ML Studio (What-If) API – Full Studio API reference
MLOps & Model Serving – Deploy models for What-If analysis