<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Joshua Oladokun</title>
    <description>The latest articles on DEV Community by Joshua Oladokun (@timiredmind).</description>
    <link>https://dev.to/timiredmind</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F740988%2F5c4cabfb-8899-4f41-bf25-af2fe001ac43.jpeg</url>
      <title>DEV Community: Joshua Oladokun</title>
      <link>https://dev.to/timiredmind</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/timiredmind"/>
    <language>en</language>
    <item>
      <title>Building a Recommender System with Flask and AWS Personalize (Part 2): Setting Up Amazon Personalize</title>
      <dc:creator>Joshua Oladokun</dc:creator>
      <pubDate>Wed, 11 May 2022 15:11:23 +0000</pubDate>
      <link>https://dev.to/timiredmind/building-a-recommender-system-with-flask-and-aws-personalize-part-2-setting-up-amazon-personalize-3mgn</link>
      <guid>https://dev.to/timiredmind/building-a-recommender-system-with-flask-and-aws-personalize-part-2-setting-up-amazon-personalize-3mgn</guid>
      <description>&lt;p&gt;In the previous part of this series, we learnt what a recommender system is. We also learnt about some use cases of a recommender system, and how Amazon Personalize works. Here, we would be going through the steps required to set up Amazon Personalize.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting Up Amazon Personalize
&lt;/h2&gt;

&lt;p&gt;To get started with Amazon Personalize, you need to have an Amazon Web Service (AWS) account. In case, you don't have an account, follow the instructions &lt;a href="https://docs.aws.amazon.com/personalize/latest/dg/setup.html#aws-personalize-set-up-aws-account"&gt;here&lt;/a&gt; to create an account. &lt;/p&gt;

