Revolutionize Your Machine Learning Workflow with AutoML.

Jelal Sultanov
2 min readMar 7, 2023

The Power of Automated Machine Learning on Google Cloud

AutoML is a Google Cloud service that automates the entire machine learning workflow, from data preparation to model selection and tuning. It simplifies the process of building and deploying machine learning models, making it accessible to a wider audience, regardless of their machine learning expertise.

Advantages of AutoML over Other AWS Services

  1. Reduced Time and Cost: AutoML automates the entire machine learning workflow, saving significant amounts of time and cost compared to traditional machine learning methods that require significant manual effort.
  2. Increased Accuracy: AutoML uses advanced algorithms to automatically select the best model and hyperparameters for a given dataset, resulting in higher accuracy models compared to manual methods.
  3. Greater Accessibility: AutoML allows businesses and individuals with limited machine learning expertise to leverage machine learning technologies, making it more accessible to a wider audience.
  4. Scalability: AutoML can handle large datasets and complex machine learning workflows, making it suitable for enterprise-level applications.

Real Code Examples of Running MLOps in AutoML

To demonstrate the power and ease of use of AutoML, let’s look at some real code examples of running MLOps in AutoML using Google Cloud’s AutoML service.

First, we’ll import the necessary libraries and authenticate with Google Cloud:

from google.cloud import automl_v1beta1
from google.oauth2 import service_account

credentials = service_account.Credentials.from_service_account_file('path/to/credentials.json')
client = automl_v1beta1.AutoMlClient(credentials=credentials)
project_id = 'your-project-id'
location = 'us-central1'
model_id = 'your-model-id'

Next, we’ll load our data into a Pandas DataFrame and split it into training and validation sets:

import pandas as pd
from sklearn.model_selection import train_test_split

data = pd.read_csv('path/to/data.csv')
train_data, test_data = train_test_split(data, test_size=0.2, random_state=42)

We’ll then upload our training data to Google Cloud Storage:

from google.cloud import storage

bucket_name = 'your-bucket-name'
bucket = storage.Client().bucket(bucket_name)

blob_name = 'train.csv'
blob = bucket.blob(blob_name)
blob.upload_from_string(train_data.to_csv(index=False), 'text/csv')

We’ll create an AutoML dataset and import our training data:

dataset_name = 'your-dataset-name'
dataset_metadata = automl_v1beta1.types.DatasetMetadata()
dataset = client.create_dataset(project_id=project_id, location=location, dataset={'display_name': dataset_name, 'metadata': dataset_metadata})
dataset_id = dataset.name.split('/')[-1]

import_data_operation = client.import_data(dataset_id=dataset_id, input_config={'gcs_source': {'input_uris': ['gs://{}/{}'.format(bucket_name, blob_name)]}})
import_data_operation.result()

We’ll then train our AutoML model:

model_name = 'your-model-name'
model_metadata = automl_v1beta1.types.ModelMetadata()
training_budget = 1000

model = client.create_model(project_id=project_id, location=location, model={'display_name': model_name, 'dataset_id': dataset_id, 'metadata': model_metadata, 'training_budget_milli_node_hours': training_budget})
model_id = model.name.split('/')[-1]

operation = client.deploy_model(model_id=model_id)
operation.result()

Finally, we’ll make predictions using our AutoML model:

prediction_client = automl_v1beta1.PredictionServiceClient(credentials=credentials)

We’ll create a function to format our prediction request:

def get_prediction_request(instance):
payload = {
'instances': [{'csv': instance}]
}
request = prediction_client.predict(model_full_id, payload=payload)
return request

We’ll then make a prediction using our AutoML model:

model_full_id = client.model_path(project_id, location, model_id)

instance = 'example input data'
response = get_prediction_request(instance)

prediction = response.payload[0]
predicted_class = prediction.tables.scored_labels.labels[0]

In summary, AutoML is a powerful and user-friendly service that automates the machine learning workflow and simplifies the process of building and deploying machine learning models. By leveraging AutoML, businesses and individuals with limited machine learning expertise can benefit from machine learning technologies and achieve higher accuracy models with reduced time and cost.

--

--