Reader small image

You're reading from  Serverless Machine Learning with Amazon Redshift ML

Product typeBook
Published inAug 2023
Reading LevelBeginner
PublisherPackt
ISBN-139781804619285
Edition1st Edition
Languages
Right arrow
Authors (4):
Debu Panda
Debu Panda
author image
Debu Panda

Debu Panda, a Senior Manager, Product Management at AWS, is an industry leader in analytics, application platform, and database technologies, and has more than 25 years of experience in the IT world. Debu has published numerous articles on analytics, enterprise Java, and databases and has presented at multiple conferences such as re:Invent, Oracle Open World, and Java One. He is lead author of the EJB 3 in Action (Manning Publications 2007, 2014) and Middleware Management (Packt, 2009).
Read more about Debu Panda

Phil Bates
Phil Bates
author image
Phil Bates

Phil Bates is a Senior Analytics Specialist Solutions Architect at AWS. He has more than 25 years of experience implementing large-scale data warehouse solutions. He is passionate about helping customers through their cloud journey and leveraging the power of ML within their data warehouse.
Read more about Phil Bates

Bhanu Pittampally
Bhanu Pittampally
author image
Bhanu Pittampally

Bhanu Pittampally is Analytics Specialist Solutions Architect at Amazon Web Services. His background is in data and analytics and is in the field for over 16 years. He currently lives in Frisco, TX with his wife Kavitha and daughters Vibha and Medha.
Read more about Bhanu Pittampally

Sumeet Joshi
Sumeet Joshi
author image
Sumeet Joshi

Sumeet Joshi is an Analytics Specialist Solutions Architect based out of New York. He specializes in building large-scale data warehousing solutions. He has over 17 years of experience in the data warehousing and analytical space.
Read more about Sumeet Joshi

View More author details
Right arrow

Building Regression Models

In the previous chapter, we learned about classification models. In this chapter, we will learn about building linear regression models where we predict numeric variables. Unlike classification models, linear regression models are used to predict a continuous numeric value. Similar to the previous chapter, here also you will learn about various methods that Redshift provides for creating linear regression models.

This chapter will provide several detailed examples of business problems that can be solved with these modeling techniques. In this chapter, we will walk through how you can try different algorithms to get the best regression model.

By the end of this chapter, you will be in a position to identify whether a business problem is a linear regression or not and then be able to identify the right method that Redshift provides to train and build the model.

In this chapter, we will go through the following main topics:

  • Introducing regression...

Technical requirements

This chapter requires a web browser and access to the following:

  • AWS account
  • Amazon Redshift Serverless endpoint
  • Amazon Redshift Query Editor v2

You can find the code used in this chapter here:

https://github.com/PacktPublishing/Serverless-Machine-Learning-with-Amazon-Redshift/blob/main/CodeFiles/chapter7/chapter7.sql

Introducing regression algorithms

Regression models are used where you are trying to predict a numeric outcome such as what price an item will sell for. The outcome variable is your target and your input variables are used to determine the relationship between the variables so that you can predict the unknown target on sets of data without the target variable.

You can have a single input variable, also known as simple linear regression. For example, years of experience and salary usually have a relationship.

Multiple linear regression is when you have multiple input variables. For example, predicting the selling price of homes in a particular zip code by using the relationship between the target (price) and various inputs such as square footage, number of bedrooms, pool, basement, lot size, and year built.

A good linear regression model has a small amount of vertical distance between the line and the data points. Refer to the following figure:

Figure 7.1 – Linear regression line

Figure...

Creating a simple linear regression model using XGBoost

To build our simple linear regression problem, we are going to take a look at a dataset that includes predicting weight based on height. This dataset has only one independent variable, which is height in inches, and is used to predict weight in pounds. Since there is only one independent variable, we call this the simple linear regression model.

In this section, we will upload the data, analyze it, prepare it for training the model, and then lastly, we will create the model and run prediction queries using the function created by the model.

Uploading and analyzing the data

We are going to work on a height and weight dataset in this section.

The dataset contains 25,000 synthetic records of human heights and weights of 18-year-old participants. This data was generated based on a 1993 Growth Survey, which was conducted on 25,000 children from their birth to 18 years of age. The participants were recruited from Maternal...

Creating multi-input regression models

In this exercise, you will learn how to build a regression model using multiple input variables in Amazon Redshift ML.

In this use case, we will use a dataset containing the sales history of online sporting events. A sporting event management company wants to review the data for the latest football and baseball seasons to figure out which games underperformed for revenue, and what the revenue projections look like for the season.

Your task is to build and train a model to predict revenue for upcoming events in order to proactively take action to increase ticket sales to ensure revenue numbers meet the company’s targets.

After successfully connecting to Redshift as an admin or database developer, load data into Amazon Redshift.

Navigate to Redshift query editor v2 and connect to the Serverless endpoint and the dev database.

Use the same schema and query editor page you created for the previous exercise.

Create your input...

Summary

In this chapter, we discussed regression models in detail and saw how to create single-input and multi-input regression models. We learned how easy it is to predict a numeric value. We also learned how to validate regression models, take actions to improve our model’s accuracy, and do prediction queries with our regression models. We walked through options for using XGBoost, Linear Learner and auto options to train your model.

We also saw how we can check and validate the MSE score from the SHOW MODEL output using SQL commands in Redshift.

In the next chapter, we will show you how to create unsupervised models using the K-means algorithm.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Serverless Machine Learning with Amazon Redshift ML
Published in: Aug 2023Publisher: PacktISBN-13: 9781804619285
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (4)

author image
Debu Panda

Debu Panda, a Senior Manager, Product Management at AWS, is an industry leader in analytics, application platform, and database technologies, and has more than 25 years of experience in the IT world. Debu has published numerous articles on analytics, enterprise Java, and databases and has presented at multiple conferences such as re:Invent, Oracle Open World, and Java One. He is lead author of the EJB 3 in Action (Manning Publications 2007, 2014) and Middleware Management (Packt, 2009).
Read more about Debu Panda

author image
Phil Bates

Phil Bates is a Senior Analytics Specialist Solutions Architect at AWS. He has more than 25 years of experience implementing large-scale data warehouse solutions. He is passionate about helping customers through their cloud journey and leveraging the power of ML within their data warehouse.
Read more about Phil Bates

author image
Bhanu Pittampally

Bhanu Pittampally is Analytics Specialist Solutions Architect at Amazon Web Services. His background is in data and analytics and is in the field for over 16 years. He currently lives in Frisco, TX with his wife Kavitha and daughters Vibha and Medha.
Read more about Bhanu Pittampally

author image
Sumeet Joshi

Sumeet Joshi is an Analytics Specialist Solutions Architect based out of New York. He specializes in building large-scale data warehousing solutions. He has over 17 years of experience in the data warehousing and analytical space.
Read more about Sumeet Joshi