slickbet.tune¶

Hyperparameter tuning for the betting model.

Uses cached API data to run backtests across different weight configurations and find the best parameters. No API calls during tuning.

Examples

>>> # 1. Populate cache:
>>> #    slickbet backtest-all --weeks 12 --cache-dir data/12_weeks_cache
>>> # 2. Run tuning:
>>> #    slickbet tune --cache-dir data/12_weeks_cache --trials 20
>>> from slickbet.tune import tune
>>> best = tune(cache_dir="data/12_weeks_cache", weeks=12, trials=20)

Attributes¶

Classes¶

TuneResult

Result of a single tuning trial.

Functions¶

format_best_weights(→ str)

Format weights for copying into BettingModel.

run_backtest_with_weights(...)

Run backtest-all-global with given weights using cached data.

tune(→ TuneResult | None)

Run hyperparameter tuning over weight configurations.

Module Contents¶

slickbet.tune.ALL_LEAGUES = [('1', 'Bundesliga', 'Germany'), ('2', 'Premier League', 'England'), ('3', 'La Liga', 'Spain'),...¶
slickbet.tune.AMERICAS_LEAGUES = [('23', 'Liga Professional', 'Argentina'), ('24', 'Serie A Brazil', 'Brazil'), ('45', 'Liga MX',...¶
slickbet.tune.ASIA_LEAGUES = [('313', 'Saudi Pro League', 'Saudi Arabia'), ('67', 'Hyundai A-League', 'Australia'), ('28',...¶
slickbet.tune.MAJOR_LEAGUES = [('1', 'Bundesliga', 'Germany'), ('2', 'Premier League', 'England'), ('3', 'La Liga', 'Spain'),...¶
slickbet.tune.MINOR_LEAGUES = [('68', 'Belgian Pro League', 'Belgium'), ('8', 'Primeira Liga', 'Portugal'), ('6', 'Super Lig',...¶
class slickbet.tune.TuneResult[source]¶

Result of a single tuning trial.

weights¶

Factor weights used for this trial (sum to 1.0).

Type:

dict[str, float]

accuracy¶

Overall win-prediction accuracy (0-1).

Type:

float

accuracy_excl_draws¶

Accuracy excluding matches that ended in a draw.

Type:

float

best_dc_accuracy¶

Accuracy of the recommended double-chance bet.

Type:

float

total_matches¶

Number of predictions evaluated.

Type:

int

correct¶

Number of correct win predictions.

Type:

int

accuracy: float¶
accuracy_excl_draws: float¶
best_dc_accuracy: float¶
correct: int¶
total_matches: int¶
weights: dict[str, float]¶
slickbet.tune.format_best_weights(weights: dict[str, float]) str[source]¶

Format weights for copying into BettingModel.

Parameters:

weights (dict[str, float]) – Factor name → weight mapping.

Returns:

str – Indented "name": value, lines sorted by name.

slickbet.tune.run_backtest_with_weights(cache_dir: str | pathlib.Path, weeks: int, weights: dict[str, float], min_probability: float = 0.0) slickbet.backtest.BacktestResults | None[source]¶

Run backtest-all-global with given weights using cached data.

Parameters:
  • cache_dir (str or Path) – Directory with cached API data.

  • weeks (int) – Weeks of history (must match what was cached).

  • weights (dict[str, float]) – Factor name → weight mapping for BettingModel.

  • min_probability (float, optional) – Minimum prediction probability to include.

Returns:

BacktestResults or None – Aggregated results, or None if no matches.

slickbet.tune.tune(cache_dir: str | pathlib.Path, weeks: int = 12, trials: int = 20, strategy: str = 'random', min_probability: float = 0.0, metric: str = 'accuracy_excl_draws', verbose: bool = True) TuneResult | None[source]¶

Run hyperparameter tuning over weight configurations.

Parameters:
  • cache_dir (str or Path) – Directory with cached API data (from prior backtest with –cache-dir).

  • weeks (int) – Weeks of data (must match what was cached).

  • trials (int) – Number of weight configurations to try.

  • strategy (str) – “random” = random weights, “near_default” = perturb defaults.

  • min_probability (float) – Minimum prediction probability to include.

  • metric (str) – “accuracy”, “accuracy_excl_draws”, or “best_dc”.

  • verbose (bool) – Print progress.

Returns:

TuneResult or None – Best result, or None if no valid trials.