%%{init: {"theme":"base", "flowchart": {"useMaxWidth": false, "htmlLabels": true, "wrappingWidth": 340, "padding": 14, "nodeSpacing": 40, "rankSpacing": 44}}}%%
flowchart TD
subgraph Setup [Build task]
A["Define task objects<br/>recipe(), model spec, metric_set()"]
B["Assemble pipeline<br/>workflow() + add_recipe() + add_model()"]
C["Create holdout split<br/>initial_split()"]
A --> B --> C
end
C --> D{"Need tuning / resampling?"}
subgraph TunePath [If yes]
E["Build CV folds from train only<br/>vfold_cv(training(split))"]
F["Tune candidates<br/>tune_grid()"]
G["Pick best by metric<br/>select_best()"]
H["Lock in best hyperparameters<br/>finalize_workflow()"]
E --> F --> G --> H
end
subgraph OneShotPath [If no]
I["One-shot training fit<br/>fit(wf, training(split))"]
M["Generate train/test predictions<br/>augment()"]
I --> M
end
D -->|"Yes"| E
D -->|"No"| I
H --> J["Final honest test estimate<br/>last_fit(..., split)"]
J --> K["Summarize holdout metrics/preds<br/>collect_metrics(), collect_predictions()"]
M --> N["One-shot check (faster, less robust)<br/>accuracy()/conf_mat() on augment outputs"]
classDef setup fill:#f3f8ff,stroke:#1f4f99,color:#0f2b56,stroke-width:1.5px;
classDef decision fill:#fff4cc,stroke:#8a6d00,color:#3d2f00,stroke-width:1.5px;
classDef tune fill:#e9f9ef,stroke:#1f7a3f,color:#124825,stroke-width:1.5px;
classDef oneshot fill:#f4f4f4,stroke:#555555,color:#222222,stroke-width:1.5px;
classDef final fill:#ffeef0,stroke:#a12a3a,color:#5c1220,stroke-width:1.5px;
class A,B,C setup;
class D decision;
class E,F,G,H tune;
class I,M,N oneshot;
class J,K final;