Machine Learning in Cloud

September 11, 2024

Machine learning is a very resource-hungry field, requiring significant computational power, storage, and scalability.

Let us say you want to develop a Large Language Model, scratch it, even if you want to develop a Small Language Model pertaining to specefic tasks then setting up the necessary infrastructure would mean purchasing hardware, doing maintenance, and hiring machine learning expertise. Even if you want to set up the first of these namely GPU's, you have seen the stock price of Nvidia right?

Then how can a medium scale enterprise or a startup hinge on to the fast moving, rapidly evolving landscape of AI? The answer is Cloud Computing. With the advent of cloud computing, these barriers have been significantly lowered. The cloud offers virtually unlimited resources on demand, enabling organizations to scale their machine learning operations efficiently and cost-effectively.

Whether you're working on neural networks for image recognition, deploying pre-trained models for financial services, or integrating machine learning into various business applications, the cloud provides the necessary infrastructure without the need for heavy upfront investments.

Wait, what the F? Computing over the cloud? How did we get here? Let us answer these curious questions.

What is Cloud Computing?

Not on the literal cloud, cloud computing is the delivery of computing services—including servers, storage, databases, networking, software, analytics, and intelligence—over the Internet (“the cloud”) to offer faster innovation, flexible resources, and economies of scale. You typically pay only for cloud services you use, helping you lower your operating costs, run your infrastructure more efficiently by creating virtual machine, and scale as your business needs change.

Cloud computing services can be broadly categorized into three types: Infrastructure as a Service (IaaS), Platform as a Service (PaaS), and Software as a Service (SaaS). IaaS provides virtualized computing resources over the internet, PaaS offers hardware and software tools over the internet, and SaaS delivers software applications over the internet on a subscription basis. This model has transformed the way businesses operate by providing access to advanced technology and capabilities that were once only available to large corporations with significant IT budgets.

Cloud vs Traditional Computing

Well, we have gone through the major difference above, training a SLM in house would be called using traditional computing whereas training it on a cloud server would be called cloud computing! Here is the summarized difference,

Training Machine Learning Projects in the Cloud

Follow these five steps to train your machine learning project in the cloud.

Identify and Understand Your Data Sources

Sort through your data and identify the sources—this could be a complicated and time-consuming process, especially if you have incomplete data. If you need to move data from on-premises environments to the cloud, take into account data transfer rates in case of large data volumes, and check for any compliance or legal restrictions. 

It is important to provision the appropriate storage resources to store your dataset and compute resources to process it. 

Engineer the Features

Start your modeling process using iterative steps. First, conduct feature engineering to determine the variables you want to model. Next, start training the model. Feature engineering is a complicated but critical process and requires business and domain knowledge for exploratory data analysis. One challenge is to ensure you have the right number of variables to enable the model’s functionality while avoiding noise.

Train and Validate Your Model 

Model training is a standard procedure with iterative testing and training steps. Cloud-based machine learning is useful for testing multiple machine learning models, given the flexibility of cloud computing resources. The algorithms you use depend on your business requirements, data accuracy requirements, data volume and availability, parameters, and the computing task (i.e., classification, prediction).

Cloud providers offer automated machine learning services that let you tune hyperparameters and test multiple algorithms simultaneously. For example, Azure offers AutoML, which supports different ensemble modeling methods and incorporates best practices for building an ML model. It also provides a centralized workspace to keep track of your artifacts, including the full model history.

Deploy and Monitor Your Model 

Once you’ve built a model that meets your business objectives, you can deploy it at scale. Once you have trained the model using a cloud-based ML platform, deployment should be straightforward. This typically involves defining the model endpoint, specifying computing resources that should run the model, and hitting the switch.

When you deploy your model, you must monitor it continuously to ensure it functions properly. Monitor performance to verify if the model’s predictions are relevant and accurate. Some cloud ML platforms offer automated data drift monitoring. Look out for data drift to keep the predictions relevant (the input data can diverge from the training data over time). When data drift occurs, revisit your dataset and retrain the model with more relevant data.

Example:

Let's walk through an example of using machine learning on Azure. We'll use Azure Machine Learning to create, train, and deploy a machine learning model. For this example, we'll build a simple classification model to predict whether a customer will make a purchase based on their browsing behavior.

