Build, train and deploy a machine learning model using Amazon Sagemaker

by Pronay Ghosh and Hiren Rupchandani

  • Taking machine learning models from concept to production is often difficult and time-consuming.
  • To train the model, one must first manage enormous amounts of data, then determine the optimal technique for training it.
  • After that, one must manage computing capacity while training it, and then deploy it into a production environment.
  • Amazon SageMaker simplifies the process of creating and deploying machine learning models.
  • SageMaker controls all of the underlying infrastructures to train your model at petabyte size and deploy it to production.
  • Here, in this article, we will learn more about Amazon Sagemaker.
  • We will learn how to create a SageMaker notebook instance.
  • Next, we will see how to prepare the data.
  • Then, we will train the model to learn from the data.
  • At last, we will Deploy our machine learning model.
  • The Bank Marketing Data Set will be used to train the model.

Steps to Build, train and Deploy a Machine Learning model into Amazon SageMaker

  • You build the notebook instance in this stage, which you’ll use to download and process your data.
  • You also build an Identity and Access Management (IAM) role that allows Amazon SageMaker to access data in Amazon S3 as part of the setup procedure.
  • Sign in to the Amazon SageMaker interface and choose your desired AWS Region in the top right corner.
  • Choose Notebook instances from the left navigation window, then Create notebook instance.
  • Fill in the following fields in the Notebook instance setting box on the Create notebook instance page:
  • Type <Name of the notebook> in the Notebook instance name field.
  • Choose ml.t2.medium as the Notebook instance type.
  • Keep the default selection -> none for elastic inference.
  • Choose to Create a new role in the Permissions and encryption section for the IAM role.
  • Then in the Create an IAM role dialogue box, pick Any S3 bucket and Create role.
  • Choose Open Jupyter after the status of your SageMaker notebook instance changes to InService.
  • Choose New in Jupyter, and then conda python3.
  • Copy and paste the following code into a new code cell in your Jupyter notebook, then pick Run.
  • To save your data, create an S3 bucket.
  • Choose Run after copying and pasting the following code into the next code box.
  • Load the data into a dataframe after downloading it to your SageMaker instance.
  • Choose Run after copying and pasting the above code into the next code box.
  • After that one can perform train test split with the help of the following command.

Keep Note that in Amazon Sagemaker one should do train test split with the help of np.split() method. The traditional train_test_split doesn’t work here. In order to learn more you can refer to the following block of code.

  • Copy and paste the following code into a new code cell in your Jupyter notebook, then pick Run.
  • Set up the Amazon SageMaker session, create an instance of the XGBoost model (an estimator), and define the model’s hyperparameters.
  • Copy and paste the above code into the next code cell and choose Run.
  • Start the training job.
  • Copy and paste the above code into a new code cell in your Jupyter notebook, then pick Run.
  • Copy the following code into the next code box and pick Run to forecast whether clients in the test data enrolled for the bank product or not.

Conclusion:

  • So far in this article, we covered a high-level overview of how to train, test and deploy a machine learning model using Amazon Sagemaker.
  • In the next article, we will learn about the basics of Amazon Augmented AI.

Follow us for more upcoming future articles related to Data Science, Machine Learning, and Artificial Intelligence.

Also, Do give us a Clapđź‘Ź if you find this article useful as your encouragement catalyzes inspiration for and helps to create more cool stuff like this.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
INSAID

INSAID

523 Followers

One of India’s leading institutions providing world-class Data Science & AI programs for working professionals with a mission to groom Data leaders of tomorrow!