Skip to content

getaero-io/gtm-eng-skills / skills/deepline-scoring

deepline-scoring

Verified

Use when discovering niche signals, auditing ICP or won/lost evidence, rescoring accounts, or building account and lead scoring Plays. Triggers on fit scoring, engagement scoring, backtesting, holdout evaluation, predictive lift, external proxies, and scoring leakage. Skip pure outreach copy or contributor skill installation tasks.

FileKindSize
.gitignoreother26 B
SKILL.mdskill md12.4 KB
package.jsonmanifest114 B
references/account-website-features.mdmarkdown10.3 KB
references/backtesting-task.mdmarkdown10.0 KB
references/buyer-language-research.mdmarkdown8.6 KB
references/capacity-evidence.mdmarkdown4.4 KB
references/dedupe.mdmarkdown1.5 KB
references/jev-feature-extraction.mdmarkdown8.2 KB
references/keyword-catalog.mdmarkdown4.9 KB
references/pitfalls.mdmarkdown1.6 KB
references/proven-signals.mdmarkdown1.1 KB
references/quality-gate.mdmarkdown2.8 KB
references/report-template.mdmarkdown6.2 KB
references/scorecard-creation.mdmarkdown3.3 KB
references/scorecard-training.mdmarkdown6.5 KB
references/scoring-delivery.mdmarkdown8.3 KB
references/scoring-diagnostics.mdmarkdown8.9 KB
references/scoring-pitfalls.mdmarkdown2.8 KB
references/signal-interpretation.mdmarkdown2.3 KB
references/step-7-prospects.mdmarkdown1.6 KB
references/technology-evidence.mdmarkdown9.4 KB
references/testing-and-evaluation.mdmarkdown6.8 KB
scripts/analyze_signals.pyscript16.9 KB
scripts/analyze_signals_v2.pyscript28.3 KB
scripts/build_feature_matrix.pyscript4.7 KB
scripts/collect_sources.pyscript16.1 KB
scripts/dedupe_utils.pyscript15.6 KB
scripts/dedupe_utils_v2.pyscript15.7 KB
scripts/find_contacts_v2.pyscript1.9 KB
scripts/hubspot_accounts.pyscript7.1 KB
scripts/jev_features.pyscript7.1 KB
scripts/replay-score.play.tsscript2.3 KB
scripts/requirements-scorecard.txtmarkdown263 B
scripts/scorecard/__init__.pyscript514 B
scripts/scorecard/config.pyscript5.0 KB
scripts/scorecard/explainer_artifacts.pyscript8.4 KB
scripts/scorecard/pipeline.pyscript38.9 KB
scripts/scorecard/report.pyscript30.4 KB
scripts/scorecard/scorer.pyscript17.3 KB
scripts/scorecard/specs.pyscript1.3 KB
scripts/scoring_contract.tsscript7.5 KB
scripts/technology_evidence.pyscript3.8 KB
scripts/tests/contract_check.tsscript1.9 KB
scripts/tests/test_jev_features.pyscript3.4 KB
scripts/tests/test_scorecard.pyscript9.5 KB
scripts/train_scorecard.pyscript20.0 KB
skill-metadata.jsonconfig3.8 KB

scripts/scorecard/explainer_artifacts.py

View on GitHub
from __future__ import annotations

from pathlib import Path
from typing import Dict, Any, Tuple
import json
import pandas as pd
import numpy as np


def assign_bins_numeric(s: pd.Series, edges: list) -> pd.Series:
    from .pipeline import _assign_bins_from_edges
    return _assign_bins_from_edges(s.astype(float), edges)


def _feature_specs_list(preprocess: Dict[str, Any]) -> list[dict]:
    if isinstance(preprocess, dict):
        feats = preprocess.get("features", [])
    else:
        feats = preprocess
    return list(feats or [])


