College football — additional Python functions — Models and calculators: cfb_simulations–fit_field
cfb_simulations
cfb_simulations(games: 'FrameLike', teams: 'FrameLike', compute_results: 'ComputeResultsFn | None' = None, *, simulations: 'int' = 10000, playoff_seeds: 'int' = 12, tiebreaker_depth: 'str' = 'SOS', sim_include: 'str' = 'POST', rankings: 'FrameLike | None' = None, tiebreaker_data: 'dict[str, FrameLike] | None' = None, seed: 'int | None' = None, return_as_pandas: 'bool' = False) -> 'dict[str, pl.DataFrame | Any]'
Simulate college football seasons (nflseedR-style week loop).
Replicates the input season simulations times, fills unplayed games
week by week through the pluggable compute_results, then simulates
the postseason (conference championships + CFP bracket) and aggregates
per-team probabilities. See the module docstring for every documented
CFB simplification.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
games | FrameLike | One season of games in the engine schema (season or sim, week, game_type, home_team, away_team, result — null = unplayed, neutral). Played results are kept as-is. A season column picks that season's tiebreakers and CFP rule; sim-keyed input uses the current ones. The optional home_points/away_points/conf_game columns of sportsdataverse.cfb.cfb_games_from_schedule pass through to sportsdataverse.cfb.cfb_standings. | |
teams | FrameLike | Team table (team, conference, plus the optional sportsdataverse.cfb.cfb_standings columns). | |
compute_results | ComputeResultsFn | None | None | Results generator with the signature fn(teams, games, week_num, **kwargs) -> {"teams": ..., "games": ...} filling result for that week's unplayed games only. Defaults to cfb_compute_results (dynamic ELO). |
simulations | int | 10000 | Number of simulated seasons (sequential, no chunking). |
playoff_seeds | int | 12 | CFP field size passed to cfb_playoff_seeds. |
tiebreaker_depth | str | 'SOS' | nflseedR depth ladder (RANDOM < PRE-SOV < SOS < POINTS) used by every standings computation. |
sim_include | str | 'POST' | How deep to simulate: "REG" (regular season only), "CONF" (+ conference championships) or "POST" (+ CFP bracket, default). |
rankings | FrameLike | None | None | Optional committee rankings (team, rank) forwarded to cfb_playoff_seeds. When None, seeding falls back to the per-sim standings ordering (documented in cfb_playoff_seeds). |
tiebreaker_data | dict[str, FrameLike] | None | None | Optional tiebreaker inputs ("analytics_ratings", "cfp_rankings", "apr" frames) forwarded unchanged to every sportsdataverse.cfb.cfb_standings call, so the official rungs run. |
seed | int | None | None | Seed for the numpy RNG (deterministic runs). |
return_as_pandas | bool | False | Return pandas DataFrames instead of polars. |
Returns
Dict of frames mirroring the nflseedR summary list: * "standings" — per (sim, team) standings incl. conf_rank, conf_champ and (sim_include="POST") seed. * "games" — all games incl. simulated results and generated postseason rows. * "overall" — per-team probabilities (won_conf, made_playoff, first_round_bye, won_cfp) and mean record columns. * "game_summary" — per unique matchup: games played, home win / tie rates and mean margin.
| col_name | type | description |
|---|---|---|
team | String | Team name the simulated probabilities belong to (overall summary frame). |
conference | String | Conference the team belongs to; null or "FBS Independents" marks an independent. |
wins | Float64 | Mean wins per simulated season (all game types through the conference championship). |
losses | Float64 | Mean losses per simulated season (all game types through the conference championship). |
ties | Float64 | Mean ties per simulated season. |
win_pct | Float64 | Mean overall win percentage across the simulated seasons. |
won_conf | Float64 | Share of simulations in which the team won its conference (CONF_CHAMP game winner, or rank-1 fallback). |
made_playoff | Float64 | Share of simulations in which the team made the College Football Playoff field. |
first_round_bye | Float64 | Share of simulations in which the team earned a CFP first-round bye (seeds 1-4 in the 12-team field; in general the top P - n seeds, P being the smallest power of two at or above the field size n). |
won_cfp | Float64 | Share of simulations in which the team won the College Football Playoff national championship. |
Raises
| Exception | Description |
|---|---|
ValueError | On invalid sim_include / tiebreaker_depth, multi-season input, missing columns, or duplicate team rows. |
Example
from sportsdataverse.cfb import cfb_simulations
out = cfb_simulations(games, teams, simulations=100, seed=42,
playoff_seeds=12)
print(out["overall"].sort("won_cfp", descending=True).head())
# Regular season only
out = cfb_simulations(games, teams, simulations=100,
sim_include="REG", seed=1)
cfb_special_teams_phase
cfb_special_teams_phase(plays: 'pl.DataFrame | pd.DataFrame', *, return_as_pandas: 'bool' = False) -> 'pl.DataFrame | pd.DataFrame'
Season special-teams value per team by phase (punt, kickoff, punt return, kick return) and FG makes over expected.
Each phase is EPA per opportunity from the side of the team being rated (the kicking team for punts and
kickoffs, the returning team for returns), on punt and kickoff plays outside garbage time by the score-margin
rule. The displayed value is shrunk toward the phase's league mean by n / (n + k); the per-game value is
that shrunk deviation times the team's opportunities per game, and st_epa_per_game sums the four phases.
Field goals are rated as makes over expected per attempt (fg_made - fg_make_prob), each kicker shrunk with a
beta-binomial prior and combined per team by attempts. No opponent adjustment. In-sample and descriptive.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
plays | DataFrame | DataFrame | A cfbfastR-schema play-by-play frame (polars or pandas), one season, every play type (the punt, kickoff and FG rows are selected here) with game_id, pos_team, pos_team_id, def_pos_team_id, EPA, punt, kickoff_play, fg_attempt, fg_made, fg_make_prob, fg_kicker_player_id, period and pos_score_diff_start. | |
return_as_pandas | bool | False | Return a pandas DataFrame instead of polars. |
Returns
One row per team on either side of a kept punt or kickoff or with a rated FG attempt: team_id, pos_team, games (games in plays), then for each phase <phase>_n (opportunities), <phase>_epa_raw (mean EPA per opportunity), <phase>_epa_shrunk (the display value), <phase>_epa_per_game (shrunk deviation from the league mean per game) and <phase>_rank (on _shrunk, highest first); st_epa_per_game and st_rank; fg_att, fg_moe_raw, fg_moe_shrunk and fg_rank. A phase with no opportunities is null and adds 0 to the total.
| col_name | type | description |
|---|---|---|
team_id | String | Team ESPN id (character join key). |
pos_team | String | Team name as ESPN spells it in the play-by-play. |
games | Int64 | Games the team appears in within the input plays (the per-game denominator). |
punt_n | Int64 | Opportunities in the phase: punts outside garbage time (the n in the shrinkage); null when none. |
punt_epa_raw | Float64 | Raw value: the punting team's EPA per punt, mean over its opportunities outside garbage time. |
punt_epa_shrunk | Float64 | Display value: punt EPA per opportunity shrunk toward the league mean of the phase by n / (n + 63.1). |
punt_epa_per_game | Float64 | The shrunk punt EPA per opportunity above the league mean, times the team's opportunities per game: EPA the phase adds per game. |
punt_rank | Float64 | Rank of punt_epa_shrunk (highest = 1, ties averaged). |
kickoff_n | Int64 | Opportunities in the phase: kickoffs outside garbage time (the n in the shrinkage); null when none. |
kickoff_epa_raw | Float64 | Raw value: the kicking team's EPA per kickoff (the negative of the receiving team's EPA on the play), mean over its opportunities outside garbage time. |
kickoff_epa_shrunk | Float64 | Display value: kickoff EPA per opportunity shrunk toward the league mean of the phase by n / (n + 160.2). |
kickoff_epa_per_game | Float64 | The shrunk kickoff EPA per opportunity above the league mean, times the team's opportunities per game: EPA the phase adds per game. |
kickoff_rank | Float64 | Rank of kickoff_epa_shrunk (highest = 1, ties averaged). |
punt_return_n | Int64 | Opportunities in the phase: opponent punts received outside garbage time (the n in the shrinkage); null when none. |
punt_return_epa_raw | Float64 | Raw value: the returning team's EPA per punt received (the negative of the punting team's EPA), mean over its opportunities outside garbage time. |
punt_return_epa_shrunk | Float64 | Display value: punt return EPA per opportunity shrunk toward the league mean of the phase by n / (n + 215.6). |
punt_return_epa_per_game | Float64 | The shrunk punt return EPA per opportunity above the league mean, times the team's opportunities per game: EPA the phase adds per game. |
punt_return_rank | Float64 | Rank of punt_return_epa_shrunk (highest = 1, ties averaged). |
kick_return_n | Int64 | Opportunities in the phase: opponent kickoffs received outside garbage time (the n in the shrinkage); null when none. |
kick_return_epa_raw | Float64 | Raw value: the receiving team's EPA per kickoff received, mean over its opportunities outside garbage time. |
kick_return_epa_shrunk | Float64 | Display value: kick return EPA per opportunity shrunk toward the league mean of the phase by n / (n + 119.5). Unlike the other three phases, its shrunk value was less reliable split-half than the raw value on 2014-2023 (.259 vs .267), so it is published labelled as noisier. |
kick_return_epa_per_game | Float64 | The shrunk kick return EPA per opportunity above the league mean, times the team's opportunities per game: EPA the phase adds per game. |
kick_return_rank | Float64 | Rank of kick_return_epa_shrunk (highest = 1, ties averaged). |
st_epa_per_game | Float64 | Special-teams EPA per game: the sum of the four phases' per-game values (a phase with no opportunities adds 0). Field goals are not included. |
st_rank | Float64 | Rank of st_epa_per_game (highest = 1, ties averaged). |
fg_att | Int64 | Field-goal attempts rated: attempts outside garbage time with EPA, a make probability and a kicker id. |
fg_moe_raw | Float64 | Raw field-goal makes over expected per attempt: mean of fg_made minus fg_make_prob over the team's rated attempts. |
fg_moe_shrunk | Float64 | Display value: each kicker's makes over expected per attempt shrunk toward the season's league mean with a beta-binomial prior of 118.6 attempts (n / (n + 118.6)), averaged over the team's kickers by attempts. |
fg_rank | Float64 | Rank of fg_moe_shrunk (highest = 1, ties averaged). |
Raises
| Exception | Description |
|---|---|
KeyError | If plays is missing a required column. |
Example
import sportsdataverse.cfb as cfb
plays = cfb.load_cfb_pbp(seasons=2025)
st = cfb.cfb_special_teams_phase(plays)
st.sort("st_rank").select("pos_team", "st_epa_per_game", "punt_epa_shrunk", "fg_moe_shrunk").head()
cfb_touchback_yardline_expr
cfb_touchback_yardline_expr(season: polars.expr.expr.Expr) -> polars.expr.expr.Expr
Kickoff-touchback yards-to-endzone per row: 80 through 2011, 75 from 2012.
Reads TOUCHBACK_YARDLINE_BY_SEASON (the NCAA 2012 kickoff rule). Named with the cfb_
prefix so the top-level sportsdataverse namespace keeps NFL's touchback_yardline_expr
(2016 cut) distinct from this one.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
season | Expr | Integer season expression (pl.col("season")). |
Returns
An integer expression of the touchback yards-to-endzone per row.
Example
import polars as pl
from sportsdataverse.cfb import cfb_touchback_yardline_expr
df = pl.DataFrame({"season": [2011, 2012]})
print(df.select(cfb_touchback_yardline_expr(pl.col("season"))).to_series().to_list()) # [80, 75]
efficiency_ratings
efficiency_ratings(plays: 'pl.DataFrame', *, config: 'RatingsConfig | None' = None) -> 'pl.DataFrame'
One row per team: opponent-adjusted offensive/defensive efficiency.
The same fit as sportsdataverse.cfb.cfb_adjusted_epa: one ridge of
per-play EPA on offense, defense and home-field indicators over the pass
and rush plays that are not garbage time (score margin at the snap above
43 / 37 / 27 / 21 in Q1-Q4 and overtime, the
~sportsdataverse.cfb.cfb_opponent_adjust.flag_garbage_time rule; no
win probability, so the pregame line never decides which plays count),
every team shrunk toward the league average by its own play count
(_ADJ_EPA_LAMBDA). Each team's raw per-game EPA on those same plays is
then netted against the opponent's fitted strength and averaged across
games -- the R adjust_epa statistic. games and off_pace still
count every pass/rush play. Through 0.2.0b1 this function fit a separate
standardized ridge (lambda 0.035) on 0.1 <= wp_before <= 0.9, which
priced the pregame spread into the fit and predicted next week's margins
0.67 points worse.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
plays | DataFrame | A cfbfastR-schema play-by-play frame carrying every column in cfb_adjusted_epa._ADJ_REQUIRED (game_id, pos_team, pos_team_id, def_pos_team_id, home, neutral_site, EPA, pass, rush, period, pos_score_diff_start). Callers pass an already as-of-date-filtered frame; this function is pure. | |
config | RatingsConfig | None | None | Accepted for signature parity with fei_ratings; not read here (the penalty is cfb_adjusted_epa's, so the two entry points cannot disagree). |
Returns
A polars.DataFrame with one row per team_id: team_id (Utf8), adj_off_epa / adj_def_epa / adj_net (Float64), games (Int64), off_pace (Float64 -- scrimmage plays per game, the tempo input the totals model consumes). Empty (zero-row, correctly-typed) when every play is garbage time.
No returns table is published for this function: no capture: it needs play-by-play joined with schedule fields (home, neutral_site, pos_team_id) that neither load_cfb_pbp nor load_cfb_pbp_r carries; only cfb_ratings builds that join, internally.
Raises
| Exception | Description |
|---|---|
KeyError | If plays is missing a required column. |
Example
from sportsdataverse.cfb.cfb_ratings import efficiency_ratings
ratings = efficiency_ratings(pbp)
ratings.sort("adj_net", descending=True).head()
fei_ratings
fei_ratings(plays: 'pl.DataFrame', *, config: 'RatingsConfig | None' = None) -> 'pl.DataFrame'
One row per team: opponent-adjusted per-drive efficiency (FEI-style).
The Fremeau Efficiency Index rates teams on drive value above expectation
given starting field position. The cfbfastR-schema plays frame this
package works with carries no starting-field-position column, so this
function uses the documented fallback: per-play EPA summed within each
(game_id, drive_id) group stands in for drive value, and that
aggregate is fit through the same opponent-adjustment ridge as
efficiency_ratings / special_teams_ratings -- no forked
solver. Offline validation against the Fremeau FEI oracle put this
fallback's team ranking at Spearman 0.967.
cfb_adjusted_epa._prepare filters to individual pass/rush plays and
is not reused here (drive value should reflect every play on the drive,
special-teams snaps included); the hfa treatment is reproduced
directly, matching special_teams_ratings.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
plays | DataFrame | A cfbfastR-schema play-by-play frame carrying every column in cfb_adjusted_epa._REQUIRED_COLUMNS (game_id, pos_team, pos_team_id, def_pos_team_id, home, neutral_site, EPA, pass, rush, wp_before) plus drive_id. Not pre-aggregated to drives -- this function does that grouping itself. | |
config | RatingsConfig | None | None | Ratings tuning knobs. Only ridge_lambda is consulted here; defaults to RatingsConfig when omitted. |
Returns
A polars.DataFrame with one row per team_id appearing as pos_team_id on at least one drive: team_id (Utf8), fei_off / fei_def / fei_net (Float64). The ridge's dropped reference team is re-added at the shared intercept (fei_net == 0.0). Zero-row (correctly-typed) when plays has no rows with a non-null EPA.
No returns table is published for this function: no capture: it needs play-by-play joined with schedule fields (home, neutral_site, pos_team_id) that neither load_cfb_pbp nor load_cfb_pbp_r carries; only cfb_ratings builds that join, internally.
Raises
| Exception | Description |
|---|---|
ImportError | If scikit-learn is not installed. |
Example
from sportsdataverse.cfb.cfb_ratings import fei_ratings
fei = fei_ratings(pbp)
fei.sort("fei_net", descending=True).head()
fit_field_position_ep
fit_field_position_ep(drives: 'pl.DataFrame', *, start_col: 'str' = 'drive_start_yardline', pts_col: 'str' = 'drive_next_score_pts') -> 'pl.DataFrame'
Fit the monotone EP-by-starting-yardline curve from a drives frame.
Groups drives by starting yard line (from own goal), takes the mean next-score points, and applies sample-count-weighted isotonic regression (weight = number of drives at each starting yard line, non-decreasing), interpolated onto the full 1..99 grid.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
drives | DataFrame | one row per drive. | |
start_col | str | 'drive_start_yardline' | starting yard line from own goal (1..99). |
pts_col | str | 'drive_next_score_pts' | net next-score points for the drive's offense. |
Returns
yardline_own: Int64 (1..99), ep: Float64 -- monotone non-decreasing. Empty input returns a zero-row frame.
| col_name | type | description |
|---|---|---|
yardline_own | Int64 | Starting yard line from the offense's own goal (1-99). |
ep | Float64 | Fitted expected points for a drive starting at this yard line (isotonic, non-decreasing). |
Example
import polars as pl
from sportsdataverse.cfb.cfb_field_position import fit_field_position_ep
curve = fit_field_position_ep(drives_frame)