Machine learning has become so ubiquitous we hardly notice it. We ask Siri for directions and check Google Maps for a free parking spot. We discover new music and get reminders to breathe. In the meantime, tech giants use some serious machine learning technologies behind all these interactions.
Can we harness this power of ML for our own mobile apps? If you’d like to learn how to build machine learning applications, this blog is the right place to find the answers. We’ll discuss how to equip your mobile app with ML features and share some best practices for mastering artificial intelligence.
- The easiest way to build a machine learning app for smartphones is to use ready-made ML services from Google, e.g., ML Kit or Firebase ML, and Core ML from Apple.
- There are two basic options for approaching machine learning app development. One is to keep all ML functionality in the cloud, and the second is an edge case when all ML happens right on a mobile device.
- Starting an app that uses machine learning, keep in mind that one of the challenges will be to put together a team of expert data scientists who will be responsible for creating viable ML models.
Table of Contents
- How to Build a Machine Learning App
- Step 1: Define the problem
- Step 2: Assemble the right team
- Step 3: Define your app’s architecture
- Step 4: Pick a tech stack for developing a machine learning mobile app
- Step 5: Get the data ready
- Step 6: Build, train, and validate ML models
- Step 7: Deploy machine learning models into a mobile app
- Step 8: Maintain ML operations
- How Can Topflight Apps Help You With Machine Learning App Development?
What Does It Take to Build a Machine Learning App?
If you’ve read any of our guides on developing different mobile apps, you probably remember that ML often poses as an add-on feature.
In fact, it always appears that way to your customers, who take for granted many things on mobile phones. Yet, building these AI capabilities into an app requires a lot of effort. In essence, machine learning mobile app development implies creating ML models that output some valuable data.
That means you’re still custom building a mobile app, but this time you need to figure out how to fit this part with ML models inside it in a way that benefits users. And frankly, there’s quite a lot to tackle.
So I suggest we skip the part where you:
- design, prototype, and verify a prototype
- code and test
- deploy and maintain an app (because you do these things with any mobile app)
Instead, we’ll zero in on ML development in mobile apps per se. So if you’re looking for steps on how to create a machine learning mobile app, here they are.
Step 1: Define the problem
That may seem pretty obvious, but with all the AI hype, it’s easy to overthink and try to implement ML when it’s not necessary. Start by answering these questions:
- What benefit will my customers get from this ML feature?
- Can I solve this task without using ML?
For example, suppose your chatbot has a well-defined tree of dialog options, where all answers and questions are hardcoded. In that case, there’s clearly no use in messing with AI. It’s when you can’t fulfill your business needs with regular algorithms (e.g. to analyze user behavior), then machine learning calculations become the holy grail.
Related: How to Build a Chatbot
Apple’s, Google’s, Microsoft’s, and other tech giant’s guidelines for ML app development advise you should also think about such things as:
- What happens when ML algorithms fail?
- What will be the criteria for a successful outcome for the customer?
- Do I have enough data to train a sustainable model?
- Will my customers be able to provide any feedback?
- Will my ML models evolve over time?
Starting an app that uses machine learning is a challenging task, so it makes all the sense in the world to spend enough time considering alternative ways to solving this business problem.
Step 2: Assemble the right team
Besides app developers, full-stack backend developers, designers, and QA engineers, you will need data analysts (or data scientists) to build a machine learning mobile application. These are specialists who deal with data and create ML models.
Step 3: Define your app’s architecture
Not so long ago, app developers always had to rely on an external server for enabling AI features in apps. The idea is there’s a powerful server with all the ML infrastructure, running data analysis, and an app fetches the output from the server.
Today, thanks to faster CPUs and GPUs and dedicated ML chips in modern smartphones, you have options of where to keep the ML portion of your app:
- cloud hosting with APIs
- on-device SDKs or custom libraries
- a hybrid approach, which is a mixture of the two mentioned options
Certainly, there are some pros and cons for each scenario. So how do you decide which works best for you?
When do you want to keep ML in the cloud?
First of all, let me just say that from the machine learning app development perspective, it’s the easiest way — on the app side of things, that is. You build a regular mobile app and simply integrate it with the AI-powered back end via APIs. You call the server, get the answer, serve it to the customer, and update the server based on the user feedback, but that’s it . Easy-peasy, right?
Well, unfortunately, you still have to build all the ML server infrastructure. And sure, you can circumvent that by using off-the-shelf solutions, but we’ll discuss that in a bit. The fact remains: the ML complexity just shifts to a server.
The most common reasons for choosing this cloud-ML-hosting scenario include:
- more apps will use the ML functionality down the road
Let’s say you’re planning to make a web or a desktop app later on. Adding ML features to them will be as easy as connecting them with the ML server-side via APIs.
- users with older, slower phones should be able to access the ML features
Machine learning processing requires very intensive computing power. While modern smartphones (since iPhone 8 and Pixel 4) are quite capable of that, many phones would still struggle with on-device ML tasks.
- the ML model has to be trained non-stop in real-time
Imagine a stock trading app with bots that need to learn on the fly about market movements to make the correct predictions about stock prices.
- the ML model is too large to fit on a mobile device
Machine learning models may often require more than 100Mb of disk space, making downloads less likely to happen, given an average app size of 100Mb.
- the algorithm’s output should combine with other data pulled from third-party APIs
Let’s say you’re Netflix, and you want to fetch information from IMDB about my reviews and ratings before serving me movie recommendations solely based on my activity in the Netflix app.
Also read: NLP App Development Guide
When to keep ML on a smartphone?
Creating apps that use machine learning hosted on devices makes the app development process a little more complicated. Fortunately, there are some legit shortcuts, much like with the cloud hosting option, which we’ll discuss shortly.
Anyways, what are the advantages of setting up a machine learning application with the ML part hosted by an app?
Since machine learning algorithms run right on a smartphone, we no longer need to wait for an answer from a server like in the cloud hosting case. That’s particularly important for apps that require extra smooth video (e.g., AR apps) and audio playback. Another example is mobile software automatically tagging objects in photos posted on social media.
Dedicated hardware AI chips and a potent combination of powerful GPUs and CPUs make the user experience buttery smooth. Think of a mobile app instantly recognizing all players while you’re watching a sports match.
Increased privacy and data security
For the mobile apps relying on the analysis of personal data, this information no longer needs to travel to a server because all processing and data mining happens right on smartphones.
Lower cost of development and maintenance
Unlike the cloud option, you don’t need to worry about server infrastructure development and maintenance. Accordingly, the cost of development goes down. Plus, you save on decreased bandwidth usage.
Always available, even without an internet connection
Customers can access ML features even when they are offline because the model sits right on their devices.
What about the hybrid option?
The hybrid option can boast the best user experience but also costs a pretty penny. In this scenario, a food delivery app would serve, say, dish recommendations based on the data coming from a server, and users would still be able to detect food with their camera in an offline mode.
Another common scenario would be natural language processing. Imagine a translation app that allows users to download an ML module handling the French-English language pair so they can converse freely offline. Other languages would still require an internet connection to work.
Carefully weigh in all these AI implementation options before you start an ML app.
Step 4: Pick a tech stack for developing a machine learning mobile app
When you create a machine learning app from scratch, you may choose to build a completely custom solution or use off-the-shelf machine learning components.
Of course, developing from scratch offers more flexibility. You can pick any tech stack and tools for creating the AI core for your mobile app. At the same time, canned ML services remove a lot of the burden associated with building custom ML functionality.
Tech stacks for developing ML apps from scratch
What frameworks and technologies are available for machine learning in app development?
Programming language: the most frequently used programming language for ML development is Python.
AI/ML stack: there’s definitely no shortage of decent ML frameworks allowing you to build machine learning models. Some popular choices include TensorFlow, PyTorch, Caffe, Scikit, Keras, Pandas, Numpy, and MXNet.
Big data-processing: knowing that you’ll have to deal with massive amounts of information, you should also identify appropriate technologies for managing this data. Spark or Hadoop fit great for this purpose.
There are many other instruments available to streamline and automate ML development. For example, CometML is a service that simplifies collaboration and version control during ML development. There’s also Dask-ML that helps to train ML models for neural networks faster.
Also Read: IoT App Development Guide for 2022
However, these nascent tools are not required for proper AI development. The rest of the tech stack can be absolutely anything that works best for you.
|Top 5 ML-Specific Technologies across the stack|
|Cloud services||AWS SageMaker||Google Cloud AI Platform||Azure ML Studio||IBM Watson||Azure DataBricks||AWS Glue|
|Tools||Jupiter Notebooks||Google Colab||Airflow||Google Data Lab||Hevo||SQL Alchemy|
Off-the-shelf components for making ML apps
Machine learning technologies have developed to a point when you can insert an ML feature into an app like a plugin. Well, almost.
Remember when we talked about using ready-made solutions to enable chats, maps, notifications, and other typical features in your mobile app? The same goes for ML, although I’d recommend sticking with offerings from the big guys like Apple, Google, and similar. What are our options with machine learning in mobile app development?
Cloud-hosting ML services: the big players in this field, as I mentioned, are technology giants like AWS, IBM, Microsoft, and Google. These companies push forward the concept of AutoML, implying that the big hairy mess of ML can be abstracted away and dealt with somewhat indirectly.
Amazon Web Services offers the following AutoML instruments:
- AutoGluon (an ML library automating deep learning (DL) and machine learning)
- SageMaker platform (a tool for building, training, and deploying ML models)
Google’s ML arsenal includes:
- TensorFlow (including TensorFlow.js)
- Firebase ML (back end powered by AI)
- Cloud AI (a variety of machine learning products and services)
- Cloud AutoML (tools for training custom machine learning models)
Microsoft and IBM also offer plenty of tools and services to develop, train, and deploy ML components. Keep in mind that you host your ML core in the cloud with the tools mentioned above and integrate your mobile app with it via APIs.
Mobile app-hosting ML services: Google and Apple dominate this niche as rightful owners and creators of Android and iOS ecosystems.
For on-device ML on Android, use ML Kit or TensorFlow Lite by Google. One exciting thing about ML Kit is that it’s part of Google Play Services; therefore, apps don’t need to include some ML bits into their app, and users can enjoy faster app downloads.
For on-device ML on iOS, use Core ML by Apple or ML Kit/ TensorFlow Lite by Google. As you can see, using TensorFlow Lite or ML Kit ensures your ML models will work on both iOS and Android.
However, I suggest that you stick with natively supported Core ML on iPhones and iPads because the tool will allow you to fully exploit the computing capabilities of Apple’s devices. In addition, Apple offers a Create ML app that helps you train models in a drag-and-drop interface.
One more thing worth mentioning about off-the-shelf ML solutions is that you still get to customize ML features for your app in addition to saving time and money for implementation. That’s far from plugging ML into your app to use as is for predictive analysis.
Step 5: Get the data ready
Data availability is precisely why creating apps that use machine learning should start with answering questions like, “Do we have enough data?” Simply because AI features hinge on data analysis: the more data you collect for analyzing, the better results you will get.
However, gathering data alone is not enough to make a machine learning app. We need to run data through a series of pre-processing steps before creating models with it:
Data may come from disparate sources. Therefore, it needs to be cleansed and brought to a standard format. These activities include many manipulations, such as transforming all information to numeric values, removing statistical noise and errors, identifying the most relevant input variables, etc. Otherwise, we may end up with what a legendary IBM programmer called:
“Garbage in. Garbage out.”
After we have pre-processed data, we need to divide it into two sets:
- data set for training ML models
- data set evaluating created models
The rule of thumb here is to use the 80/20 ratio, with 80% of data going into the training data set and 20% being used for testing models. We use algorithms to train a model in the training set by pairing input with the expected output. In other words, we need to label all data in the training dataset. That’s the learning part in ML.
Step 6: Build, train, and validate ML models
The next step in developing a machine learning mobile app is creating ML models. That’s where the real magic of ML happens.
I wish I could tell you more, but the reality is it’s a really complicated subject that could easily take another long read to consider, even on a high level. And that’s why you need a development team comprised of skilled data science engineers.
They tinker with learning algorithms, using the tools I’ve outlined above, e.g., PyTorch or TensorFlow, to create models that output desired results. In the process, they evaluate different models, blend them into a single one or choose one model that significantly outperforms the rest.
The two types of models that data scientists build include:
- classification (when you need to predict to which class any object belongs)
- regression (when you need to predict continuous values)
A couple of things to keep in mind when working on ML models:
- you can use existing models and customize them to your liking
- you can build models from scratch
- you may have to convert some models if they are incompatible with the tools you use
- you should test and validate your models only with the trained data, no previously “seen” by the machine
In the end, you get a model that spits out reliable predictions, and you can congratulate yourself. You’ve almost finished building a machine learning application.
Step 7: Deploy machine learning models into a mobile app
Once you have built, trained, and validated ML models, you’re really close to completing making a machine learning mobile app.
From the app perspective, adding ML is as simple as implementing APIs, calling a server where models are hosted and adding a mobile SDK, or adding the models directly to code.
But from the back-end perspective, things are a little bit more complicated. When you have multiple models and a team of data scientists constantly working on making them better, you need to establish an ML pipeline.
ML pipelines help automate the workflow required to produce a machine learning model: from data extraction and preprocessing to model training and deployment. Using such end-to-end machine learning pipelines, data scientists can optimize models going forward and scale the solution with ease.
Step 8: Maintain ML operations
Finally, after uploading AI-charged mobile apps to the App Store and Google Play, you need to maintain the apps (of course, to accommodate new OS features and remove lingering bugs) and the ML infrastructure, if it’s running on a server.
There are various MLops (machine learning operations) tools you can use for that:
- Domino Data Lab
In short, these solutions help to automate model versioning, implement pipelines, scale models on-demand, and other aspects of machine learning application development, so you can keep your models operating at their best.
How Can Topflight Apps Help You With Machine Learning App Development?
Hopefully, you have a better understanding of how to build your own machine learning app. We’ll be happy to discuss your ML project and offer our recommendations on machine learning applications development if you schedule a call with one of our experts.
[This blog was originally published in August 2021 but has been updated with more recent content in March 2022]
Frequently Asked Questions
What's the easiest way to add machine learning in mobile apps on iOS?
Core ML or TensorFlow Lite
What are the benefits of machine learning in mobile apps development?
Businesses get to sell more by offering more personalized experiences to customers. Customers get their stuff done faster.
What are the main types of machine learning algorithms?
Supervised — learning patterns from training data with marked correct output; unsupervised — detecting patterns without human assistance; reinforcement — continuous learning from the environment to discover all possible states.
What if my startup wants to create IoT software unlocking ML-powered analytics for enterprises? Do we need to keep ML features on a website?
Using TensorFlow Lite, you can deploy ML models right to microcontrollers.
I want to develop a machine learning application for iOS only. What will be my biggest challenge?
Compressing the ML model to a manageable size, especially if you envision on-device ML usage.