Member-only story
Using AI and Python to predict NFL Matches
Utilize power of AI to make NFL score predictions
Introduction
Today we will leveraging the power of Claude Sonnet 3.5 to generate predictions for the upcoming Week 9 of NFL games.
Given NFL current season data from pro football reference, the idea here is we will not write any code ourselves instead we will ask Claude to write all code. We will simply run the code to ensure it executes properly and then examine the generated predictions.
Walkthrough
First, lets get the data we will be making predictions on. For simplicity I will only be using data for the current NFL season scraped from -
The benefit of this data is that it also contains upcoming fixtures which should make our workflow much easier.
The first prompt I will ask claude is- “Using requests and beautiful soup extract the data from this table”. Table-
The code generated is
from bs4 import BeautifulSoup
import pandas as pd
def extract_table_data(html_content):
"""
Extract data from an HTML table with the id 'games' into a DataFrame
Parameters:
html_content (str): HTML content containing the table
Returns:
pandas.DataFrame: DataFrame containing the table data
"""
# Parse HTML with BeautifulSoup
soup = BeautifulSoup(html_content, 'html.parser')
# Find the table
table = soup.find('table', id='games')
# Get headers
headers = []
for th in table.find('thead').find_all('th'):
# Get header text, if empty use the data-stat attribute
header = th.text.strip() if th.text.strip() else th.get('data-stat', '')
headers.append(header)
# Get rows
rows = []
tbody = table.find('tbody') if table.find('tbody') else table
for tr in tbody.find_all('tr')…