Step 1: Set Up Your Azure Environment

  1. Create an Azure Account: If you don't have an Azure account, you'll need to create one.
  2. Create a Machine Learning Workspace:some text
    • Navigate to the Azure portal.
    • Click on "Create a resource" and search for "Machine Learning."
    • Click "Create" and fill in the required details to set up your workspace.

Step 2: Prepare Your Data

  1. Upload Data to Azure Blob Storage:some text
    • In your Machine Learning workspace, go to "Datasets" and click "Create dataset" > "From local files."
    • Upload your dataset (e.g., customer_behavior.csv).

Step 3: Create and Train a Model

  1. Create a Jupyter Notebook in Azure Machine Learning Studio:
    • In the Azure Machine Learning Studio, go to "Notebooks" and create a new notebook.
  2. Install Required Libraries:
    !pip install pandas scikit-learn
  3. Load and Prepare the Data:
    import pandas as pd
    from sklearn.model_selection import train_test_split
    from sklearn.preprocessing import StandardScaler

    # Load data
    data = pd.read_csv('customer_behavior.csv')

    # Preprocess data
    X = data.drop('purchase', axis=1)
    y = data['purchase']

    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

    scaler = StandardScaler()
    X_train = scaler.fit_transform(X_train)
    X_test = scaler.transform(X_test)
  4. Train a Model:
    from sklearn.linear_model import LogisticRegression
    from sklearn.metrics import accuracy_score

    model = LogisticRegression()
    model.fit(X_train, y_train)

    # Evaluate the model
    y_pred = model.predict(X_test)
    accuracy = accuracy_score(y_test, y_pred)
    print(f"Model Accuracy: {accuracy}")

Step 4: Register and Deploy the Model

  1. Register the Model:
    from azureml.core import Workspace, Model

    ws = Workspace.from_config()
    model = Model.register(workspace=ws, model_path="model.pkl", model_name="purchase-prediction-model")
  2. Create an Inference Configuration:
    from azureml.core.environment import Environment
    from azureml.core.model import InferenceConfig

    env = Environment(name="inference-env")
    env.python.conda_dependencies.add_pip_package("scikit-learn")

    inference_config = InferenceConfig(entry_script="score.py", environment=env)
  3. Create a Scoring Script (score.py):
    import json
    import joblib
    import numpy as np
    from azureml.core.model import Model

    def init():
        global model
        model_path = Model.get_model_path("purchase-prediction-model")
        model = joblib.load(model_path)

    def run(raw_data):
        data = np.array(json.loads(raw_data)["data"])
        predictions = model.predict(data)
        return json.dumps(predictions.tolist())
  4. Deployment of machine learning:
    from azureml.core.webservice import AciWebservice, Webservice

    deployment_config = AciWebservice.deploy_configuration(cpu_cores=1, memory_gb=1)
    service = Model.deploy(workspace=ws,
                          name="purchase-prediction-service",
                          models=[model],
                          inference_config=inference_config,
                          deployment_config=deployment_config)

    service.wait_for_deployment(show_output=True)
    print(service.scoring_uri)

Step 5: Test the Deployed Model

  1. Send a Test Request:
    import requests
    import json

    scoring_uri = "your_service_scoring_uri"
    headers = {"Content-Type": "application/json"}

    test_data = json.dumps({"data": [[value1, value2, value3, ...]]})
    response = requests.post(scoring_uri, data=test_data, headers=headers)
    print(response.json())

Advantages of ML on cloud

It enables experimenting and testing multiple models

For one thing, the cloud allows you to scale your machine learning projects up and down as needed. You can start with a small set of data points and add more as you get more confident in your predictions. 

Variable usage makes it easy for enterprises to experiment with machine learning capabilities and scale up as projects go into production and demand increases.

You can also use machine learning to run experiments on different sets of data to see what works best. This is something that’s difficult or impossible to do on your own server at home or in your office building. And it’s something that requires a lot of time and effort if you want to do it yourself. In short, the cloud drastically speeds up the machine learning lifecycle.

It’s inexpensive