&lt;p&gt;Now that you've created your AWS account, you need to create an AWS Identity and Access Management (IAM) admin user. An IAM user is an entity created to represent a person or application interacting with an AWS. An IAM user with administrative permission has unrestricted access to AWS services in your account. To create an IAM user, follow the set of instructions &lt;a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/getting-started_create-admin-group.html"&gt;here&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Before we can use Amazon Personalize, you have to set up permissions that allow your IAM user access to Amazon Personalize Console and API operations. To set up the IAM user policy, follow the instructions &lt;a href="https://docs.aws.amazon.com/personalize/latest/dg/aws-personalize-set-up-permissions.html#set-up-required-permissions"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You now have to create an IAM role for Amazon Personalize. An IAM role is an IAM identity that you create in your account that has specific permissions. An IAM role is similar to an IAM user, in that it is an AWS identity with permission policies that determine what the identity can and cannot do in AWS. However, an IAM role is not uniquely associated with one person, a role is intended to be assumable by anyone who needs it. To create the IAM Role, follow the instructions &lt;a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-service.html"&gt;here&lt;/a&gt;.&lt;br&gt;
Use these configurations while creating the IAM Role:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For &lt;strong&gt;Choose the service that will use this role&lt;/strong&gt;, choose &lt;code&gt;Personalize&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;For &lt;strong&gt;Attach permissions policies&lt;/strong&gt;, either choose the IAM user policy you created previously, or choose &lt;code&gt;AmazonPersonalizeFullAccess&lt;/code&gt; from the list of Amazon-managed policies.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After creating the IAM role for Amazon Personalize, you have to prepare your training data and upload it to Amazon S3. We would be using a Custom dataset group. Download the user-interactions file &lt;a href="https://drive.google.com/file/d/1xq78NlKjkhnPafeeLjoAseG0JUJBAW87/view?usp=sharing"&gt;here&lt;/a&gt;. &lt;br&gt;
You would have to format the &lt;code&gt;user_interaction.csv&lt;/code&gt; so that Amazon Personalize can understand the data. We have to change the header rows from &lt;code&gt;user_id&lt;/code&gt;, &lt;code&gt;movie_id&lt;/code&gt;and &lt;code&gt;timestamp&lt;/code&gt; to &lt;code&gt;USER_ID&lt;/code&gt;, &lt;code&gt;ITEM_ID&lt;/code&gt;, and &lt;code&gt;TIMESTAMP&lt;/code&gt;. You can manually enter it with an Excel file or use the Python Pandas package. &lt;br&gt;
Follow these steps to change the header row using pandas&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import pandas as pd
# Read user_interactions.csv into a Pandas Dataframe
df = pd.read_csv("user_interactions.csv", encoding='latin-1')
#Rename column name
df = df.rename(columns={"user_Id":"USER_ID","movie_Id": "ITEM_ID","timestamp": "TIMESTAMP"})
#Save dataframe into a new CSV file named interactions.csv
df.to_csv("interactions.csv", index=False)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We would have to upload our &lt;code&gt;interaction.csv&lt;/code&gt; file into an AWS S3 bucket. To create an S3 bucket and upload files to it follow the set of instructions &lt;a href="https://docs.aws.amazon.com/redshift/latest/dg/tutorial-loading-data-upload-files.html"&gt;here&lt;/a&gt;. &lt;br&gt;
For Region, choose &lt;code&gt;US West (Oregon) us-west-2&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;After uploading your file to Amazon S3, you have to set up permission that allows Amazon Personalize to access the Amazon S3 bucket. We would be doing two things to set up the permission:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Attaching an Amazon S3 policy to your Amazon Personalize service role.&lt;/li&gt;
&lt;li&gt;Attaching an Amazon Personalize access policy to your Amazon S3 bucket. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To attach an Amazon S3 policy to your Amazon Personalize service role, do the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sign in to the &lt;a href="https://console.aws.amazon.com/iam/"&gt;IAM console&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;In the navigation pane, choose Policies, and choose &lt;strong&gt;Create Policy&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Choose the JSON tab, and update the policy as follows. Replace the bucket name with the name of your S3 bucket.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "Version": "2012-10-17",
    "Id": "PersonalizeS3BucketAccessPolicy",
    "Statement": [
        {
            "Sid": "PersonalizeS3BucketAccessPolicy",
            "Effect": "Allow",
            "Action": [
                "s3:GetObject",
                "s3:ListBucket"
            ],
            "Resource": [
                "arn:aws:s3:::bucket-name",
                "arn:aws:s3:::bucket-name/*"
            ]
        }
    ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Choose Next: Tags. Optionally add any tags and choose Review.&lt;/li&gt;
&lt;li&gt;Give the policy a name.&lt;/li&gt;
&lt;li&gt;For &lt;strong&gt;Description&lt;/strong&gt;, enter a short sentence describing this policy, for example, &lt;code&gt;Allow Amazon Personalize to access its Amazon S3 bucket&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Choose the &lt;strong&gt;Create Policy&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;In the navigation pane, choose Roles, and choose the role you created for Amazon Personalize.&lt;/li&gt;
&lt;li&gt;For Permissions, choose &lt;strong&gt;Attach Policies&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;To display the policy in the list, type part of the policy name in the &lt;strong&gt;Filter policies&lt;/strong&gt; filter box.&lt;/li&gt;
&lt;li&gt;Choose the check box next to the policy you created earlier in this procedure.&lt;/li&gt;
&lt;li&gt;Choose &lt;strong&gt;Attach policy&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now you have to attach a bucket policy to the Amazon S3 bucket containing your data. This permission allows Amazon Personalize access to the S3 bucket. &lt;/p&gt;

&lt;p&gt;To create a bucket policy:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In the &lt;strong&gt;Buckets&lt;/strong&gt; list, choose the name of the bucket that you want to create a bucket policy.&lt;/li&gt;
&lt;li&gt;Choose &lt;strong&gt;Permissions&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Under &lt;strong&gt;Bucket Policy&lt;/strong&gt;, choose &lt;strong&gt;Edit&lt;/strong&gt;. This opens the Edit bucket policy page.&lt;/li&gt;
&lt;li&gt;On the &lt;strong&gt;Edit bucket policy&lt;/strong&gt; page, replace the JSON in the &lt;strong&gt;Policy&lt;/strong&gt; section, with the following:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "Version": "2012-10-17",
    "Id": "PersonalizeS3BucketAccessPolicy",
    "Statement": [
        {
            "Sid": "PersonalizeS3BucketAccessPolicy",
            "Effect": "Allow",
            "Principal": {
                "Service": "personalize.amazonaws.com"
            },
            "Action": [
                "s3:GetObject",
                "s3:ListBucket"
            ],
            "Resource": [
                "arn:aws:s3:::bucket-name",
                "arn:aws:s3:::bucket-name/*"
            ]
        }
    ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;bucket-name&lt;/code&gt; with the name of the S3 bucket.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Choose the &lt;strong&gt;Save Changes&lt;/strong&gt; to save the policy.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Before starting with Amazon Personalize, you have to determine your use case. Determining your use case will help identify what recipe would be used to train our model. &lt;strong&gt;Recipes&lt;/strong&gt; are Amazon Personalize algorithms that are prepared for specific use cases. &lt;br&gt;
The available use cases for Amazon Personalize include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Recommending items for users using the &lt;code&gt;USER_PERSONALIZATION&lt;/code&gt; recipe.&lt;/li&gt;
&lt;li&gt;Ranking items for a user using the &lt;code&gt;PERSONALIZED_RANKING&lt;/code&gt; recipe.&lt;/li&gt;
&lt;li&gt;Recommending similar items using the &lt;code&gt;RELATED_ITEMS&lt;/code&gt; recipe.&lt;/li&gt;
&lt;li&gt;Getting user segments using the &lt;code&gt;USER_SEGMENTATION&lt;/code&gt; recipes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Our use cases are for recommending items to users and recommending similar items. To start with Amazon Personalize, we have to create a Custom Dataset group, to do this follow the set of instructions &lt;a href="https://docs.aws.amazon.com/personalize/latest/dg/data-prep-ds-group.html#data-prep-creating-ds-group-console"&gt;here&lt;/a&gt;. &lt;br&gt;
After creating a new Dataset group, you would be directed to the &lt;strong&gt;Create interactions dataset&lt;/strong&gt; page. Follow the following steps to create an interaction dataset and schema:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Specify a name for the dataset group.&lt;/li&gt;
&lt;li&gt;Choose &lt;strong&gt;Create new schema&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Enter a name to distinguish our schema.&lt;/li&gt;
&lt;li&gt;Paste the schema JSON in the &lt;strong&gt;Schema definition&lt;/strong&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "type": "record",
  "name": "Interactions",
  "namespace": "com.amazonaws.personalize.schema",
  "fields": [
    {
      "name": "USER_ID",
      "type": "string"
    },
    {
      "name": "ITEM_ID",
      "type": "string"
    },
    {
      "name": "TIMESTAMP",
      "type": "long"
    }
  ],
  "version": "1.0"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Choose &lt;strong&gt;Create dataset and continue&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Next, we have to import our interaction data into Amazon Personalize from Amazon S3. To do these, we would have to create an import job. Follow the steps &lt;a href="https://docs.aws.amazon.com/personalize/latest/dg/bulk-data-import-step.html#bulk-data-import-console"&gt;here&lt;/a&gt; to create a data import job.&lt;br&gt;
After creating the dataset import job, you will be redirected to the &lt;strong&gt;Dashboard Overview&lt;/strong&gt; page. &lt;/p&gt;

&lt;p&gt;On the create dataset row, you would see the Interaction data would have Pending status. Amazon Personalize would take about   5-15 mins to create the Interaction dataset.&lt;br&gt;
While we wait for Amazon Personalize to create the Interaction dataset, we would import the Item dataset. Before we import our Item dataset into Personalize, we need to have our Item metadata. You can download the Item metadata file we would be using in this tutorial &lt;a href="https://drive.google.com/file/d/18Pl7xzIp4_NkMOG27yyJURRzCEb_vr_j/view?usp=sharing"&gt;here&lt;/a&gt;. Click &lt;a href="https://docs.aws.amazon.com/personalize/latest/dg/item-dataset-requirements.html#schema-examples-items"&gt;here&lt;/a&gt;, to learn more about creating an Item dataset. &lt;br&gt;
After downloading our Item metadata we have to upload the file to our previously Amazon S3 bucket. To upload the Item metadata to S3:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open the Amazon S3 console.&lt;/li&gt;
&lt;li&gt;In the &lt;strong&gt;Buckets&lt;/strong&gt;  list, choose the bucket's name to which you want to upload your files to.&lt;/li&gt;
&lt;li&gt;Choose &lt;strong&gt;Upload&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;In the Upload window, drag and drop the item metadata file to the Upload window.&lt;/li&gt;
&lt;li&gt;Choose &lt;strong&gt;Upload&lt;/strong&gt; at the bottom of the page to upload the file to our Amazon S3 bucket.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To import our Item dataset into Amazon Personalize;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Select the &lt;strong&gt;Import Item data ** on the **Overview Dashboard&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Enter a dataset name of your choice that will be easily distinguishable.&lt;/li&gt;
&lt;li&gt;Select &lt;strong&gt;Create new Schema&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Enter the following JSON schema, in the Schema Definition.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "type": "record",
    "name": "Items",
    "namespace": "com.amazonaws.personalize.schema",
    "fitelds": [
        {
            "name": "ITEM_ID",
            "type": "string"
        },
        {
            "name": "YEAR_RELEASED",
            "type": "int"
        },
        {
            "name": "GENRE",
            "type": "string",
            "categorical": true
        },
        {
            "name": "ACTORS",
            "type": "string",
            "categorical": true
        },
        {
            "name": "DIRECTOR",
            "type": "string"
        }
    ],
    "version": "1.0"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Choose &lt;strong&gt;Next&lt;/strong&gt;, you would be directed to the &lt;strong&gt;Configure dataset import job&lt;/strong&gt; page.&lt;br&gt;
Enter the dataset import job name the &lt;strong&gt;Configure dataset import job&lt;/strong&gt; page. The dataset import job name must be between 1-63 characters and shouldn't contain space.&lt;/p&gt;

&lt;p&gt;Enter the S3 location of your data. If you don't know the location of the file in the S3 bucket, go to the file location in the S3 console. Check the box of the file and choose the &lt;strong&gt;Copy S3 URI&lt;/strong&gt;. &lt;br&gt;
Paste the S3 URI into the S3 location box on the &lt;strong&gt;Configure Dataset import job&lt;/strong&gt; page.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;IAM Role&lt;/strong&gt; section, choose &lt;strong&gt;Enter a custom IAM Role ARN&lt;/strong&gt;. You have to enter the ARN of the IAM Role previously created. To get the ARN, go to the IAM console. Choose &lt;strong&gt;Role&lt;/strong&gt; and choose the IAM role created earlier. On the IAM Role page, you would see ARN. Copy the ARN and paste it into the IAM Role ARN on the &lt;strong&gt;Configure dataset import job&lt;/strong&gt;. Choose &lt;strong&gt;Start Import&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;After importing data, we have to create a Solution. A Solution is a combination of Amazon Personalize recipe, customized parameters, and one or more solution versions (trained models) that Amazon Personalize uses to generate recommendations. Amazon Personalize provides recipes based on common use cases, for training models. Recipes are Amazon Personalize algorithms that are prepared for specific use cases. You can read more about Amazon Personalize recipes, &lt;a href="https://docs.aws.amazon.com/personalize/latest/dg/working-with-predefined-recipes.html"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To create the Solution we would be using, head over to the Amazon Personalize &lt;strong&gt;Overview&lt;/strong&gt; page, and choose &lt;strong&gt;Create Solution&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;On the &lt;strong&gt;Create Solution&lt;/strong&gt; page. Enter a name for the solution. The solution name must have 1-63 characters with no spaces. (Valid characters: a-z, A-Z, 0-9, and _). &lt;/p&gt;

&lt;p&gt;For Solution type, choose &lt;strong&gt;Item recommendation&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;For &lt;strong&gt;Recipe&lt;/strong&gt;,  select  &lt;code&gt;aws-similar-items&lt;/code&gt;. The &lt;code&gt;aws-similar-items&lt;/code&gt; or Similar-Items recipe generates recommendations for items that are similar to an item you specify.&lt;/p&gt;

&lt;p&gt;Select &lt;code&gt;Create and train solutions&lt;/code&gt;. You would then be redirected to the &lt;strong&gt;Overview&lt;/strong&gt; page.&lt;/p&gt;

&lt;p&gt;After preparing and importing our data and creating our solutions, we are ready to deploy our solution version to generate recommendations in real-time. A solution version is a trained model that is created as part of a solution in Amazon Personalize.  We can deploy our solution version by creating an Amazon Personalize campaign. A campaign is a deployed solution version (trained model) with provisioned dedicated transaction capacity for creating real-time recommendations for your application users. After you create a campaign, you use the &lt;code&gt;GetRecommendations&lt;/code&gt; or &lt;code&gt;GetPersonalizedRanking&lt;/code&gt; API operations to get recommendations.&lt;/p&gt;

&lt;p&gt;Follow the instructions, &lt;a href="https://docs.aws.amazon.com/personalize/latest/dg/campaigns.html#create-campaign-console"&gt;here&lt;/a&gt; to create a campaign. This campaign will be used to get recommendations of items similar to a selected item.&lt;br&gt;
In the next part of this series, we would creating a movie API and integrating Amazon Personalize into our API.&lt;/p&gt;

</description>
      <category>flask</category>
      <category>restapi</category>
      <category>aws</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Building a Recommender System with Flask and Amazon Personalize. (Part 1): Introduction</title>
      <dc:creator>Joshua Oladokun</dc:creator>
      <pubDate>Fri, 29 Apr 2022 14:48:17 +0000</pubDate>
      <link>https://dev.to/timiredmind/building-a-recommender-system-with-flask-and-amazon-personalize-part-1-3ab0</link>
      <guid>https://dev.to/timiredmind/building-a-recommender-system-with-flask-and-amazon-personalize-part-1-3ab0</guid>
      <description>&lt;p&gt;Have you ever used a website, and gotten a recommendation for similar videos or items when viewing an item? Have you ever visited a site homepage, and gotten item recommendations based on your search history. What is responsible for this is a recommendation system.&lt;/p&gt;

&lt;p&gt;A recommender system is a system designed to recommend items to users based on different factors. These factors vary from user's interactions (behavior and preferences) to user's metadata (age, location, gender) to item's metadata. Companies like YouTube, Netflix, Spotify, and Amazon use recommender systems to improve users' experience on their websites.&lt;/p&gt;

&lt;p&gt;Common use cases of recommender systems include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;recommendation of similar products on the product detail page.&lt;/li&gt;
&lt;li&gt;personalized re-ranking of products for users.&lt;/li&gt;
&lt;li&gt;personalized push notifications and marketing email.&lt;/li&gt;
&lt;li&gt;recommend products based on user's interaction history on user's home page.&lt;/li&gt;
&lt;li&gt;recommend relevant new products to users.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this tutorial series, you would be using Amazon Personalize and Flask to create a recommender system. Amazon Personalize is a machine learning service managed by Amazon, that makes it easy for developers to deliver personalized experiences to users.&lt;br&gt;
Flask is a Python microframework used for creating web applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  How does Amazon Personalize Work
&lt;/h2&gt;

&lt;p&gt;In Amazon Personalize, you start by creating a dataset group. A dataset group is a container for storing Amazon Personalize components such as datasets, event trackers, solutions, filters, and campaigns. A dataset group helps organize resources into an independent collection, to prevent resources from one dataset group from interfering with another dataset group. There are two types of dataset groups:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Domain dataset group&lt;/li&gt;
&lt;li&gt;Custom dataset group&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A Domain dataset group is a dataset group consisting of pre-configured resources for different business use cases. There are 2 pre-configured business domain groups in Amazon Personalize:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;ECOMMERCE&lt;/code&gt; domain: for getting recommendations for best-selling products on an e-commerce application.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;VIDEO_ON_DEMAND&lt;/code&gt; domain: for getting similar video recommendations.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With Domain dataset groups, Amazon Personalize manages the life cycle of training models and deployment. When you create a Domain dataset group, you choose your business domain, import your data, and create &lt;code&gt;recommenders&lt;/code&gt; for each of your use cases. You use your &lt;code&gt;recommender&lt;/code&gt; in your application to get recommendations with the &lt;code&gt;GetRecommendations&lt;/code&gt; operation. If you start with a Domain dataset group, you can add custom resources later during the lifecycle of the model. Use a Domain dataset group if you have a video on demand or e-commerce application and want Amazon Personalize to find the best configurations for your use cases.&lt;/p&gt;

&lt;p&gt;A Custom dataset group is a dataset group containing custom resources such as solutions, solution versions, filters, and campaigns. When creating a Custom dataset group, you determine your use case, import data, train a model and deploy a campaign. You use the campaign in your application to get recommendations with the &lt;code&gt;GetRecommendation&lt;/code&gt; operation. A Custom dataset group is used if you want to configure and manage only custom resources or want to get recommendations in a batch workflow. The developer is responsible for managing the lifecycle of training models and deployment. If you start with a Custom dataset group, you cannot add a domain resource later. &lt;/p&gt;

&lt;p&gt;After choosing the dataset group, we would import data into a dataset. A dataset is a container for storing data imported into Amazon Personalize. There is 3 type of datasets in Amazon Personalize: Users, Interactions, and Items. The Items dataset is the only required dataset to create the recommender, with the other two datasets being optional.&lt;/p&gt;

&lt;p&gt;Amazon Personalize creates a recommender or a solution depending on the dataset group you are using. It creates and deploys a customized API for getting recommendations in real-time and a batch workflow for getting recommendations in batch.&lt;br&gt;
In the next series, we will be going through steps to set up Amazon Personalize.&lt;/p&gt;

</description>
      <category>flask</category>
      <category>aws</category>
      <category>restapi</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Creating A Flask REST API (Part 1):Setting Up a Basic Flask App</title>
      <dc:creator>Joshua Oladokun</dc:creator>
      <pubDate>Tue, 22 Feb 2022 16:08:23 +0000</pubDate>
      <link>https://dev.to/timiredmind/creating-a-flask-rest-api-3ga4</link>
      <guid>https://dev.to/timiredmind/creating-a-flask-rest-api-3ga4</guid>
      <description>&lt;p&gt;In this tutorial, we would be learning how to create a REST API using Flask. For those who might not know what REST is, REST is an acronym for &lt;strong&gt;REpresentational State Transfer&lt;/strong&gt;. REST is an architectural style for providing standards between computer systems on the web, making it easier for systems to communicate with each other. Like other architectural styles, &lt;a href="https://restfulapi.net/" rel="noopener noreferrer"&gt;REST has its guiding principles and constraints&lt;/a&gt;. &lt;br&gt;
API is an acronym for Application Programming Interface, it is a set of defined rules that explain how computers or application communicate with each other. APIs provides means for different entity of code (which may always not be written in the same language), to communicate with each other without any need to understand how they both go about carrying out their operations. APIs that comply with REST architectural style guidelines and constraints are called RESTful APIs.&lt;br&gt;
Creating our RESTful APIs in this tutorial, we would be using Flask framework. Flask is a Python web application microframework. The "micro" in framework does not mean that your entire web application has to fit into a single Python file (although it certainly can), nor does it mean that Flask is lacking in functionality. The “micro” in microframework means Flask aims to keep the core simple but extensible. Flask won’t make many decisions for you, such as what database to use. Those decisions that it does make, such as what templating engine to use, are easy to change. Everything else is up to you, so that Flask can be everything you need and nothing you don’t.&lt;/p&gt;

&lt;p&gt;Some of the extension we would use in this tutorial includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://flask-restful.readthedocs.io/en/latest/" rel="noopener noreferrer"&gt;flask-restful&lt;/a&gt; - extension for building RESTful APIs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://flask-sqlalchemy.palletsprojects.com/en/2.x/" rel="noopener noreferrer"&gt;flask-sqlalchemy&lt;/a&gt; - extension that adds support for SQLAlchemy (Python's ORM)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://flask-migrate.readthedocs.io/" rel="noopener noreferrer"&gt;flask-migrate&lt;/a&gt; - extension that adds handles SQLAlchemy database migration.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://flask-jwt-extended.readthedocs.io/en/stable/" rel="noopener noreferrer"&gt;flask-jwt-extended&lt;/a&gt; - extension that handles authentication and authorization of users.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this tutorial we would be building a catalogue API where the users can search for books, borrow available books and return borrowed book, search for books based on genre, authors and publishers. Users would be able to carry out CRUD operations (i.e create, read, update and delete) on their profiles. Our application would have an admin user who can carry out CRUD operation on the library database (i.e the admin user would be able to create, read, update and delete books from our library database).&lt;/p&gt;

&lt;p&gt;To begin our project we would create a directory called catalogue_api, then change our working directory to the catalogue_api directory. This is done by entering the command in our command line;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir catalogue_api
cd catalogue_api
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The next thing to do is create a virtual environment in our library_api directory for our project. A virtual environment is an isolated Python environment where a project's dependencies are installed in a different directory from those installed in the system's default Python path and other virtual environments. In order to create our virtual environment we would run the &lt;code&gt;venv&lt;/code&gt; module as a script with the directory path.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python3 -m venv venv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This would create a &lt;code&gt;venv&lt;/code&gt; directory if it doesn't exist before, and also create directories inside it containing a copy of the Python interpreter and various supporting files. Next we have to activate the virtual environment.&lt;br&gt;
On Windows, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;venv\Scripts\activate.bat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On Mac, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;source venv/bin/activate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we install flask into our virtual environment using pip. We use the pip command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install flask
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We create an &lt;code&gt;app.py&lt;/code&gt; file in our current working directory were we would create our first Flask Hello World app. Enter the following code into the &lt;code&gt;app.py&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from flask import Flask

app = Flask(__name__)

@app.route("/")
def index():
    return "Hello World"

if __name__ == "__main__":
   app.run()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the code above, first we import the Flask class from the flask package. Next we create an instance of the Flask class that take in the &lt;code&gt;__name__&lt;/code&gt; as its only argument, Flask uses the &lt;code&gt;__name__&lt;/code&gt; argument to find  templates and static files. Then we make use of a built-in route decorator to register the root URL "/" to the index function. The &lt;code&gt;@app.route&lt;/code&gt; decorator is used to register a URL to a view function. A view function is simply a function that handles client's request, and values returned are known as &lt;em&gt;response&lt;/em&gt;. Whenever a request is sent to the root URL "/" endpoint, the index function is automatically called to handle the request.&lt;br&gt;
The &lt;code&gt;app.run()&lt;/code&gt; function is used to run the Flask application on a local development server.&lt;/p&gt;

&lt;p&gt;To run the our Flask application, we enter the following code in the terminal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python app.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output looks like this:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft9rap318q268xwxp1ez8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft9rap318q268xwxp1ez8.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can see our app is running on &lt;code&gt;http://127.0.0.1:5000/&lt;/code&gt;. If we enter the URL into any browser of our choice. We would get a response looking like this :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fps0o5eiqbifhxq3r3lnx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fps0o5eiqbifhxq3r3lnx.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
This shows that our app is running well.&lt;br&gt;
But we can see that there is a warning when running our server that says &lt;code&gt;this is a development server and shouldn't be run in a production deployment.&lt;/code&gt; The reason for this warning is because Flask thinks we are running our app in a production environment on a development server. To remove the warning we have to let Flask know we are running our app in a development environment, to do this we have to create a new file called &lt;code&gt;.flaskenv&lt;/code&gt; in our &lt;code&gt;catalogue_api&lt;/code&gt; directory. Enter the following code into the &lt;code&gt;.flaskenv&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FLASK_APP = app.py
FLASK_ENV = development
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;.flaskenv&lt;/code&gt; file is used to store Flask specific configurations. In the first line, we tell Flask to check the &lt;code&gt;app.py&lt;/code&gt; file to run our application, and in the second line we set our environment to a development environment. In order for Python to read our &lt;code&gt;.flaskenv&lt;/code&gt; file we would need to install a Python library &lt;code&gt;python-dotenv&lt;/code&gt;. To install the library into our virtual environment, we enter the following code into our terminal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install python-dotenv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The library reads information  from &lt;code&gt;.env&lt;/code&gt; files or &lt;code&gt;.flaskenv&lt;/code&gt; as key-value pairs. To run our flask app we write the following code into the terminal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flask run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output will look like this&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fplqw02duupbp07ac1jnu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fplqw02duupbp07ac1jnu.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
We haves successfully set up our Flask app in a the development environment. In the next tutorial we would be looking at creating models and persisting data into our database using Flask-SQLAlchemy, Flask_Migrate and Postgres.&lt;/p&gt;

</description>
      <category>python</category>
      <category>flask</category>
      <category>api</category>
      <category>rest</category>
    </item>
  </channel>
</rss>
