AWS sagemaker






Why AWS SageMaker:


Imagine a scenario, where you run a website of house listings, your website acts as a platform where tenants search for the apartments available for rents and Owners would upload their house in listings.

And to make your website more unique, you could help the Owner could actually upload their listing in the website and if they had an option of how much rent they could expect in that particular area, and with particular amenities, let's take common use case as we know if owner has their house in city centre, they could expect more rent and we accept this with ease as it is common info we had that city centre rents were higher.

We had information prebuilt here and we could have an estimate around, city centre rents in Hyderabad would be 10,000INR , if it is Bengaluru,its around 13000INR and if its Vizag, its around 8000INR, all the data we have is something we had heard or seen somehwere, and if someone asks, if we often give a rough estimate and this rough estimate helps us plan things accordingly. If your an owner- the rent you could expect, Tenant- the rent you would pay.

AWS sage-maker works the similar way, it takes data, trains data and deploys model, let us understand it more clearly with a real-time project to make sense to the statements being specified here and how AWS sage-maker makes difference in lot dynamic businesses.
let us use similar business case and deploy a project in AWS sagemaker to understand how it helps in real time scenarios

Before we begin, also understand a simple concept of how AWS sagemaker works, it takes data from AWS S3, turn up an instance required to train Data, prepares model for it which we can use, uploads trained data and model into s3 bucket back, and turns off the instance.
 

Also Create notebook instance in this particular regions only where AWS sagemaker is available.




Search for AWS sagemaker AI





Navigate to Notebooks > Create Notebook Instance


also select role and also based on it



And here IAM role is important, you can create your Own role or use default role



the default role has access to s3 buckets as we need






now, leaving everything as default, click on "Create Notebook instance"


it takes few mins for our notebook instance to spin up


once instance is up, click on Open Jupyter (this is similar to Jupyter notebook)



click on New > Conda_python3



and now rename it to anything apart from untitled to avoid confusions




Now double click on it, it opens on separate browser, select conda_python3 as kernel




Now let us generate a random data, if you want to train existing data which you have, you can skip this step and upload your data directly to S3 Bucket

import pandas as pd

data = {

    "Area": [

        "City Centre",

        "City Centre",

        "City Centre",

        "City Centre",

        "City Centre"

    ],



    "Size_sqft": [

        450,

        600,

        700,

        850,

        1000

    ],



    "Bedrooms": [

        1,

        1,

        2,

        2,

        3

    ],



    "Bathrooms": [

        1,

        1,

        2,

        2,

        2

    ],



    "Furnished": [

        "Yes",

        "Yes",

        "No",

        "Yes",

        "Yes"

    ],



    "BillsIncluded": [

        "Yes",

        "No",

        "No",

        "Yes",

        "Yes"

    ],



    "Balcony": [

        "No",

        "Yes",

        "Yes",

        "Yes",

        "Yes"

    ],



    "DistanceToMetro_min": [

        2,

        5,

        4,

        3,

        1

    ],



    "MonthlyRent": [

        1100,

        1300,

        1450,

        1750,

        2200

    ]

}

df = pd.DataFrame(data)
df


click on ">" play button to execute the cell



once executed, you get the data in tabular format.



Now, lets save this generated file into CSV file so that we can upload to s3 bucket

df.to_csv("city_centre_rent.csv", index=False)




you will be able to find the generated CSV file in the same path 


Points to remember if you are using Jupyter notebook for first time.

Each code placed is placed inside the cell, and play button is run, once the code gets into next block, it means your code executed without errors, also if there are any files generated, you can always find it in home tab. always remember to rename untitled files as jupyter notebook opens each file in different tabs, naming files can avoid potential confusions.

Now we would use sagemaker here, because of the role we attached to instance, it would be able to create s3 buckets for us and store data 


import sagemaker

session = sagemaker.Session()

SAGEMAKER_SUPPRESS_V2_WARNING=1

bucket = session.default_bucket()

print(bucket)
this train and test helps our model to check on the accuracy, for example we have values around
5 building and now 4th building value is taken as test, Model uses values of 1,2,3 and 5, trains the data and tries to predict rent of 4th building, once it predicted than compares with actual rent value of 4th building

Comments