No updates detected yet. GitHub releases will appear here.
The maker's introduction consists of the line above. Read the repository README for more details. Repository README ↗
Loading the full README.
Read the full README ↗機械学習による競馬予測・資金管理・データ収集を一気通貫で実現するフルスタックアプリケーション。
必要なローカル環境が設定済みのPCでは、リポジトリ直下のstart-keiba-ai-pro.batをダブルクリックすると、FastAPIとWebアプリを安全なObservationモードで一括起動し、ログイン画面を開きます。
start-keiba-ai-pro.batcheck-keiba-ai-pro.batstop-keiba-ai-pro.bat起動時にスケジューラ、Production書き込み、自動購入は有効化されません。不足しているvenv、環境設定、DB、Node依存がある場合はfail-closedで停止します。
netkeiba.com
│
│ scrape_race_full() / _scrape_shutuba_fallback()
▼
race.py(スクレイピング)
│ JSON (race_info + 馬別30項目)
▼
storage.py(DB保存)
│
▼
keiba_ultimate.db (SQLite3)
├─ races_ultimate ← レース基本情報 (JSON per row)
└─ race_results_ultimate ← 馬別結果 (JSON per row)
│
│ db_ultimate_loader.load_ultimate_training_frame()
▼
pandas DataFrame (~ 13,000行 × 83列)
│
│ add_derived_features()
▼
派生特徴量追加 (+ ~40列 → 合計 ~125列)
│
│ UltimateFeatureCalculator.add_ultimate_features()
▼
過去統計特徴量追加 (+ ~24列 → 合計 ~137列)
│
│ prepare_for_lightgbm_ultimate()
▼
LightGBM用前処理 (Label Encoding, 未来情報除外) → 110列前後
│
├─ 学習モード ─────────────────────────────────────────────┐
│ LightGBM (binary 分類, target=win) │
│ Optuna 最適化 (100試行, 5-fold CV) │
│ → model_win_YYYYMMDD_YYYYMMDD_ultimate.joblib │
└──────────────────────────────────────────────────────────┘
│
└─ 推論モード(/api/analyze_race)─────────────────────────┐
Quality Gate チェック │
model.predict_proba(X) → 勝率スコア │
キャリブレーション │
期待値計算 (EV = prob × odds) │
ベッティング戦略生成 │
→ JSON レスポンス │
────────────────────────────────────────────────────── │
| 用途 | URL |
|---|---|
| レース結果 | https://db.netkeiba.com/race/{race_id}/ |
| 出馬表(フォールバック) | https://race.netkeiba.com/race/shutuba.html?race_id={race_id} |
| 当日レース一覧 | https://race.netkeiba.com/top/race_list.html?kaisai_date={YYYYMMDD} |
race_id の構造: YYYYMMDDVVRR
YYYY: 年, MM: 月, DD: 日VV: 会場コード (05=東京, 06=中山, 09=阪神 など)RR: レース番号 (01~12)レース基本情報(races_ultimate.data に JSON 格納)
| フィールド | 型 | 例 |
|---|---|---|
race_name | str | "日本ダービー" |
date | str (YYYYMMDD) | "20260601" |
venue | str | "東京" |
venue_code | str | "05" |
distance | int | 2400 |
track_type | str | "芝" / "ダート" |
weather | str | "晴" / "曇" / "雨" |
field_condition | str | "良" / "稍重" / "重" / "不良" |
num_horses | int | 18 |
post_time | str | "15:40" |
kai | int | 開催回 |
day | int | 開催日 |
course_direction | str | "右" / "左" / "直線" |
馬別情報(race_results_ultimate.data に JSON 格納)
| フィールド | 型 | 例 |
|---|---|---|
horse_number | int | 7 |
bracket_number | int | 4 |
horse_name | str | "ドウデュース" |
horse_id | str | "2020110038" |
sex_age | str | "牡3" |
sex | str | "牡" / "牝" / "セ" |
age | int | 3 |
jockey_name | str | "武豊" |
jockey_id | str | "00356" |
jockey_weight | float | 57.0 |
trainer_name | str | "友道康夫" |
trainer_id | str | "01101" |
weight_kg | int | 492 |
weight_diff | int | +4 |
odds | float | 4.5 |
popularity | int | 2 |
finish_position | int | 1 |
finish_time | str | "2:23.5" |
margin | str | "クビ" |
last_3f | str | "34.8" |
last_3f_rank | int | 3 |
corner_positions | str |
ファイル: keiba/data/keiba_ultimate.db (SQLite3, WAL モード)
-- レース基本情報(1レース1行)
CREATE TABLE races_ultimate (
race_id TEXT PRIMARY KEY,
data TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- 馬別データ(1頭1行)
CREATE TABLE race_results_ultimate (
id INTEGER PRIMARY KEY AUTOINCREMENT,
race_id TEXT,
data TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX idx_results_race_id ON race_results_ultimate (race_id);
現状規模
races_ultimate: 約 14,000+ レースrace_results_ultimate: 約 180,000+ 行(平均 13 頭/レース)add_derived_features() — 派生特徴量 (~40列追加)休養期間
| 特徴量 | 型 | 説明 |
|---|---|---|
days_since_last_race | int | 現レース日 - 前走日(日数) |
rest_category | str | "short" / "normal" / "long" / "very_long" |
前走・2走前
| 特徴量 | 説明 |
|---|---|
prev_race_finish | 前走着順 |
prev_race_time | 前走タイム(秒) |
prev_race_weight | 前走馬体重 |
prev_race_distance | 前走距離 |
prev2_race_finish | 2走前着順 |
prev2_race_distance | 2走前距離 |
距離・馬場変化
| 特徴量 | 説明 |
|---|---|
distance_change | 今走距離 - 前走距離 (m) |
distance_increased | 1/0(距離延長) |
distance_decreased | 1/0(距離短縮) |
surface_changed | 1/0(芝↔ダート変更) |
コーナー通過派生
| 特徴量 | 説明 |
|---|---|
corner_position_avg | 平均コーナー通過順位 |
corner_position_variance | 通過順位の分散(低=安定した脚質) |
last_corner_position | 最終コーナーでの通過順位 |
position_change | 1C→最終Cの順位変化(正=追い込み) |
近走統計(expanding window)
This is the beginning of the README. Read the rest at the original. Read the full README ↗
"7-7-4-3" |
corner_positions_list | list[int] | [7, 7, 4, 3] |
prize_money | float | 30000 |