Baseball decision analysis with ML.NET and Blazor
This scenario describes a web application, called the Baseball Machine Learning Workbench, which provides an interface for non-technical users to use artificial intelligence (AI) and machine learning (ML) to perform decision analysis techniques in order to rapidly gain insights and make informed predictions.
This solution uses historical baseball data to generate National Baseball Hall of Fame insights. Machine intelligence powers the what-if analysis, decision thresholding, and improvements over traditional rule-based systems. User-friendly interface controls set adjustable parameters and surface the results in real time, with clear visual cues to highlight positive or negative outcomes.
The architecture provides rapid results by using in-memory models and rapid two-way communication between the user and server. Delta rendering pushes down only modified content to the web browser, updating the display without having to reload the entire page. This solution can scale to tens of in-memory models serving hundreds of concurrent sessions in real time.
The following article explains the architecture of the Baseball Machine Learning Workbench, where to get the source code for it, and how to deploy it. You can also view a live demo of this solution.
Relevant use cases
Consider this scenario for the following use cases:
Decision analysis system replacement with AI and ML
AI-assisted decision support systems or decision management systems
Business goal and objective modeling (budgeting and project planning, for example)
The processing sequence in this solution flows as follows:
The user accesses the workbench application with any browser. They choose which analysis method to employ and then which player to analyze.
SignalR brokers two-way communication with the server in real time.
Azure App Service hosts the application, including AI logic with the machine learning models.
One of three different decision analysis mechanisms is utilized, depending on which mode the user has selected.
Historical data is analyzed using the designated set of rules or ML models in ML.NET, operating in-memory for very quick inference.
Blazor Server surfaces the results to the end user's browser, updating only the portions of the interface that have changed, and transmits back to the user via SignalR.
Azure Application Insights is optionally used to monitor performance and instrumentation resources as needed.
The following assets and technologies were used to craft the Baseball Machine Learning Workbench:
Azure App Service enables you to build and host web applications in the programming language of your choice without managing infrastructure.
.NET Core 3.1 is an open-source, cross-platform, general-purpose development framework that runs on Windows, Linux, and macOS platforms.
ML.NET is a cross-platform, open-source framework for creating machine learning and artificial intelligence models using .NET. It is used in the inference sections of this application.
SignalR provides asynchronous communication between the browser and the server (including Blazor). It handles event updates, UI updates, and any processing done on the server (such as model inference).
Visual Studio 2019 is the software programming environment used for this project. This architecture uses cross-platform components, so either the Windows or Mac version can be used.
This solution uses the prediction engine functionality in ML.NET to scale the model response times. Object pooling allows the ML.NET models to be accessed by multiple requests in a thread-safe manner. Learn more about ML.NET object pooling in Deploy a model in an ASP.NET Core Web API.
Azure App Service is used for hosting the workbench in the cloud. With App Service you can automatically scale the number of instances that run your app, letting you keep up with customer demand. For more information on autoscale, refer to Autoscaling best practices in the Azure Architecture Center.
In Blazor Server, the state of many components might be maintained concurrently by the server. Because of this, memory exhaustion is a concern that must be addressed. For guidance on how to author a Blazor Server app to help ensure the best use of server memory, consult Threat mitigation guidance for ASP.NET Core Blazor Server. Applying these best practices allows a server-side Blazor application to scale to thousands of concurrent users—even on relatively small server hosts.
General guidance on designing scalable solutions is provided in the Azure Architecture Center's Performance efficiency checklist.
Resiliency and support
Use .NET Core 3.1.x because it is a Long Term Support (LTS) release. Although Blazor Server is also available in .NET Core 3.0, that is not an LTS release and thus continuing compatibility with future component updates is not assured. Learn more about the .NET Core Support Policy.
Deploy this solution
For online deployments, you must have an existing Azure account. If you need one, create a free Azure account before you begin.
The historical baseball data used for the analysis and machine learning models comes from Sean Lahman's Baseball Database, which is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. The Major League Baseball data itself is public domain.
Deployment to Azure
Make sure you have your Azure subscription information handy.
Start by cloning the workbench GitHub repository:
git clone https://github.com/bartczernicki/MachineLearning-BaseballPrediction-BlazorApp.git
Follow the instructions provided in the GETSTARTED.md file.
Alternative: Docker container
This application is also available as a complete, ready-to-run Docker container downloadable from Docker Hub.
The container can be run locally (offline) in your own environment. It can also be deployed online in an Azure Container Instance. Instructions for getting started with either use case are provided in the main GitHub repo's Get Started documentation:
View a live demo of this solution
Baseball HOF prediction using R mlr and DALEX packages is a GitHub repo using R and cutting edge “black box” model techniques to explain ML.NET models related to this workload
MLOps (DevOps for Machine Learning) helps data science teams deliver innovation faster, increasing the pace of ML model development
Learn about the National Baseball Hall of Fame voting process and rules
XAI Stories: Case Studies for Explainable Artificial Intelligence (Warsaw University of Technology and University of Warsaw, 2020)