def apply_feature_transform(df: pd.DataFrame, feature_spec: Dict[str, Any]) -> tuple[str, pd.Series]:
    col_in = feature_spec.get("input")
    col_out = feature_spec.get("output", col_in)
    t = feature_spec.get("transform") or {}
    # If the input column is missing but the output column already exists (pre-binned frame), use it directly
    if (col_in not in df.columns) and (col_out in df.columns):
        return col_out, df[col_out]
    if not t:
        return col_out, df[col_in]
    if t.get("boolean_text"):
        from .pipeline import canonical_bool
        return col_out, canonical_bool(df[col_in])
    if "edges" in t and ("mapping" not in t):
        return col_out, assign_bins_numeric(df[col_in], t["edges"])
    if "mapping" in t:
        mapping = t.get("mapping", {})
        other = t.get("unknown_label", "Other")
        return col_out, df[col_in].astype("object").map(mapping).fillna(other).astype(str)
    return col_out, df[col_in]


def points_map_for(specs: dict, out_col: str) -> Dict[str, int]:
    model = specs.get("model", {})
    feats = model.get("features", {}) or {}
    fdef = feats.get(out_col, {}) or {}
    return {str(k): int(v) for k, v in (fdef.get("points_map", {}) or {}).items()}


def build_binned_explainer(
    preprocess: Dict[str, Any],
    specs: Dict[str, Any],
    training_df: pd.DataFrame,
    y_col: str,
        model_version: str | None = None,
        overrides: Dict[str, Dict[str, int]] | None = None,
) -> pd.DataFrame:
    baseline_rate = float(training_df[y_col].astype(int).mean())
    rows = []
    for spec in _feature_specs_list(preprocess):
        col_in = spec.get("input")
        out_col, binned = apply_feature_transform(training_df, spec)
        if (col_in not in training_df.columns) and (out_col not in training_df.columns):
            continue
        pmap = points_map_for(specs, out_col)
        grp = pd.DataFrame({"bin_label": binned.astype("object").astype(str), "y": training_df[y_col].astype(int)})
        agg = grp.groupby("bin_label").agg(n=("y","size"), rate=("y","mean")).reset_index()
        agg["feature"] = str(out_col)
        agg["baseline_rate"] = baseline_rate
        agg["historical_lift"] = agg.apply(lambda r: float(r["rate"]/baseline_rate) if baseline_rate > 0 else np.nan, axis=1)
        agg["points"] = agg["bin_label"].map(pmap).fillna(0).astype(int)
        # Annotate overrides at binned level if provided
        if overrides and out_col in overrides:
            ovmap = overrides.get(out_col, {}) or {}
            agg["override_points"] = agg["bin_label"].map(lambda v: ovmap.get(str(v))).astype("Int64")
        else:
            agg["override_points"] = pd.Series([pd.NA] * len(agg), index=agg.index, dtype="Int64")
        rows.append(agg)
    out = pd.concat(rows, ignore_index=True) if rows else pd.DataFrame(columns=[
        "feature","bin_label","n","rate","baseline_rate","historical_lift","points","override_points"
    ])
    out["ref_bin"] = (out["points"] == 0)
    if model_version is not None:
        out.insert(0, "model_version", str(model_version))
    return out.sort_values(["feature","points","n"], ascending=[True, False, False]).reset_index(drop=True)


