Skip to content

Instantly share code, notes, and snippets.

@sdorsett
Created April 20, 2019 02:24
Show Gist options
  • Save sdorsett/6c2e897a4967344be6817339e0139d0a to your computer and use it in GitHub Desktop.
Save sdorsett/6c2e897a4967344be6817339e0139d0a to your computer and use it in GitHub Desktop.
team-data-import-ml4k-text.py
import csv
import ml4k
import os
listOfFiles = [
'./nflscrapR-data/games_data/regular_season/reg_games_2017.csv',
'./nflscrapR-data/games_data/regular_season/reg_games_2016.csv'
]
API_KEY = "******************************"
model = ml4k.Model(API_KEY)
for file in listOfFiles:
with open(file) as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
line_count = 0
for row in csv_reader:
home_team = row[2]
away_team = row[3]
home_score = row[8]
away_score = row[9]
matchup = away_team + ' @ ' + home_team
if home_team > away_team:
winner = 'home_team'
if home_team < away_team:
winner = 'away_team'
if home_team != away_team:
print( 'label: ' + winner)
print( 'value: ' + matchup)
model.add_training_data(winner, matchup)
if line_count == 0:
print(f'Column names are {", ".join(row)}')
line_count += 1
else:
print( matchup + ' and ' + winner + ' won!')
line_count += 1
print(f'Processed {line_count} lines.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment