09.10.2023 Views

Advanced Data Analytics Using Python_ With Machine Learning, Deep Learning and NLP Examples ( 2023)

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 1

Introduction

metadata1 = MetaData(db1)

metadata2 = MetaData(db2)

metadata3 = MetaData(db3)

self.scores = Table('scores', metadata1, autoload=True)

self.probabilities = Table('probabilities', metadata2,

autoload=True)

self.ctr = Table('ctr', metadata3, autoload=True)

client = MongoClient(connect=False,maxPoolSize=1)

self.db = client.frequency

self.gi = pygeoip.GeoIP('GeoIP.dat')

self.high = 1.2

self.low = .8

def get_hour(self,timestamp):

return dt.datetime.utcfromtimestamp(timestamp / 1e3).hour

def get_score(self, featurename, featurevalue):

prob = 0

pred = 0

s = self.scores.select((self.scores.c.feature_name

== featurename) & (self.scores.c.feature_value ==

featurevalue))

rs = s.execute()

row = rs.fetchone()

if row is not None:

pred = pred + float(row['score'])

s = self.probabilities.select((self.probabilities.c.feature_

name == featurename) & (self.probabilities.c.feature_value ==

featurevalue))

rs = s.execute()

row = rs.fetchone()

19

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!