In this article, we are going to create a Machine Learning model on AWS SageMaker using Amazon SageMaker Studio and Autopilot to predict house prices
1. Upload dataset to Amazon S3
First, we need to upload the dataset for house pricing. You can download the dataset for training and testing, here.
From the search bar in our AWS Management Console, search S3.
Create a bucket and upload the training dataset.
2. Setup SageMaker domain
Now, from the search bar, search for SageMaker Studio.
We must have a SageMaker domain, so create one. Click on Create a SageMaker domain.
Choose Quick setup and type a domain name.
Below the same page, you must specify a profile name and create an Execution role.
Select the before role created a click on Submit.
Once the domain and profile are created, you can launch SageMaker Studio.
3. Import the dataset on SageMaker and add some preprocessing steps
From SageMaker Studio, click on Data Wrangler from the left sidebar.
Click on Import data.
From Data sources, choose Amazon S3.
Select the bucket where you uploaded the dataset.
Select the dataset and then click on Import.
In the Data types * Transform section, we can add some steps for preprocessing. Click on + Add step.
In the search bar, type "remove col" and click on the first result.
Select Drop column in Transform and Id in Columns to drop. Then, click on Add.
Click on Export and train.
In the Training tab, click on Export and train.
4. Create an Autopilot experiment
Type an experiment name, toggle on Auto split data, and click on Next.
Select SalePrice as Target and the rest of the columns as Features. Then, click on Next.
Choose Auto and click on Next.
Type the endpoint name, select Regression as the problem type, and MSE as an objective metric. Then, click on Next.
Check if the configuration details are correct and click on Create experiment.
Now, wait until the experiment finishes. You can see the best trial at the top. In this case, the experiment made 100 trials.
In the Job profile tab, you can see how much time it took the experiment to finish. In this case, it took 46 minutes.
You can see the model details for the best trial. In the Trials tab, click on View model details. On this page, there is a chart about the feature importance.
5. Deploy ML model
Go back to the Trials tab, check the best model from the table, and click on Deploy model.
Choose Make real-time predictions and type the endpoint name. Then, click on Deploy
Now, wait until the endpoint is deployed. In this case, it took 19 minutes to finish the deployment.
6. Invoke deployed ML model
In the AWS Settings tab you can copy the deployed URL.
In order to invoke the URL, we need the Access Key and Secret Key. So, we can create a user and assign the AmazonSageMakerFullAccess permission policy. To do that, follow these steps:
- Go to IAM Management Console
- Users
- Click on Add Users
- Type de username
- In the Set permissions step, check Use a permissions boundary to control the maximum permissions and search AmazonSageMakerFullAccess in the permissions policies list
- Review the details for the user and click on Create user
Once the user is created, from the user's list, click on this user. Then, go to the Security credentials tab and create an access key. Copy the access key and secret key.
We're going to invoke the URL from Postman, but you can do it from other similar software as well.
Select POST as the HTTP method. In the Authorization tab, select AWS Signature as type. Then, paste the access key and secret key. Also, type sagemaker as Service Name.
In the Headers tab, change the Content-Type to text/csv.
In the Body tab, select raw and Text. Paste any record from the testing dataset. Don't forget to remove the id and sale price from the record. Now it's ready to invoke the URL.
NOTE: After this lab, if you want to delete the created endpoint, visit this page.
Thanks for reading
Thank you very much for reading, I hope you found this article interesting and may be useful in the future. If you have any questions or ideas that you need to discuss, it will be a pleasure to be able to collaborate and exchange knowledge together.