The MLB Lineup Optimizer is an interactive decision-support tool designed to recommend a starting lineup based on the opposing starting pitcher. I built an Excel dataset using FanGraphs hitter, pitcher, and fielding data from 2024 through 2026, with additional handedness information used to identify the correct platoon matchup for each player.
Using Excel and RStudio, I cleaned and combined the data, created matchup-specific hitter and pitcher profiles, and developed a Matchup Index to compare each available hitter against the selected starting pitcher. The final system was integrated into an R Shiny application and deployed through shinyapps.io.
AI tools were used throughout development to assist with coding, debugging, and editing.
The model evaluates hitters using their performance against the opposing pitcher’s handedness and evaluates pitchers using their performance against the hitter’s batting side. Switch hitters are evaluated from the side they would bat in the specific matchup.
Performance from 2024 through 2026 is weighted toward more recent seasons, while plate appearances and batters faced are also considered so larger samples carry more influence.
Hitter Index: wOBA 60% · ISO 25% · K% 15%
Pitcher Favorability Index: K% 40% · BB% 30% · AVG Allowed 30%
The two components are combined into a Matchup Index centered around 100, where higher values indicate a more favorable matchup for the hitter. Smaller samples are adjusted toward the league average to reduce the impact of limited playing time.
Once the available position players and opposing starter are selected, the tool calculates a Matchup Index for every hitter and uses optimization to identify the highest-value legal starting nine.
The lineup must include:
C · 1B · 2B · 3B · SS · LF · CF · RF · DH
Defensive eligibility is based on 2026 positional appearances, while every hitter is eligible to fill the DH spot.
After selecting the starting nine, the app creates a recommended batting order using matchup quality along with on-base ability, contact, and power.
Different scoring profiles are used for the top, middle, and remaining portions of the order so the lineup is not simply ranked from highest to lowest Matchup Index.
The Matchup Index is a relative matchup rating rather than a projection of exact offensive production. The project is designed as a transparent lineup decision-support tool rather than a predictive machine-learning model.
To test the optimizer in a real game setting, I used the Yankees’ available position players from their July 19 matchup against Yoshinobu Yamamoto. Yamamoto pitched a complete game as Los Angeles defeated New York 8–2, making this an interesting opportunity to examine whether a different lineup construction could have created more favorable individual matchups.
Yankees Actual Lineup, 7/19/26
Trent Grisham, CF
Ben Rice, 1B
Jasson Dominguez, DH
Cody Bellinger, RF
Max Schuemann, RF
Jazz Chisholm Jr., 2B
Anthony Volpe, SS
Ryan McMahon, 3B
Ali Sanchez, C
Yankees Optimized Lineup, 7/19/26
Results
The optimizer retained six of the Yankees’ nine actual starters, but recommended three changes based on the matchup with Yamamoto: Austin Wells (88.5) over Ali Sánchez (71.8), Amed Rosario (86.4) over Max Schuemann (77.0), and José Caballero (77.3) over Anthony Volpe (76.4). The model also substantially reordered the lineup, led by Ben Rice (111.5), Trent Grisham (102.3), Cody Bellinger (100.9), and Jazz Chisholm Jr. (98.8) in the top four spots.
This case study shows how the Matchup Index can influence both player selection and batting order by comparing each available hitter specifically against the opposing starter, rather than relying solely on a player’s overall offensive reputation or typical lineup position.