Shipment readiness / Python + machine learning

Connect Python machine learning to Decision Lab.

Keep your model in Python. Pass its estimates to Decision Lab’s planning and learning assessments, then bring the findings back into your own application. A shipment example shows the integration in practice.

Jonathan Nacionales 6 min read

A Python machine learning model supplies estimates to Decision Lab’s planning and learning assessments, which return findings to a Python report.

The case in brief

At stake. Maya needs a shipment decision before noon. Her analyst can estimate registration in Python, but a probability alone does not say whether a $200 check justifies its fee, leaves time to respond or enables a shipment that meets the requirements.

How it resolves. The Python application connects a scikit-learn model to Decision Lab through the public Python SDK. It supplies numerical estimates, evaluates complete shipment responses and returns a focused report. The timely check offers $227.04 expected improvement under fictional assumptions; the same model supports a different proposal when the fee or timing changes.

Maya’s analyst works in Python. The team has shipment history, a scikit-learn model and a question to answer before the noon reservation cutoff: should Maya buy a registration check before choosing freight? This example connects that Python model to Decision Lab and returns the findings to a report built by the same Python application.

Backup meets the recorded shipment requirements for $6,000. Direct costs $4,000 but needs current, correctly scoped registration confirmation. The model estimates the chance of registration; the team also needs to account for the check’s fee, the time to respond and which complete shipment arrangements remain available.

The complete Python integration includes the estimator, input adapter, pinned Decision Lab apps and report code. Maya, the history and all amounts are fictional. The screenshots show the sample’s actual generated reports.

The analyst prepares the inputs and numerical basis. Maya uses the resulting report to decide whether to buy the check and retain a fallback, or propose Backup now. Responsible people obtain the actual confirmation, authorize spending and arrange freight.

One Python application connects prediction and decision.

The developer could write the shipment requirements, check-and-response comparison and report contracts alongside the model. In this integration, the team keeps its Python data science code and presentation while reusing Decision Lab’s authored planning and learning assessments.

Offline training produces a fitted model for the Python estimator. The adapter calls Decision Lab’s public Python SDK with pinned app definitions. Complete planning eligibility and costs return to the adapter, which binds them with numerical estimates into the information-value assessment. Returned findings feed the Python report renderer.
Component view. The team’s Python application owns estimation, the bindings and presentation. The public SDK evaluates the pinned app definitions. Complete planning findings return through the adapter as inputs to the information-value assessment. View full-size SVGSee the implementation

The adapter is the connection between the parts. It calls the public decision_lab package, checks the planning findings and binds them into the information-value assessment alongside the numerical estimates. The pinned app definitions supply the requirements and comparison rules; the Python report renderer presents the returned findings.

The estimate and the decision answer different questions. Machine learning estimates registration from history. A commitment assessment establishes which complete shipment responses meet the recorded requirements. A learning assessment compares the check and its possible responses with the best supported outside option: reserve Backup now. This is the composition of assessment patterns that the Python application connects through the SDK. The estimator stays in Python; the authored apps supply the planning and information-value rules.

Keep the machine learning model in Python.

The sample trains a standardized logistic regression model with scikit-learn and calibrates its scores on a separate chronological partition. At assessment time, the fitted model supplies a registration probability through ordinary Python calls:

Predict calibrated probabilities with scikit-learn · estimation.py, lines 58–60
def calibrated_probabilities(bundle: dict[str, Any], frame: pd.DataFrame) -> np.ndarray:
    scores = bundle["classifier"].decision_function(frame).reshape(-1, 1)
    return bundle["calibrator"].predict_proba(scores)[:, 1]

For the worked case, the model proposes 24.96%. Historical check records separately supply the frequencies of confirmation and no usable result. These estimates stay in the Python application; they do not need to be rewritten as Decision Lab rules. The estimator also returns provenance and applicability information so an unsupported input can withhold a usable estimate.

Bind the estimates to Decision Lab’s inputs.

The adapter places the proposed registration probability into the information-value app’s declared states:

Bind the model estimate to the authored learning case · decision.py, lines 140–147
    probability = proposal["probabilityRegistered"]
    inputs.update(id=f"{business['id']}-learning", currentTime=parameters["currentTime"],
                  cashBudget=parameters["cashLimit"])
    inputs["probabilityBasis"] = {"source": "Proposed model basis " + lab.hashing.canonical_hash(proposal),
                                  "scope": inputs["scope"]}
    inputs["priors"] = [{"state": "registered", "probability": probability},
                        {"state": "not_registered", "probability": 1 - probability}]
    inputs["acceptedFacts"] = []

Here probability comes from the Python proposal. The adapter also supplies the check’s fee, duration and report likelihoods. It retains the authored meanings of registered, not_registered and an inconclusive report. The probability is a numerical premise; actual registration confirmation remains a separate requirement for Direct.

Planning contributes another part of the input: which complete arrangements meet the timing, capacity, expense, cash and recorded-permission conditions when reserving now or responding after the check. The adapter carries those findings into the information-value assessment, including their retained source references. Its candidates now mean a check together with responses to its possible reports, rather than another freight quote. Their expected complete expense is compared with the supported reserve-now alternative.

Call Decision Lab through the Python SDK.

The application opens its pinned planning and learning packages with lab.apps.open. A DecisionLab instance then evaluates the authored apps through the same public Python call:

Evaluate an authored app through the Python SDK · decision.py, lines 94–95
    run = lab.run(app=app, case=inputs, timeout_ms=30_000,
                  run_id=f"{business['id'].lower()}-{tag}", created_at=business["asOf"])

The application assesses the shipment responses first, then combines their complete findings with the probability proposal, fee and response time. When the numerical basis is supported and accepted under the sample’s policy, the learning assessment returns its comparison and complete reports to Python.

