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. These techniques help you rapidly gain insights and make informed predictions.
Architecture
Download a Visio file of this architecture.
Dataflow
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 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.
Components
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.
Blazor Server lets you build interactive web UIs using C# instead of JavaScript, as in this solution. In this architecture, Blazor renders the UI on the server and pushes HTML and other changes out to the browser.
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 2022 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.
Azure Application Insights, a feature of Azure Monitor, can be used for performance monitoring and analytics and to drive autoscaling.
Scenario details
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.
This 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.
Potential use cases
This solution is ideal for the sports and finance industries. 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
Fantasy baseball
Financial forecasting
Business goal and objective modeling (budgeting and project planning, for example)
Considerations
These considerations implement the pillars of the Azure Well-Architected Framework, which is a set of guiding tenets that can be used to improve the quality of a workload. For more information, see Microsoft Azure Well-Architected Framework.
Scalability
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, see 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 maintenance, 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, see 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 scenario
All of the source code for this scenario is available in the Baseball Machine Learning Workbench repository. This solution is open source and provided with an MIT License.
Prerequisites
For online deployments, you must have an existing Azure account. If you need one, create a free Azure account before you begin.
For deployment as an Azure application instance, you need the Visual Studio 2019 IDE and you must have Git installed locally.
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 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:
Next steps
- 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
- Azure App Service overview
- Blazor documentation
- ML.NET documentation
- ASP.NET Core Blazor hosting models
- 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)