Advanced Data Analytics Using Python_ With Machine Learning, Deep Learning and NLP Examples ( 2023)
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Chapter 1
Introduction
if f == 'client_time':
feature_value = get_
hour(int(feature_value))
predicted = predicted + get_value(g.
session, g.scores, f, feature_value)
return str(math.exp(predicted + g.b)-1)
app.run(debug = True, host ='0.0.0.0')
This code exposes a deep learning model as a Flask web service.
A JavaScript client will send the request with web user parameters such
as the IP address, ad size, ad position, and so on, and it will return the
price of the ad as a response. The features are categorical. You will learn
how to convert them into numerical scores in Chapter 3. These scores
are stored in an in-memory database. The service fetches the score from
the database, sums the result, and replies to the client. This score will be
updated real time in each iteration of training of a deep learning model. It
is using MongoDB to store the frequency of that IP address in that site. It is
an important parameter because a user coming to a site for the first time
is really searching for something, which is not true for a user where the
frequency is greater than 5. The number of IP addresses is huge, so they
are stored in a distributed MongoDB database.
High-Performance API and Concurrent
Programming
Flask is a good choice when you are building a general solution that is
also a graphical user interface (GUI). But if high performance is the most
critical requirement of your application, then Falcon is the best choice. The
following code is an example of the same model shown previously exposed
by the Falcon framework. Another improvement I made in this code is that
I implemented multithreading, so the code will be executed in parallel.
17