If the estimate is unsupported or its basis awaits review, the application retains the planning findings and leaves the information-value comparison unassessed. A different Python estimator could supply the same declared numerical inputs after its meanings and applicability are checked.

Check the planning result before using it as a premise

Finishing execution and establishing a complete planning assessment are separate checks. The sample resolves the native assessment before passing operating eligibility downstream:

Require a complete planning assessment · decision.py, lines 101–105
def resolve_planning(lab: DecisionLab, run: dict) -> dict:
    result = lab.commitment.resolve_commitment_assessment(run["assessment"], run["report"])
    if not lab.commitment.is_assessment_complete(result):
        raise ValueError("A complete current planning assessment is required for this handoff.")
    return result

estimate, learning_case and the surrounding orchestration are sample application functions. lab.run, lab.apps.open and the commitment assessment helpers are public SDK operations. The pinned source shows their complete context.

Use the same model with a different decision context.

The Python application renders the returned findings as a business report. With a timely $200 check, it reports $5,772.96 expected complete cost, including the check fee, against the supported $6,000 fallback now. The conditional expected improvement is $227.04.

Change only the fee to $2,500. The model’s features and numerical proposal remain unchanged. Decision Lab now prefers the $6,000 fallback because checking would cost $8,072.96 in expectation:

Shared basis. The same fitted Python model, features and numerical proposal feed the same pinned Decision Lab planning and learning apps. Shipment arrangements, recorded permissions, expense and cash boundaries, and the noon reservation cutoff remain unchanged.

What changes. The Python application supplies a different check fee: $200 or $2,500. The model inputs and the 10:30 a.m. response-ready time stay fixed. Case IDs and titles label the separate scenarios.

A $200 check

Checking has $227.04 of expected improvement.

Check fee
$200
Response ready
10:30 a.m.
Expected complete cost
$5,772.96
The qualified timely report proposes checking, with $5,772.96 expected complete cost, $227.04 expected improvement and a 25.0 percent readiness estimate.
The timely $200 check improves expected complete expense under the supplied numerical basis. It establishes no actual registration, purchase or booking. View full size

Maya can put forward the timely check, retaining Backup if it supplies no usable registration confirmation.

A $2,500 check

Reserving Backup now is preferred.

Check fee
$2,500
Response ready
10:30 a.m.
Expected complete cost
$8,072.96
With the same estimate, the high-fee report prefers reserving now: the $2,500 check raises expected complete cost to $8,072.96.
The check can still return in time, but its $2,500 fee outweighs the expected benefit. View full size

The information can still affect the route, but its higher price exceeds the expected improvement. Maya can propose the supported $6,000 fallback now.

What this means for the decision. The Python model supplies the same numerical premises. Decision Lab evaluates the changed fee against the available responses and returns a different recommendation to the Python application.

The same registration estimate therefore supports different choices because the check’s value depends on its cost and the responses still available. More information is useful here only when its modeled benefit exceeds its complete expense relative to acting now. Changing the check price or duration needs no retraining of this model; changing a shipment requirement belongs in the authored app, and changing the estimator’s intended population needs its own model review.

The same integration preserves different kinds of findings.
Changed conditionIntegration behavior
The $200 check and response are ready at 3 p.m.The planning and learning assessments retain the noon cutoff. Checking leaves no complete response in time; the report proposes Backup now.
Current features fall outside the estimator’s supportPython withholds a usable estimate and leaves learning value unassessed. The independent $6,000 planning finding remains available. Inspect the retained report.

Bring the findings back into your own application.

Maya’s analyst can now give her a report that connects the model’s estimate to the shipment options, cost and cutoff. Open the actual Python report to inspect its concise finding, possible responses and expandable model and calculation details. The same application retains complete SDK runs for another interface or further analysis.

Maya can propose the timely check under the accepted numerical assumptions. The report also makes the downside clear: a valid positive confirmation can enable Direct at $4,200 including the check; otherwise Backup costs $6,200 including the check. The estimated chance of a usable positive report is about 21.35%, below the registration estimate because a check can be inconclusive. These are prospective findings, with purchasing and reservation left to the responsible owners.

The learning-before-commitment decision pattern organizes the overall approach. Its supporting planning assessment establishes available responses; the learning assessment compares their modeled value with acting now. Python supplies the estimator, orchestration and team interface. The complete sample repository shows the training code, adapter, authored apps and report together.

Sources and scope

This standalone Python application uses separate pinned planning and learning apps. It is an integration example, not an added model-training feature in the Marketplace UI. Its explicit acceptance of numerical premises is an application policy, separate from the per-answer and per-result acceptance removed from the current calculation workflow. The earlier guide retains its hypothetical 50/50 and perfect-verification assumptions.

The pinned source includes 1,200 deterministic synthetic records. Chronological training, calibration and held-out evaluation demonstrate the pipeline and establish no real supplier prediction quality. Acceptance records a reviewed numerical basis; it authenticates neither a reviewer nor the underlying facts.

Authoritative, correctly scoped confirmations have authored meanings. Historical records estimate their frequencies and the chance of no result; they do not establish that arbitrary registration reports are accurate. A registration probability never replaces required confirmation. Probability sensitivity values in the report are assumptions, not confidence bounds.

The objective is risk-neutral expected complete shipment expense, counting the check fee once. Revenue, total profit and reserve-now/later-cancel policies are outside the comparison. The verification record and capture notes identify the retained qualified reports and original source. The sample performs no external check, purchase, freight reservation or delivery.

The component illustration uses a viewpoint informed by Philippe Kruchten’s 4+1 architectural view model. It describes the composition of this sample; offline model training is separate from each shipment assessment. The separate use-case illustration records the analyst’s and Maya’s responsibilities.