Traditional machine learning isn’t just complex and hard to set up: It’s pricey. If you want to train and deploy large machine learning models, such as deep learning, on your own servers, you’ll need expensive GPU cards. This is particularly true with today’s state-of-the-art models, such as China’s natural language Wu Dao 2.0, a model with nearly 2 trillion parameters. With such models, the cloud is a must-have, not just a nice-to-have.

In order to scale your models to accommodate large-scale needs, you’ll need high-end GPU units, which means that they’ll remain largely unused during periods of low use. In other words, you’ll have expensive servers sitting around collecting dust, while still requiring extensive maintenance.

On the other hand, when using machine learning in the cloud, you’re only paying for your consumption, which works wonders for scalability. Whether you’re just personally experimenting or servicing millions of customers, you can scale to any needs, and only pay for what you use.

It needs less technical knowledge

Building, managing, and maintaining powerful servers oneself is a complex task. With the cloud, much of the complexity behind these tasks is handled by the cloud provider.

Popular cloud services like AWS, Microsoft Azure, and Google Cloud Platform in fact offer machine learning options that don’t require deep knowledge of AI, machine learning theory, or a large team of data scientists.

With the cloud, AI can be deployed in a matter of minutes. It also scales automatically, so you don’t have to worry about the technical complexity of provisioning resources or managing infrastructure.

Easy integration

Most popular cloud services also provide SDKs (software developer kits) and APIs. This allows you to embed machine learning functionality directly into applications. They also support most programming languages. 

It reduces time-to-value

Another important aspect of the cloud is that it reduces the time-to-value. Time-to-value is the amount of time it takes from when you start a project to when you see results from it.

In traditional machine learning deployments, this process can take months or even years. With the cloud, you can start seeing results in hours or days. That’s because you don’t have to provision resources, manage infrastructure, or write code. You can simply upload your data and start building models.

Access to more data

Data is the lifeblood of machine learning. The more data you have, the better your models will be. And the cloud provides access to more data than ever before.

For example, if you’re building a predictive model for customer churn, you can access historical customer data that’s stored in the cloud. This data can be used to train your machine learning model so that it can make better predictions.

Security and privacy

When done right, machine learning in the cloud is secure and private. That’s because the data is stored in the cloud provider’s secure data center.

The cloud provider is responsible for the security of the data center and the data that’s stored there. This means that you don’t have to worry about building your own security infrastructure.In addition, most cloud providers offer additional security features, such as encryption, to further protect your data.

It frees up resources

Machine learning in the cloud frees up resources so that you can focus on other things. For example, if you’re building a machine learning model to predict demand for a new product, you can use the cloud to train and deploy the model. This frees up your time so that you can focus on other things, such as marketing the product.

When done right, machine learning in the cloud provides a number of benefits that are difficult or impossible to achieve with traditional machine learning. These benefits include reduced time-to-value, easier integration, and increased security and privacy.

Limitations of ML on Cloud

It doesn’t replace experts

Machine learning is a powerful tool, but it can’t make decisions on its own. And machine learning systems need to be monitored and corrected by humans. This is true for virtually any technology, not just machine learning. It’s also true for many of the most exciting uses of machine learning today: from fraud detection in credit card transactions to improving cancer treatments to predicting earthquakes. 

These are all great applications that could benefit from machine learning, but they still require human oversight and intervention.    

