We are excited to announce the launch of Amazon DocumentDB (with MongoDB compatibility) integration with Amazon SageMaker Canvas, allowing Amazon DocumentDB customers to build and use generative AI and machine learning (ML) solutions without writing code. Amazon DocumentDB is a fully managed native JSON document database that makes it straightforward and cost-effective to operate critical document workloads at virtually any scale without managing infrastructure. Amazon SageMaker Canvas is a no-code ML workspace offering ready-to-use models, including foundation models, and the ability to prepare data and build and deploy custom models.
In this post, we discuss how to bring data stored in Amazon DocumentDB into SageMaker Canvas and use that data to build ML models for predictive analytics. Without creating and maintaining data pipelines, you will be able to power ML models with your unstructured data stored in Amazon DocumentDB.
Solution overview
Let’s assume the role of a business analyst for a food delivery company. Your mobile app stores information about restaurants in Amazon DocumentDB because of its scalability and flexible schema capabilities. You want to gather insights on this data and build an ML model to predict how new restaurants will be rated, but find it challenging to perform analytics on unstructured data. You encounter bottlenecks because you need to rely on data engineering and data science teams to accomplish these goals. This new integration solves these problems by making it simple to bring Amazon DocumentDB data into SageMaker Canvas and immediately start preparing and analyzing data for ML. Additionally, SageMaker Canvas removes the dependency on ML expertise to build high-quality models and generate predictions.
We demonstrate how to use Amazon DocumentDB data to build ML models in SageMaker Canvas in the following steps:
1. Create an Amazon DocumentDB connector in SageMaker Canvas.
2. Analyze data using generative AI.
3. Prepare data for machine learning.
4. Build a model and generate predictions.
Prerequisites
To implement this solution, complete the following prerequisites:
1. Have AWS Cloud admin access with an AWS Identity and Access Management (IAM) user with permissions required to complete the integration.
2. Complete the environment setup using AWS CloudFormation through either of the following options:
a. Deploy a CloudFormation template into a new VPC – This option builds a new AWS environment that consists of the VPC, private subnets, security groups, IAM execution roles, Amazon Cloud9, required VPC endpoints, and SageMaker domain. It then deploys Amazon DocumentDB into this new VPC. Download the template or quick launch the CloudFormation stack by choosing Launch Stack.
b. Deploy a CloudFormation template into an existing VPC – This option creates the required VPC endpoints, IAM execution roles, and SageMaker domain in an existing VPC with private subnets. Download the template or quick launch the CloudFormation stack by choosing Launch Stack. Note that if you’re creating a new SageMaker domain, you must configure the domain to be in a private VPC without internet access to be able to add the connector to Amazon DocumentDB. To learn more, refer to Configure Amazon SageMaker Canvas in a VPC without internet access.
3. Follow the tutorial to load sample restaurant data into Amazon DocumentDB.
4. Add access to Amazon Bedrock and the Anthropic Claude model within it. For more information, see Add model access.
Create an Amazon DocumentDB connector in SageMaker Canvas
After you create your SageMaker domain, complete the following steps:
1. On the Amazon DocumentDB console, choose No-code machine learning in the navigation pane.
2. Under Choose a domain and profile¸ choose your SageMaker domain and user profile.
3. Choose Launch Canvas to launch SageMaker Canvas in a new tab. When SageMaker Canvas finishes loading, you will land on the Data flows tab.
4. Choose Create to create a new data flow.
5. Enter a name for your data flow and choose Create.
6. Add a new Amazon DocumentDB connection by choosing Import data, then choose Tabular for Dataset type.
7. On the Import data page, for Data Source, choose DocumentDB and Add Connection.
8. Enter a connection name such as demo and choose your desired Amazon DocumentDB cluster. Note that SageMaker Canvas will prepopulate the drop-down menu with clusters in the same VPC as your SageMaker domain.
9. Enter a user name, password, and database name. Finally, select your read preference. To protect the performance of primary instances, SageMaker Canvas defaults to Secondary, meaning that it will only read from secondary instances. When read preference is Secondary preferred, SageMaker Canvas reads from available secondary instances, but will read from the primary instance if a secondary instance is not available. For more information on how to configure an Amazon DocumentDB connection, see the Connect to a database stored in AWS.
10. Choose Add connection. If the connection is successful, you will see collections in your Amazon DocumentDB database shown as tables.
11. Drag your table of choice to the blank canvas. For this post, we add our restaurant data. The first 100 rows are displayed as a preview.
12. To start analyzing and preparing your data, choose Import data. Enter a dataset name and choose Import data.
Analyze data using generative AI
Next, we want to get some insights on our data and look for patterns. SageMaker Canvas provides a natural language interface to analyze and prepare data. When the Data tab loads, you can start chatting with your data by following these steps:
1. Choose Chat for data prep.
2. Gather insights about your data by asking questions like the samples shown in the following screenshots. To learn more about how to use natural language to explore and prepare data, refer to Use natural language to explore and prepare data with a new capability of Amazon SageMaker Canvas.
3. Let’s get a deeper sense of our data quality by using the SageMaker Canvas Data Quality and Insights Report, which automatically evaluates data quality and detects abnormalities.
4. On the Analyses tab, choose Data Quality and Insights Report.
5. Choose rating as the target column and Regression as the problem type, then choose Create. This will simulate model training and provide insights on how we can improve our data for machine learning.
6. The complete report is generated in a few minutes. Our report shows that 2.47% of rows in our target have missing values—we’ll address that in the next step. Additionally, the analysis shows that the address line 2, name, and type_of_food features have the most prediction power in our data. This indicates basic restaurant information like location and cuisine may have an outsized impact on ratings.
Prepare data for machine learning
SageMaker Canvas offers over 300 built-in transformations to prepare your imported data. For more information on transformation features of SageMaker Canvas, refer to Prepare data with advanced transformations. Let’s add some transformations to get our data ready for training an ML model. Follow these steps:
1. Navigate back to the Data flow page by choosing the name of your data flow at the top of the page.
2. Choose the plus sign next to Data types and choose Add transform.
3. Choose Add step. Let’s rename the address line 2 column to cities. Choose Manage columns.
4. Choose Rename column for Transform.
5. Choose address line 2 for Input column, enter cities for New name, and choose Add.
6. Additionally, let’s drop some unnecessary columns. Add a new transform.
7. For Transform, choose Drop column. For Columns to drop, choose URL and restaurant_id. Choose Add.
8. Our rating feature column has some missing values, so let’s fill in those rows with the average value of this column. Add a new transform.
9. For Transform, choose Impute. For Column type, choose Numeric. For Input columns, choose the rating column. For Imputing strategy, choose Mean. For Output column, enter rating_avg_filled. Choose Add.
10. We can drop the rating column because we have a new column with filled values. Because type_of_food is categorical in nature, we’ll want to numerically encode it. Let’s encode this feature using the one-hot encoding technique. Add a new transform.
11. For Transform, choose One-hot encode. For Input columns, choose type_of_food. For Invalid handling strategy, choose Keep. For Output style, choose Columns. For Output column, enter encoded. Choose Add.
Build a model and generate predictions
Now that we have transformed our data, let’s train a numeric ML model to predict the ratings for restaurants. Follow these steps:
1. Choose Create model.
2. For Dataset name, enter a name for the dataset export.
3. Choose Export and wait for the transformed data to be exported.
4. Choose the Create model link at the bottom left corner of the page. You can also select the dataset from the Data Wrangler feature on the…
Source link