cursus.steps.scripts.piper_metric_generation¶
- check_call(cmd, *a, **k)¶
- install_packages_from_public_pypi(packages)[source]¶
Install packages from standard public PyPI.
- Parameters:
packages (list) – List of package specifications (e.g., [“pandas==1.5.0”, “numpy”])
- install_packages_from_secure_pypi(packages)[source]¶
Install packages from secure CodeArtifact PyPI.
- Parameters:
packages (list) – List of package specifications (e.g., [“pandas==1.5.0”, “numpy”])
- install_packages(packages, use_secure=False)[source]¶
Install packages from PyPI source based on configuration.
This is the main installation function that delegates to either public or secure PyPI based on the USE_SECURE_PYPI environment variable.
- Parameters:
- Environment Variables:
USE_SECURE_PYPI: Set to “true” to use secure PyPI, “false” for public PyPI
Example
# Install from public PyPI (default) install_packages([“pandas==1.5.0”, “numpy”])
# Install from secure PyPI os.environ[“USE_SECURE_PYPI”] = “true” install_packages([“pandas==1.5.0”, “numpy”])
- detect_and_load_predictions(input_dir, preferred_format=None)[source]¶
Load the upstream prediction file, robust to the naming/format divergence across cursus inference & eval steps.
Filenames differ by producer (predictions.* / inference_predictions.* / eval_predictions[_with_comparison].*), all single-file and non-sharded, in one of csv/tsv/parquet/json. This globs the known base names (priority order) across the format list (preferred_format first) and loads the first match.
- resolve_score_column(df, score_field, id_field=None, label_field=None)[source]¶
Resolve which column holds the positive-class model score, robust to the naming divergence across cursus inference/eval producers.
- Resolution order (first match wins):
explicit
score_field(config SCORE_FIELD) if present;prob_class_1— the positive-class prob from XGBoostModelInference / PyTorchModelInference / XGBoostModelEval (standard mode);new_model_prob_class_1— XGBoostModelEval COMPARISON mode (whereprob_class_1is renamed away);the sole
*_probcolumn — LightGBMMTModelInference single-task output (<task_name>_prob), excluding id/label columns;the sole non-id / non-label numeric column in [0, 1].
For MULTI-task LightGBMMT (several
*_probcolumns) the intended positive class is ambiguous —score_fieldMUST be set explicitly; this raises.
- compute_metadata(df, y_true, dataset_type, amount_field)[source]¶
Build the PIPER metadata block shared by every Graph-Line / Tabular file.
Keys use the hyphenated PIPER contract names (record-count, fraud-count, fraud-rate, date-range-start, date-range-end, dataset-type). These are JSON string keys, so they are emitted as literal hyphenated strings.
- write_curve_csv(output_dir, filename, header, x, y)[source]¶
Write a 2-column data CSV (with header) FLAT to output_dir.
- write_metric_json(output_dir, filename, payload)[source]¶
Write a .metric JSON file FLAT to output_dir.
- emit_roc(output_dir, y_true, variant_score, control_score, variant_model_id, control_model_id, metadata)[source]¶
Compute ROC curve(s), write per-series CSVs, and emit roc_curve.metric (Graph-Line). Control series is only added when control_score is present.
- emit_pr(output_dir, y_true, variant_score, control_score, variant_model_id, control_model_id, metadata)[source]¶
Compute PR curve(s), write per-series CSVs, and emit pr_curve.metric (Graph-Line). Control series is only added when control_score is present.
precision_recall_curve returns (precision, recall, thresholds). We plot Recall (x) vs Precision (y) so the CSV header is ‘Recall,Precision’.
- emit_data_statistics(output_dir, metadata)[source]¶
Emit data_preprocessing_statistic.metric (Tabular). Reuses the same metadata block computed for the Graph-Line files.
- main(input_paths, output_paths, environ_vars, job_args)[source]¶
Main entry point for PIPER Metric Generation.
Reads eval predictions, recomputes ROC/PR curves, and emits the PIPER contract (.metric JSON + paired 2-column CSVs) FLAT to the output root so PIPER’s output-root scan finds every artifact.