Build recommendation engine with Amazon Machine Learning in Cloud9
Overview
Machine learning is a way to achieve artificial intelligence, using large amounts of data to train computers to learn a set of rules. We can use historical data to predict specific future data. Machine learning can be divided into two categories: Supervised Learning , Unsupervised Learning and Reinforcement Learning, while supervised learning infers a function from labeled training data consisting of a set of training examples, like Classification and Regression, while unsupervised learning learns from test data that has not been labeled, commonly used in Clustering and Dimensionality Reduct. Building machine learning models requires steps such as data cleanup, feature extraction, model selection, and often time-consuming.
Amazon Machine Learning provides visualization tools and wizards that guide you through the process of creating machine learning (ML) models without having to learn complex ML algorithms and technology. Once your models are ready, Amazon Machine Learning makes it easy to obtain predictions for your application using simple APIs, without having to implement custom prediction generation code or manage any infrastructure.
Scenario
In this lab, you will build a smart solution using Amazon S3, Amazon Machine Learning and Amazon Cloud9 that predict rental bikes for Capital bike-share system. The dataset contains the daily amount of rental bikes between the years 2011 and 2012 in the Capital bike-share system with the corresponding weather and seasonal information. You will learn how to use S3 to save data and predict using Machine Learning to create a model that will predict the rental bikes.
Step by Step
Frist, we need to create a bucket to store rental bikes data. Following the steps and you will create a bucket.
-
On the service menu, click S3, Click Create Bucket .
-
For Bucket Name, type Unique Name.
-
For Region, choose US East (N. Virginia), Click Create.
-
Select the bucket which you created before, Click Upload, Click Add files.
-
Select the bike.csv file, then choose Click Start Upload.
Create Model using Amazon Machine Learning
Create a model for the number of bicycle rentals, and use S3 as the data source, we will use season, month, weekday, working day, weather sit as feature, and cnt is target label. At last, we will create real-time predictions endpoint to get a real-time result.
-
On the service menu, click Machine Learning, click Get Started and Launch.
-
For Where is your data, choose S3.
-
For S3 location, choose the s3
bucket name/file
which you created. -
For Datasource name, type
ml‐data
, Click Verify.
- For S3 permissions, click yes.
Note: You will see ‘The validation is successful. To go to the next step, choose Continue’
-
In Schema part:
- About the first line in the column name, click yes when you see the question: Does the first line in your CSV contain the column names?
- For Datatype, choose season/mnth/weekday/workingday/weathersit as Categorical, and cnt as Numetric.
-
In Target part, choose cnt as target for prediction.
-
In Row ID ,Review ,ML model settings part, use the default settings and click Review.
-
In Review part,
- Click Create ML Model.
- Wait for Amazon ML reports the status as Completed and note your model ID.
-
In Predictions section, click Create endpoint to enable real-time predictions. For Create a real-time endpoint dialog, click Create.
-
Note your real-time prediction Endpoint Url.
Test Model in Web page using Cloud9
We will use AWS Cloud9 services to develop our web page. The web use AWS SDK for PHP to integrate Amazon Machine Learning in our application and build real-time predictions.
AWS Cloud9 is a cloud-based integrated development environment (IDE) that lets you write, run, and debug your code with just a browser. It includes a code editor, debugger, and terminal. Cloud9 comes prepackaged with essential tools for popular programming languages, including JavaScript, Python, PHP, and more, so you don’t need to install files or configure your development machine to start new projects. – On the service menu, click Cloud9, click Create environment.
-
Enter the followings:
- Name :
test-ml-model
- Describe :
use to test AWS ML
- Name :
-
In Environment settings part:
- Environment type : Choose Create a new instance for environment (EC2).
- Instance type : Choose t2.micro (1 GiB RAM + 1 vCPU).
-
At Review page, click Create environment.
Note: Please download the Web folder in this tutorial.
-
In the navigation pane, click File and choose Web folder for Select folder.
-
Copy below command and paste into the terminal to update packages.
sudo yum -y update
-
Enter the command in terminal to change the folder to Web.
cd Web
- Enter the command in terminal to install the composer.
curl -sS https://getcomposer.org/installer | php
- Enter the command in terminal to install AWS SDK for PHP.
php composer.phar require aws/aws-sdk-php
-
Open the regression.php in the console.
-
At line 118 and 119, paste your model id and your predict endpoint here.
-
At line 164, paste your model id here.
-
In the navigation pane, click Run and choose Run Configurations.
-
Choose New Run Configuration.
-
In Command field, enter the following :
Web/regression.php
-
In Runner part, choose PHP (built-in web server), and click green button Run.
-
In the navigation pane, click Review and choose Preview Running Application. You will see the page as below.
-
Add the following behind the /. You will see the below page.
Web/regression.php
-
Click Predict, you will see the predict result.
Conclusion
Now you’ve created a forecast model for the number of bicycle rentals with AWS Machine Learning and tested it with Cloud9 , and create a realtime endpoint to add this to the php page for real-time predictions.
AWS Machine Learning can also be used in other scenarios, such as spam classification, text sentiment analysis, news classification, movie recommendation engine, etc. It really reduces labor costs and time to build, train the model.
Machine learning is now a trend, if you don’t have any machine learning experience, just try AWS Machine Learning.