Skip to content

Instantly share code, notes, and snippets.

View BlueSCar's full-sized avatar

Bill Radjewski BlueSCar

View GitHub Profile
class PermutationImportance():
def __init__(self, learn:Learner, df=None, bs=None):
"Initialize with a test dataframe, a learner, and a metric"
self.learn = learn
self.df = df
bs = bs if bs is not None else
if self.df is not None:
self.dl = learn.dls.test_dl(self.df, bs=bs)
self.dl = learn.dls[1]
BlueSCar /
Created January 23, 2021 20:21
Plotting team logos in Python with matplotlib
import cfbd
import matplotlib.pyplot as plt
from matplotlib.offsetbox import OffsetImage, AnnotationBbox
import pandas as pd
# Grab some stats from the CFBD API
stats = cfbd.StatsApi().get_advanced_team_season_stats(year=2020)
df = pd.DataFrame.from_records([dict(, o_line_yards=s.offense.line_yards, d_line_yards=s.defense.line_yards) for s in stats])
# Need to grab team ids
import cfbd
import pandas as pd
games = cfbd.GamesApi().get_team_game_stats(year=2020, week=1)
stats = []
for g in games:
for t in g.teams:
for s in t.stats:
stats.append(dict(,, conference=t.conference, category=s.category, stat=s.stat))
import numpy as np
import pandas as pd
import requests
pd.set_option('display.float_format', lambda x: '%.8f' % x)
season = 2
day = 3
response = requests.get('', params={'season': season, 'day': day})
BlueSCar /
Last active January 8, 2020 00:17
Python - Normalizing /game/players endpoint
import pandas as pd
import requests
response = requests.get(
params={"year": 2019, "week": "1"}
records =
BlueSCar / playTypes.json
Created August 20, 2019 15:42
Regexes for parsing player names out of play types
typeId: 3,
regex: /(?:Fumble by [^,]+, )?(?:([A-Z][^,\s]+(?: [A-Z][^,\s]+)+)|(?:N\/A))(?:(?: pass incomplete(?: to )*)([A-Z][^,\s]+(?: [A-Z'][^,\s]*)+)*)*(?:(?:, broken up by )([A-Z][^,\s]+(?: [A-Z][^,\s]+)+))*/g,
types: [{
id: 1,
isOffense: true,
yardageStat: false
}, {
id: 2,
isOffense: true,