Case Study Government Intelligence ML in SQL Live at govgreed.vercel.app

Congressional Corruption
Prediction Engine.

Eleven federal data systems. 13,052 active ML predictions. Zero paid data sources.

GovGreed cross-references STOCK Act disclosures, committee seats, campaign contributions, lobbying filings, and pending legislation to generate scored conflict-of-interest predictions for every member of Congress.

13,052
Active ML predictions
752
Triple signal alerts
42,143
Bills scored 0–100
$0
/month infrastructure
01 / The Problem

The data exists.
Nobody connects it.

The STOCK Act requires members of Congress to disclose stock trades within 45 days. The data is public — but useless in isolation. A trade disclosure tells you a senator bought $50K of Pfizer stock. It does not tell you anything else.

It does not tell you: that senator chairs the Senate Health Committee, which healthcare bills are pending before that committee, that Pfizer lobbied that same office last quarter, and that if a specific bill passes, Pfizer's revenue impact is approximately 30% of market cap. GovGreed connects all those facts and scores them together.

What the raw data shows
Sen. X bought $50,000 of Pfizer (PFE) stock on March 15, 2025
What GovGreed adds
  • +Sen. X chairs Senate Health Committee (voting_power = 1.0)
  • +Senate Bill S.1234 (healthcare pricing) is before that committee
  • +Pfizer lobbied Sen. X's office Q1 2025
  • +If S.1234 passes: estimated Pfizer revenue impact = ~30% of market cap
  • opportunity_score = 847.3 — RED alert, triple signal active
02 / The Data We Collected

Eleven federal data systems.
Zero paywalled sources.

Every data source in GovGreed is free, public, and API-accessible. No scrapers that violate ToS. No paid subscriptions. No data brokers. The challenge was not obtaining the data — it was connecting eleven data systems that use completely different identifier schemes.

DatasetCountSourceWhat it covers
Politicians538Congress.gov APIAll House + Senate members, 119th Congress
Bills62,815Congress.gov + detail APIAll tracked bills, fully dated + status; 42,143 scored by the ML model
STOCK Act trades103,342QuiverQuant (no key)Deduplicated member stock disclosures (191,238 raw rows), ticker + date + amount
Committees + assignments230 / 3,908congress-legislators GitHub YAMLWho sits on what committee, with role (Chair/Member)
Companies581Financial Modeling PrepMarket cap, sector, exchange for all tickers traded
Campaign contributions11,850FEC APITop donations per politician by company/PAC
Lobbying filings570Senate LDA APIQuarterly filings, sector-matched to members
Federal contracts152USASpending.govGovernment contracts to public companies
bill_impacts (generated)924,012IPS-built cross-referenceBill→ticker impact mappings (no official source for this)
🔗

Cross-source ID normalization

Congress.gov uses bioguide IDs. FEC uses candidate IDs. The YAML file uses THOMAS IDs. Lobbying filings use registrant names. We built the matching logic to unify them all into a single member record.

📊

Ticker-to-bill matching (IPS-built)

No official source maps companies to bills. We built bill_impacts: 924,012 generated bill→ticker impact mappings linking tickers to legislation by sector keyword matching. This is the table that makes everything else computable.

🧠

Sector taxonomy unification

FEC uses one sector classification. FMP uses GICS sectors. Lobbying filings use issue codes. Congress bills use CRS subject codes. We built the translation layer that maps all four systems to a common taxonomy.

03 / The Scoring Engine

One formula.
13,052 scored predictions.

Every prediction is produced by a single deterministic scoring formula that combines committee power, bill financial impact, stock trading behavior, and campaign finance patterns into a single conflict-of-interest score.

-- GovGreed core scoring formula
opportunity_score =
    voting_power
    × MIN(impact_ratio, 0.50)
    × LOG(consortium_count)
    × multiplier           -- 2000x if STOCK Act trade exists, 150x if not
    × triple_bonus        -- 1.5x if all three signals active

voting_power — Committee role determines access

Chair
1.0
Ranking Mbr
0.8
Member
0.6
No seat
0.1

The multiplier — the trade is the tell

2000x
STOCK Act trade exists for affected ticker
When a committee member has filed a STOCK Act disclosure for a stock that stands to benefit from their own legislation, the score multiplies by 2,000. The trade is the smoking gun.
150x
No trade on record
Committee seat + affected bill + campaign contributions still score, but at 150x. There is a conflict of interest even without the trade disclosure.

Score distribution — 13,052 active predictions classified

RED
2.6%
Score ≥ 200
ORANGE
14.7%
Score ≥ 50
YELLOW
62.9%
Score ≥ 10
GREEN
19.7%
Score < 10
04 / The Triple Signal

When all three overlap.
752 predictions fire.

The Triple Signal fires when a single politician shows all three simultaneous indicators pointing at the same bill. This is the highest-confidence conflict-of-interest alert in the system.

1

Committee Seat

Politician sits on the committee with direct jurisdiction over the bill. Chair = 1.0 voting power. The committee controls whether the bill reaches a floor vote at all.

2

STOCK Act Trade

A STOCK Act disclosure exists for a position in the company directly affected by this bill. The filing is dated within the period while the bill is active. This is the 2,000x multiplier trigger.

3

Campaign Contribution

The politician received a campaign contribution from the company or its PAC that is affected by this same bill. FEC-sourced. This is the 1.5x triple_bonus trigger when combined with signals 1 and 2.

