|
1 | 1 | #!/usr/bin/env python3
|
2 |
| - |
3 | 2 | import logging
|
4 | 3 | from dataclasses import dataclass
|
5 | 4 | from datetime import datetime, timezone
|
6 | 5 |
|
| 6 | +import numpy as np |
| 7 | +import pandas as pd |
7 | 8 | from rich import print
|
8 | 9 | from rich.console import Console
|
9 | 10 | from rich.logging import RichHandler
|
10 | 11 | from rich.table import Table
|
| 12 | +from sklearn.linear_model import LinearRegression # type: ignore |
| 13 | +from sklearn.metrics import mean_squared_error # type: ignore |
| 14 | +from sklearn.model_selection import train_test_split # type: ignore |
11 | 15 |
|
12 | 16 | from holdet import holdet
|
13 |
| -from lp import lp |
14 | 17 | from sofascore import sofascore
|
15 | 18 |
|
16 | 19 |
|
@@ -71,9 +74,13 @@ def xGrowth(self) -> float:
|
71 | 74 |
|
72 | 75 | return growth
|
73 | 76 |
|
| 77 | + @property |
| 78 | + def growth(self) -> int: |
| 79 | + return self.values.growth |
| 80 | + |
74 | 81 | @property
|
75 | 82 | def diff(self) -> float:
|
76 |
| - return self.xGrowth - self.values.growth |
| 83 | + return self.xGrowth - self.growth |
77 | 84 |
|
78 | 85 | def __lt__(self, other: "Round") -> bool:
|
79 | 86 | return self.number < other.number
|
@@ -375,8 +382,42 @@ def get_holdet(game: holdet.Game) -> list[Holdet]:
|
375 | 382 | candidates.append(Candidate(h, s))
|
376 | 383 | status.console.log(f"Found {len(candidates)} players on Sofascore")
|
377 | 384 |
|
378 |
| - with console.status("Finding optimal team..."): |
379 |
| - solution = lp.find_optimal_team(candidates, 70 * 1000000) |
380 |
| - status.console.log(f"Found optimal 11 out of {len(candidates)} players") |
381 |
| - |
382 |
| - print(Formation(solution)) |
| 385 | + # Extract and flatten the data |
| 386 | + data = [] |
| 387 | + for candidate in candidates: |
| 388 | + for round in candidate.rounds: |
| 389 | + for stat in round.stats: |
| 390 | + row = { |
| 391 | + "id": candidate.id, |
| 392 | + "round": round.number, |
| 393 | + } |
| 394 | + row.update(stat.features) |
| 395 | + row.update({"growth": round.growth}) |
| 396 | + data.append(row) |
| 397 | + |
| 398 | + # Create a pandas DataFrame |
| 399 | + df = pd.DataFrame(data) |
| 400 | + |
| 401 | + # Define features (X) and target (y) |
| 402 | + X = df.iloc[:, :-1] |
| 403 | + y = df.iloc[:, -1] |
| 404 | + |
| 405 | + # Split the data into training and testing sets |
| 406 | + X_train, X_test, y_train, y_test = train_test_split(X, y) |
| 407 | + |
| 408 | + # Create and fit the model |
| 409 | + model = LinearRegression() |
| 410 | + model.fit(X_train, y_train) |
| 411 | + |
| 412 | + # Make predictions |
| 413 | + y_pred = model.predict(X_test) |
| 414 | + |
| 415 | + # Evaluate the model |
| 416 | + rmse = np.sqrt(mean_squared_error(y_test, y_pred)) |
| 417 | + print("Root Mean Squared Error:", rmse) |
| 418 | + |
| 419 | + # with console.status("Finding optimal team..."): |
| 420 | + # solution = lp.find_optimal_team(candidates, 70 * 1000000) |
| 421 | + # status.console.log(f"Found optimal 11 out of {len(candidates)} players") |
| 422 | + |
| 423 | + # print(Formation(solution)) |
0 commit comments