Created
April 20, 2019 02:24
-
-
Save sdorsett/6c2e897a4967344be6817339e0139d0a to your computer and use it in GitHub Desktop.
team-data-import-ml4k-text.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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