model_name = "customer-churn-predictor-v1" # Choose a unique name for your model
upload_id = "YOUR_UPLOAD_ID" # Replace with the ID from your data upload
build_payload = {
"goal": "Predict customer churn based on usage patterns like login frequency, support tickets, and subscription duration.",
"upload_id": upload_id, # Use the ID obtained from data upload
# Optionally provide schemas if inference is not desired or needs guidance
# "input_schema": {
# "login_frequency_last_30d": "int",
# "support_tickets_last_90d": "int",
# "subscription_months": "int",
# "plan_type": "str"
# },
# "output_schema": {
# "churn_prediction": "int" # e.g., 1 for churn, 0 for no churn
# },
"metric": "f1", # Optimize for F1 score
"max_iterations": 5 # Try up to 5 approaches
}
print(f"Starting build for model: {model_name}")
try:
response = requests.post(
f"{base_url}/models/{model_name}",
headers=headers,
json=build_payload
)
response.raise_for_status() # Raise HTTPError for bad responses (4xx or 5xx)
build_result = response.json()
model_id = build_result.get("model_id") # Typically format: name:version or similar
print("\nBuild request submitted successfully!")
print(f" Model ID: {model_id}")
print(f" Initial Status: {build_result.get('status')}")
print(f"Monitor progress using the status endpoint.")
# Store model_id for status checking and inference later
# Example: store model_name and model_version if ID is like "name:version"
if model_id and ':' in model_id:
m_name, m_version = model_id.split(':', 1)
print(f" Model Name: {m_name}, Model Version: {m_version}")
else:
# Handle cases where model_id format might differ
print(" Could not parse model name/version from model_id.")
except requests.exceptions.HTTPError as http_err:
print(f"HTTP error occurred: {http_err}")
print(f"Response Text: {http_err.response.text}")
except requests.exceptions.ConnectionError as conn_err:
print(f"Connection error occurred: {conn_err}")
except Exception as err:
print(f"Other error occurred: {err}")