File size: 1,405 Bytes
653c38a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | from pathlib import Path
import csv
from la_liga_score_predictor import LaLigaScorePredictor
predictor = LaLigaScorePredictor.from_defaults(
dataset_csv_path="sample_history.csv"
)
input_path = Path("sample_fixtures.csv")
output_path = Path("predictions_output.csv")
with input_path.open(newline="", encoding="utf-8") as src, output_path.open("w", newline="", encoding="utf-8") as dst:
reader = csv.DictReader(src)
fieldnames = ["home_team", "away_team", "match_date", "predicted_score", "home_win", "draw", "away_win", "confidence_level"]
writer = csv.DictWriter(dst, fieldnames=fieldnames)
writer.writeheader()
for row in reader:
result = predictor.predict_match(
home_team=row["home_team"],
away_team=row["away_team"],
match_date=row["match_date"],
)
writer.writerow(
{
"home_team": row["home_team"],
"away_team": row["away_team"],
"match_date": row["match_date"],
"predicted_score": result["predicted_score"],
"home_win": result["result_probabilities"]["home_win"],
"draw": result["result_probabilities"]["draw"],
"away_win": result["result_probabilities"]["away_win"],
"confidence_level": result["confidence_level"],
}
)
print(f"Wrote {output_path}")
|