<div class="section-label"><span class="num">02</span> MaxFit</div> <div class="section-title">Solve for the strongest <em>fit</em>.</div> `POST /maxfit` evaluates partial-sample regression across a range of censors and thresholds, then keeps the calibration with the strongest (adjusted) fit. That is the hosted counterpart of [[Functions/MaxFit|MaxFit]]. Use MaxFit when the attribute set is already fixed and you want the engine to pick the threshold. For primary analysis, prefer [[API/Prediction Engine/Grid|Grid]]. **Call:** `POST /maxfit` **Auth:** `x-api-key` header + `access_id` in the body **Returns:** [[API/Prediction Engine/Results#Task receipt|task receipt]] — then [[API/Prediction Engine/Results|GET /results]] ## Signature ```http POST https://api.csanalytics.io/v2/prediction-engine/maxfit ``` Required JSON body (basic spec): ```text { access_id, # user access id y, # outcomes, N × 1 X, # attributes, N × K theta # circumstances, 1 × K } ``` ## Quick start The operation below is loaded live from the v2 OpenAPI spec. ```openapi spec: basic path: /maxfit method: post ``` ```python import json import requests url = "https://api.csanalytics.io/v2/prediction-engine/maxfit" payload = { "access_id": "CSA_ACCESS_ID", "y": [[18.8], [2.3], [3.0], [6.7], [15.2], [20.9], [4.0]], "X": [ [25.0, 2.0, 76.0, 53.7, 23.1], [29.0, 1.0, 78.0, 39.1, 5.7], [32.0, 2.0, 77.0, 54.1, 5.3], [30.0, 5.0, 82.0, 68.7, 8.7], [24.0, 1.0, 69.0, 51.0, 20.3], [25.0, 2.0, 79.0, 50.2, 20.0], [35.0, 3.0, 80.0, 51.5, 9.4], ], "theta": [[24.0, 5.0, 81.0, 60.0, 11.0]], } headers = { "x-api-key": "CSA_API_KEY", "Content-Type": "application/json", "Connection": "keep-alive", } response = requests.post(url, headers=headers, data=json.dumps(payload)) ``` A 200 response is the task receipt: <span class="mono">job_id</span> and <span class="mono">job_code</span>. ## Custom settings The extended spec adds PSR options plus the MaxFit threshold list. ```openapi spec: extended path: /maxfit method: post ``` ```python payload = { "access_id": "CSA_ACCESS_ID", "y": [...], "X": [...], "theta": [[24.0, 5.0, 81.0, 60.0, 11.0]], "threshold": [0, 0.20, 0.50, 0.80], "is_threshold_percent": True, "most_eval": True, "eval_type": "both", } ``` ## Results [[API/Prediction Engine/Results|GET /results]] returns the winning forecast and fit, plus extended diagnostics such as <span class="mono">r_star</span> (the threshold that maximized fit). For categorical analysis: [[API/Prediction Engine/Binary|Binary]]. ## Related - [[API/Introduction|API]] - [[API/Prediction Engine/Grid|Grid]] · [[API/Prediction Engine/PSR|PSR]] - [[Functions/MaxFit|MaxFit (local)]] <div class="btn-row center"> <a class="btn-primary" href="/API/Prediction%20Engine/Results">Retrieve results</a> <a class="btn-ghost" href="/API/Prediction%20Engine/PSR">PSR</a> </div>