09.10.2023 Views

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 7

Analytics at Scale

def fetch_score(self, featurename, featurevalue, kind):

pred = 0

try:

key = self.client.key(kind,featurename +

"_" + featurevalue)

res= self.client.get(key)

if res is not None:

pred = res['score']

except:

pass

return pred

def get_score(self, featurename, featurevalue):

with ThreadPoolExecutor(max_workers=5) as pool:

future_score = pool.submit(self.fetch_

score,featurename, featurevalue,self.

scores)

future_prob = pool.submit(self.fetch_

score,featurename, featurevalue,self.

probabilities)

if self.big:

future_howbig = pool.submit(self.

fetch_score,featurename,

featurevalue,self.is_big)

future_predbig = pool.submit(self.

fetch_score,featurename,

featurevalue,self.scores_big)

future_probbig = pool.submit(self.

fetch_score,featurename,

featurevalue,self.probabilities_big)

pred = future_score.result()

prob = future_prob.result()

172

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

Saved successfully!

Ooh no, something went wrong!