Module path
File paths
| Constant | Path |
|---|---|
DBPATH | Data/nba_stats.db |
MODELPATH | models/nba_model.pkl |
train_model_teamwins()
Trains a RandomForestClassifier on the team_game_stats table and saves the model to disk.
Returns: None
Side effects:
- Prints test accuracy to stdout.
- Creates
models/directory if it does not exist. - Writes the trained model to
models/nba_model.pkl(overwrites any existing file).
You must run
generate_features_teamwins() before calling this function so the team_game_stats table exists and is populated.Source
prediction_ai.py
predict_game_teamwins()
Loads the saved model and returns the predicted win probability for a single game.
Parameters
Difference between the team’s rolling average points and the opponent’s rolling average points.
Team’s rolling average rebounds over the last N games.
Opponent’s rolling average rebounds over the last N games.
Team’s rolling average assists over the last N games.
Opponent’s rolling average assists over the last N games.
1 if the team is playing at home, 0 if away.float — predicted probability that the team wins, in the range [0.0, 1.0].
models/nba_model.pkl must exist before calling this function. Run train_model_teamwins() to generate it.Source
prediction_ai.py
evaluate_bet_teamwins()
Converts a win probability into a human-readable betting recommendation.
Parameters
Win probability returned by
predict_game_teamwins(). Expected range: [0.0, 1.0].str — one of the following labels:
| Probability range | Return value |
|---|---|
> 0.60 | "Good Bet" |
> 0.52 | "Slight Edge" |
≤ 0.52 | "Avoid" |
Source
prediction_ai.py