def build_raw_explainer(
    preprocess: Dict[str, Any],
    specs: Dict[str, Any],
    training_df: pd.DataFrame,
    y_col: str,
        model_version: str | None = None,
        overrides: Dict[str, Dict[str, int]] | None = None,
) -> pd.DataFrame:
    """
    Unified "raw" explainer:
      - For mapped categoricals: include raw_value and bin_label rows.
      - For numeric/edge-binned features: include bin-level rows with raw_value set to None.
    """
    baseline_rate = float(training_df[y_col].astype(int).mean())
    rows: list[pd.DataFrame] = []
    for spec in _feature_specs_list(preprocess):
        col_in = spec.get("input")
        out_col = spec.get("output", col_in)
        t = spec.get("transform") or {}
        mapping = t.get("mapping") if isinstance(t, dict) else None
        pmap = points_map_for(specs, out_col)

        if mapping:
            # Raw categorical values mapped to bins
            if col_in not in training_df.columns:
                continue
            other = t.get("unknown_label", "Other")
            bin_s = training_df[col_in].astype("object").map(mapping).fillna(other).astype(str)
            raw_vals = training_df[col_in].astype("object")
            tmp = pd.DataFrame({"raw_value": raw_vals, "bin_label": bin_s, "y": training_df[y_col].astype(int)})
            agg = tmp.groupby(["raw_value","bin_label"]).agg(n=("y","size"), rate=("y","mean")).reset_index()
            agg["feature"] = str(col_in)
            agg["baseline_rate"] = baseline_rate
            agg["historical_lift"] = agg.apply(lambda r: float(r["rate"]/baseline_rate) if baseline_rate > 0 else np.nan, axis=1)
            agg["points"] = agg["bin_label"].map(pmap).fillna(0).astype(int)
            # Add override annotation for raw level
            if overrides and ((spec.get("transform", {}) or {}).get("mapping") or True):
                ovmap = (overrides.get(col_in, {}) or {})
                ov_series = agg["raw_value"].map(lambda v: ovmap.get(str(v)))
                agg["override_points"] = ov_series.astype("Int64")
            else:
                agg["override_points"] = pd.Series([pd.NA] * len(agg), index=agg.index, dtype="Int64")
            rows.append(agg[["feature","raw_value","bin_label","n","rate","baseline_rate","historical_lift","points","override_points"]])
        else:
            # Numeric features: emit bin-level rows (raw_value is None)
            out_col2, binned_series = apply_feature_transform(training_df, spec)
            if out_col2 is None:
                continue
            grp = pd.DataFrame({"bin_label": binned_series.astype("object").astype(str), "y": training_df[y_col].astype(int)})
            agg = grp.groupby("bin_label").agg(n=("y","size"), rate=("y","mean")).reset_index()
            agg["feature"] = str(out_col)
            agg["raw_value"] = None
            agg["baseline_rate"] = baseline_rate
            agg["historical_lift"] = agg.apply(lambda r: float(r["rate"]/baseline_rate) if baseline_rate > 0 else np.nan, axis=1)
            agg["points"] = agg["bin_label"].map(pmap).fillna(0).astype(int)
            rows.append(agg[["feature","raw_value","bin_label","n","rate","baseline_rate","historical_lift","points"]])

    out = pd.concat(rows, ignore_index=True) if rows else pd.DataFrame(columns=[
        "feature","raw_value","bin_label","n","rate","baseline_rate","historical_lift","points","override_points"
    ])
    if model_version is not None:
        out.insert(0, "model_version", str(model_version))
    return out.sort_values(["feature","points","n"], ascending=[True, False, False]).reset_index(drop=True)


def write_explainers_to_csv(
    preprocess_path: str,
    specs_path: str,
    training_csv_path: str,
    y_col: str,
    out_dir: str,
    model_version: str | None = None,
) -> Dict[str, str]:
    pre = json.loads(Path(preprocess_path).read_text())
    specs = json.loads(Path(specs_path).read_text())
    df = pd.read_csv(training_csv_path, dtype=str, keep_default_na=False).replace({"": np.nan})  # keep "NA"/"None" categories literal
    # Load overrides.json if present alongside specs
    overrides_path = Path(specs_path).parent / "overrides.json"
    overrides: Dict[str, Dict[str, int]] | None = None
    if overrides_path.exists():
        try:
            overrides = json.loads(overrides_path.read_text())
        except Exception:
            overrides = None
    binned = build_binned_explainer(pre, specs, df, y_col, model_version=model_version, overrides=overrides)
    raw = build_raw_explainer(pre, specs, df, y_col, model_version=model_version, overrides=overrides)
    base = Path(out_dir); base.mkdir(parents=True, exist_ok=True)
    p1 = base / "scorecard_explainer_binned.csv"
    p2 = base / "scorecard_explainer_raw.csv"
    binned.to_csv(p1, index=False)
    raw.to_csv(p2, index=False)
    return {"binned_csv": str(p1), "raw_csv": str(p2)}
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall