CEIS310_Module6_Project_Guide_QA Complete (2)
.docx
keyboard_arrow_up
School
DeVry University, Atlanta *
*We aren’t endorsed by this school
Course
115
Subject
English
Date
Dec 6, 2023
Type
docx
Pages
14
Uploaded by chrisshaunwilliams
Course Project
DeVry University
College of Engineering and Information Sciences
Course Number: CEIS310
Module 6: Develop Machine Learning Graphical Models and
Interpret Results
Objectives
To develop, test, and train a machine learning model for the Course Project
To learn and apply linear regression for ML in fitting the model and making predictions
Examining the model performance by calculating the residual sum of squares
Introduction
Pizza delivery chains such as Domino’s, Pizza Hut, and Papa John’s have been busy for the past
few years revamping, recalibrating ingredients, cutting delivery times, resetting brand images to
win customer satisfaction, and gaining an edge in the pizza delivery game. Most of them are
using AI and ML to improve store and online operations. A few of them are testing company’s
speed and efficiency by leveraging cloud servers and integrated hardware and software systems
for deep learning research.
For example, the Domino’s team created a delivery prediction model that forecasts when an
order would be ready using attributes of the order and what is happening in a Domino’s store,
such as the number of employees, managers, and customers present at that moment. The model
was based on a large dataset of 5 million orders, which isn’t massive but large enough to create
accurate models. All future orders are fed back into the system to further increase model
accuracy. Domino’s also acquired a machine learning operation platform called Datatron, which
sits on top of the Kubernetes cluster with the GPUs and assists Domino’s with ML-specific
functionalities. Datatron allows for model performance monitoring in real time, so data scientists
can be notified if their model requires retraining.
The objective of this project is to bring awareness, instigate interest, and promote the need of
using AI and machine learning algorithms and tools for process improvement. To keep things
simple, we will focus here on the use of Python machine learning library for regression analysis
and simple test/train techniques. Let us choose an example of predicting the price for a pizza
based on its many attributes (size, ingredients, toppings, etc.). When we have multiple dependent
variables for things we are trying to predict, that is multivariate regression. We will first
demonstrate simple linear regression.
Pizza Price Prediction
For example, imagine that you have a set of data comprising the sizes of a group of pizza in
inches and the corresponding pizza price in cents.
Code Run: PizzaPriceSize1.py
import matplotlib.pyplot as plt
# represents the sizes of a group of pizza in inches
size = [[6.0], [6.5], [6.9], [7.3], [7.9], [8.5]]
#represents the price of a group of pizza in cents
price =[[162], [190], [223], [250], [278], [315]]
plt.title('Pizza Price plotted against the size')
plt.xlabel('Pizza Size in inches')
plt.ylabel('Pizza Price in cents')
plt.plot(size, price, 'k.')
plt.axis([5.5, 9.0, 99, 350])
plt.grid(True)
Shown above is the graph of pizza size versus pizza price. This example is the right fit for simple linear
regression method because as the size increases, the price seems to increase, and there is a direct
relationship between pizza size and price.
Drawing Line of Linear Regression
Linear regression uses the relationship between the datapoints to draw a straight line through all
them.
It is useful to visualize the linear regression line created by the LinearRegression class.
This linear regression line can be used to predict future values.
Code Run: PizzaPriceSize2.py
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
size = [[6.0], [6.5], [6.9], [7.3], [7.9], [8.5]]
price =[[165], [200], [223], [250], [278], [315]]
plt.title('Pizza Price plotted against the size')
plt.xlabel('Pizza Size in inches')
plt.ylabel('Pizza Price in cents')
plt.plot(size, price, 'k.')
plt.axis([5.0, 9.0, 99, 355])
plt.grid(True)
#plot the regression line
plt.plot(size, model.predict(size), color='r')
Getting the Gradient and Intercept of the Linear Regression Line
Note that from the above figure, it is not clear at what value the linear regression line intercepts the y-
axis.
Here we are using model object, which provides the answer directly through the intercept_ property.
Using the model object, we can also get the gradient of the linear regression
line through the
coef_property.
print("Gradient of Linear Regression: ",round(model.coef_[0][0],2))
Using Linear Regression Class for Fitting the Model
Scikit-learn is a Python library that implements the various types of machine learning algorithms, such as
classification, regression, clustering, decision tree, and more. Using Scikit-learn, implementing machine
learning is now simply a matter of supplying the appropriate data to a function so that you can fit and
train the model.
The Scikit –learn library has the LinearRegression class that helps draw the straight line cutting through
all of the points. We create an instance of this class and use the size and price lists to create a linear
regression model using the fit() function as shown below.
from sklearn.linear_model import LinearRegression
size = [[6.0], [6.5], [6.9], [7.3], [7.9], [8.5]]
price =[[165], [200], [223], [250], [278], [315]]
model = LinearRegression()
model.fit(X = size, y = price)
Note that the size and price are both represented as two dimensional lists. This is due to the fit()
function requiring both the x and y arguments to be two dimensional of type list or ndarray.
Making Predictions
Once we have
fitted (trained)
the model, we can start to make predictions using the predict() function.
#make prediction using Scikit-learn algorithm:
size = model.predict([[10]])[0][0]
print(" Predicted Pizza Price: $", round(size/100,2))
Code Run: PizzaPriceSize3A.py
import numpy
from scipy import stats
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
size = [[6.0], [6.5], [6.9], [7.3], [7.9], [8.5]]
price =[[165], [200], [223], [250], [278], [315]]
model = LinearRegression()
model.fit(X = size, y = price)
size = model.predict([[10]])[0][0]
print(" Predicted 10 inches Pizza Price: $", round(size/100,2))
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help