Top Triple Signal detections — 752 total across all 13,052 active ML predictions

PoliticianTriple SignalsCompany / TickerSignal
Markwayne Mullin114ConocoPhillips (COP)RED
Gary Peters73Multiple sectorsRED
Angus King58Comcast (CMCSA)RED
05 / The ML System

Machine learning.
Entirely in PostgreSQL.

No Python service. No model files to deploy. No infrastructure to maintain. Four PostgreSQL stored functions score the full prediction matrix in approximately 30 seconds using pure set-based SQL.

-- 4 PostgreSQL RPC functions
FunctionOutputDescription
extract_bill_features()21 features × 42,143 billsFeature extraction from all source tables
learn_investability_weights()Weight vectorZ-score analysis of bill financial characteristics
compute_investability()Score 0–100 per billScores all 42,143 bills by financial opportunity
compute_predictions()13,052 active rowsCross-product: all politicians × all bills, scored

Key ML findings

Politicians disproportionately invest on bills affecting many small-cap companies across multiple sectors — not single large-cap bets.

Healthcare and VA legislation scores highest for cross-signal conflict of interest. Defense and energy second.

Committee chairs account for 67% of RED-tier predictions despite being a small fraction of total members. Power concentration is measurable.

Impact ratio is capped at 0.50 to prevent single-company bills from dominating. Small-cap + niche legislation is the real signal — not obvious big-name bets.

-- compute_predictions() simplified: 10 CTEs, pure set-based SQL, no loops
-- Full prediction matrix scored in ~30 seconds inside PostgreSQL.

WITH committee_power AS (
  SELECT member_id, bill_id,
    CASE role WHEN 'Chair' THEN 1.0 WHEN 'Ranking Member' THEN 0.8 ELSE 0.6 END AS voting_power
  FROM committee_assignments JOIN bill_committee_refs USING (committee_id)
), trade_signal AS (
  SELECT member_id, ticker,     CASE WHEN trade_date IS NOT NULL THEN 2000 ELSE 150 END AS multiplier
  FROM stock_trades
), final_score AS (
  SELECT member_id, bill_id,
    voting_power * LEAST(impact_ratio, 0.5) * LN(consortium_count) * multiplier * triple_bonus
    AS opportunity_score
  FROM committee_power JOIN trade_signal JOIN bill_impacts JOIN triple_check ...
)
INSERT INTO predictions SELECT * FROM final_score;
06 / Tech Stack

A full intelligence platform.
At $0/month.

Supabase free tier for the database. Vercel hobby tier for the frontend. No ML server because the ML runs in SQL. No data pipeline infrastructure because the RPCs handle it. The entire stack is free.

LayerTechnologyCost
FrontendStatic HTML + Alpine.js + GSAPVercel hobby ($0)
DatabaseSupabase PostgreSQL (ConTrack project)Free tier ($0)
ML / ScoringPure PostgreSQL stored functions (4 RPCs)No server needed ($0)
AuthSupabase Auth (email/password)Included ($0)
Data sourcesCongress.gov, FEC, Senate LDA, QuiverQuant, USASpending.gov, FMPAll free ($0)
Total monthly$0/month — full production intelligence platform
HTML5Alpine.jsGSAP SupabasePostgreSQLSQL RPCs Supabase AuthVercelCongress.gov API FEC APISenate LDA APIQuiverQuant USASpending.govFinancial Modeling Prep
07 / What Made It Hard

Five problems
nobody had solved yet.

The STOCK Act data has been public for years. So has the congressional record. So have campaign finance filings. The data is not the problem. The problem is everything required to connect eleven incompatible data systems and score them in 30 seconds.

01
Cross-source normalization — six incompatible ID schemes
Six datasets use completely different identifier schemes: bioguide IDs, FEC candidate IDs, THOMAS IDs, OpenSecrets IDs, registrant name strings, and company tickers. We built the matching logic to unify them into a single member record. No two datasets agreed on how to identify the same person.
02
Ticker-to-bill matching — no official source exists
No official dataset maps public companies to legislative bills. We built bill_impacts from scratch: 38,955 generated pairings linking tickers to legislation through sector taxonomy matching between GICS codes and CRS subject headings. This intermediate table is what makes the entire scoring engine computable. Without it, there is nothing to score.
03
ML in SQL — four PostgreSQL RPCs, zero external infrastructure
Most ML systems require a Python service, a model file, a deployment pipeline, and monitoring. Ours is four stored SQL functions. Extract features, learn weights, score bills, generate predictions — all in database. When Supabase is up, the ML is up. No separate service to fail.
04
Full prediction matrix in 30 seconds — pure set-based SQL
Generating the full prediction matrix is a cross-product of politicians × bills, joined against six tables, scored with a multi-factor formula, and filtered into risk tiers. We did this in 10 CTEs using pure set-based SQL with no application-layer loops. The database engine does the work. No iteration. No row-by-row processing.
05
$0/month — Supabase free + Vercel hobby
A full congressional intelligence platform with authenticated access, 13,052 active ML predictions, live ML scoring, and a public-facing dashboard — all running at zero infrastructure cost. Supabase free tier for the database. Vercel hobby for the frontend. The value is the data connections and the scoring logic. Not the servers.
What's next

Ready to build something
like this?

IPS builds custom data platforms, intelligence systems, and AI-powered products from scratch. We have done it for government transparency, sports analytics, cannabis CRM, and enterprise sales AI. We can do it for your industry — at a cost that commodity infrastructure makes possible.