| 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}") |
|
|