How to create horse racing AI | From data preparation to predictive model verification
When creating a horse racing AI, the first thing to decide is not the programming language, but what to predict and what to judge as useful. The required data and evaluation methods are different between a model that predicts the order of arrival and a model that supports purchase decisions based on certain conditions. There is no way to always make a prediction using horse racing AI. In this article, we will organize the basics of learning and verification using past results.
The shortest creation procedure is in 5 steps: Decide what to predict → Collect data that can be used at the time of prediction → Separate data for learning and verification based on event date → Compare with criteria such as popularity → Evaluate by fixing purchase conditions.
What does horse racing AI predict?
An easy challenge for beginners to try is the task of predicting whether each horse will finish in the top three in that race. Next, proceed to predictions according to your purpose, such as the probability of winning first place. If you use the output as a probability, check not only whether the ranking matches, but also whether the predicted probability matches the actual frequency.
By mixing race-based conditions and horse-based conditions, it becomes easier to include information from the same race for both training and validation purposes. When separating your data, pay attention to race and date.
What data do we use and how do we check the terms of use?
You can refer to official information such as JRA race results and annual results. However, being able to view it and being allowed to acquire it in bulk, redistribute it, and use it for commercial purposes are different things. Please check the terms, acquisition method, and scope of use of the data provider you use first.
JRA race resultshttps://jra.jp/faq/pop02/1_6.html
annual resultshttps://jra.jp/datafile/seiseki/report/2026.html
The first table organizes the event date, race ID, horse ID, racetrack, distance, past results, and the day's results. Missing values and spelling errors in names are also recorded. If you use odds as a feature, use only the values that can be confirmed at the time of prediction. If you mix up the information after it has been confirmed, you will end up with a score that is not actually obtained.
| Type of data | Can it be used for prediction | Things to check |
|---|---|---|
| Past race results | Can be used in principle | Acquisition conditions, race dates, and horse ID correspondence |
| Horse track/race information released before the prediction | Can be used if the release time is correct | When was the information confirmed |
| Finishing order and refund confirmed after prediction | Not used for input | Used only for correct answer labels and evaluation |
| Odds | Consider if the acquisition time is right | Are confirmed values after the deadline mixed in? |
How to verify with past data?
- Separate the older period for learning and the later period for verification.
- The average value and dictionary for preprocessing are determined only from the training data.
- Compare with simple standards. Before using a complex model, look at how it compares to a known standard, such as popularity.
- Verify multiple times by varying the verification period.
- Finally, reevaluate in the most recent period when you haven't used it.
If you just divide the rows randomly, the horses in the same race will be divided into training and testing, which can be close to knowing the results. Also, if you repeat adjustments while checking the results of the verification period, you will end up with a model that is suitable for that period.
How to distinguish between hit rate and return rate?
Even if the winning rate is high, the income and expenses will vary depending on the odds of the horse you choose and the purchase conditions. On the other hand, even if the recovery rate appears high with a small number of high dividends, the influence of chance may be significant. If you are performing an evaluation that involves a purchase, record the number of purchased points, number of eligible races, period, refund amount, and purchase amount as a set. Difference between hit rate and recovery rate will explain in detail.
Where should I start if I want to create a prototype using Python?
Loading tabular data, dividing it by event date, processing missing values, and creating a standard model and evaluation table in order will make it easier to track where grades have changed. There is no need to choose a complex deep learning model from the beginning. Before writing the code, list the source of the data and "items that can be known at the time of prediction."
The following table is an example of CSV items to be prototyped. Each line is defined as "one horse that ran in one race", and each horse in the same race is given the same race_id. top3 is the correct answer for learning, where it is 1 if it is in the top 3, and 0 otherwise. Please match the column names of the actual data according to the specifications of the provider.
| Column name | Contents | Handling during prediction |
|---|---|---|
race_date, race_id, horse_id | Values that identify the date, race, and horse | Used for division and aggregation |
distance_m・track_condition | Distance and track condition | Use only published values at the time of prediction |
past_top3_rate | Top 3 rate calculated from the horse's past performance | Calculated using only the performance prior to the target race |
win_odds_at_prediction | Winning odds recorded at the time of prediction | Save the acquisition time. Excludes models that are not used |
finish_position・top3 | Confirmed finish order and correct answer label | Not included in prediction input |
A minimal Python example that separates training and validation is: Prepare the above columns in races.csv, install and run pandas and scikit-learn. Please change the division date according to the data at hand. This example shows the validation steps and does not represent predicted performance.
import pandas as pd
from sklearn.impute import SimpleImputer
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import make_pipeline
df = pd.read_csv("races.csv", parse_dates=["race_date"])
train = df[df["race_date"] < "2026-01-01"].copy()
test = df[df["race_date"] >= "2026-01-01"].copy()
if train.empty or test.empty:
raise ValueError("学習用と検証用の両方にレースが必要です")
# 予測前に確定する数値だけを入力にする
features = ["distance_m", "past_top3_rate"]
model = make_pipeline(SimpleImputer(strategy="median"), LogisticRegression(max_iter=1000))
model.fit(train[features], train["top3"])
test["predicted_top3_probability"] = model.predict_proba(test[features])[:, 1]
# 各レースで最も確率の高い1頭を選び、3着以内だった割合を確認する
selected = test.loc[test.groupby("race_id")["predicted_top3_probability"].idxmax()]
print("対象レース数:", len(selected))
print("3着内率:", selected["top3"].mean())
Criteria such as popularity order are also calculated and compared for the same verification period and race. The top 3 rate shown above is not the winning rate or return rate of the horse racing ticket. When evaluating purchases, please separately record the ticket type, number of points purchased, purchase amount, and refund amount. Also, if past_top3_rate is calculated from the results of the entire period, future results will be mixed in, so it will be aggregated up to just before each race.
What we can learn from development experience
Public records of the developer "Fuji Keiba" who worked as an intern at ZETTAI describes the process of preprocessing data, designing features, dealing with overfitting, and redoing verification. This is the experience of the developer himself. This is not the verification result of the Python example in this article or the results of the model confirmed by ZETTAI.
Public records of the developer "Fuji Keiba" who worked as an intern at ZETTAIhttps://note.com/fujikeibaai/n/n7ae5775dce2a
FAQ
Can I create it using only free data? Small learning prototypes can be started with public information. However, please check the acquisition and usage conditions and whether you have all the necessary items.
**Will AI have a higher collection rate than humans?**Cannot be guaranteed. Past test results do not guarantee future performance.
When purchasing horse racing tickets, please check JRA Information and Purchase prohibited for persons under 20 years of age, and do so within your budget.
JRA Informationhttps://www.jra.go.jp/kouza/baken/index.html
Purchase prohibited for persons under 20 years of agehttps://www.jra.go.jp/faq/pop03/1_2.html