The limitations of machine learning are sometimes overstated, especially in the media. But there are real limits to what artificial intelligence(AI can do without human supervision and intervention. Machine learning can’t yet replace experts at every step of the process, because no algorithm can understand everything about a situation or know how to react in every possible scenario.

Data mobility

The cloud is a great place to run machine learning models, but it also has some limitations. For example, if you want to move your data from the cloud to another cloud provider, you have to do so in a way that doesn’t impact the performance of your model. 

This can be tricky because machine learning models are often sensitive to small changes in their input data. If, in order to change the location of your data, you need to make changes to its format or size, for example, then your model might not work as well anymore.

Solving these data mobility solutions with multi-cloud data lakes can seriously add to the pricing, particularly if you’re looking for solutions on-premises.

Risk associated with natural calamities and attacks

You will always run the risk of your data center facing problems caused by natural calamities and attacks made by hackers. This includes downtime, data leaks, and loss of data. It's important to invest in a secure platform that has distributed data centers and maintains multiple copies of your data.

Machine learning models can be hacked. If an attacker gains access to your AWS account credentials, for instance, they can use those credentials to modify your model and change its predictions. Such an attack could be undetectable by customers or administrators.  

Machine learning models are also vulnerable to denial of service attacks. An attacker could send millions of fake requests for prediction results until your server runs out of space.

Data confidentiality and security

Ultimately, the security of your data is in the hands of the cloud service provider. You need to ensure you know the clauses and level of security in place.

If your data is stolen or hacked, you can take legal action against the service provider. However, there is no guarantee that you will be successful in recovering your data. In some cases, it might not be possible to recover all of your data from the cloud provider because they may have deleted or encrypted certain records due to regulatory requirements. It’s important that organizations understand their own risks and then find a service provider that can help minimize them.

benefits of Cloud Computing

Cloud service providers

There are few cloud computing platforms in the world today and fewer still that offer Machine Learning and Artificial Intelligence capabilities, these Cloud-based service are-

Amazon

Amazon Cloud Services

Amazon has a wide range of machine learning tools, including the popular open-source library Apache Mahout, which lets users produce free implementations of distributed or otherwise scalable machine learning algorithms. 

The library provides a large number of machine learning algorithms and makes it easy to incorporate them into your application. It also includes ,Amazon Augmented AI,natural language processing,Amazon Polly,deep learning frameworks.

In addition to providing access to libraries like these, Amazon offers several cloud services that can be used to build machine learning applications. These include:  

  • AWS (Amazon Web Services) Lambda: A serverless compute service that allows you to run code without provisioning or managing servers.
  • Amazon SageMaker: A managed service for building and deploying ML models in the cloud that are integrated with SageMaker’s machine learning platform.
  • Amazon Rekognition: An image analysis solution designed for video surveillance applications where accuracy is critical but latency must be kept low at all times.
  • EC2 (Elastic Compute Cloud): Provides scalable compute capacity in the cloud.
  • S3 (Simple Storage Service): Scalable storage service for data storage and retrieval.

Microsoft

Microsoft Azure Services — overview and notes | by Marco Bellinaso | Medium

Microsoft Azure Cloud services are a great way to rapidly deploy and scale machine learning services, whether you’re building something simpler like speech-to-text or a more complex computer vision solution.

Microsoft Azure offers a variety of machine learning services, including: 

  • Azure Machine Learning to build, train, and deploy machine learning
  • Azure Cognitive Search to detect content with vision and speech functions
  • Azure Cognitive Services to add cognitive capabilities to apps with APIs
  • Azure Virtual Machines: Provides on-demand, scalable computing resources.
  • Azure Blob Storage: Massively scalable object storage for unstructured data.

Google

Introduction to Google Cloud | Google Cloud Blog

Google Cloud AI Platform has built its reputation on delivering Infrastructure as a Service (IaaS). It is also an excellent choice for deploying machine learning models in the cloud. The Google Cloud ML Engine provides machine learning capabilities with easy access to data stored in BigQuery and other GCP databases.  It also includes Google Cloud Vision AI,Speech synthesis,foundation models,deep learning models,hybrid models and intelligent bot services and Vertex AI.

AutoML is Google Cloud’s machine learning service. It does not require extensive knowledge of machine learning. It includes AutoML Vision.

IBM

IBM Cloud isn’t the most popular option, but it has a strong set of tools for Machine Learning. The company offers its own OpenScale ML Platform to monitor payloads. IBM Watson Machine Learning provides Machine learning workloads via IBM Watson Studio.

Author

This article was written by Zohair Badshah, a former member of our software team, and edited by our writers team.

Latest Articles

All Articles
Mathematics in Machine Learning

Mathematics in Machine Learning

🚀 Unlock machine learning with essential math skills! 📊 Master linear algebra, calculus, and probability to boost your data science career! 💡

AI/ML
Machine Learning for Kids

Machine Learning for Kids

🚀 Spark your child’s creativity with fun machine learning projects! Prepare them for a tech-powered future. 💡👾

AI/ML
Machine Learning Project For Final Year

Machine Learning Project For Final Year

Looking for a final year project that stands out? 🚀 Explore cutting-edge machine learning ideas that will boost your skills and impress future employers!

AI/ML