Skip to Content
Raspberry Pi 3 Cookbook for Python Programmers - Third Edition
book

Raspberry Pi 3 Cookbook for Python Programmers - Third Edition

by Steven Lawrence Fernandes, Tim Cox
April 2018
Beginner content levelBeginner
552 pages
13h 58m
English
Packt Publishing
Content preview from Raspberry Pi 3 Cookbook for Python Programmers - Third Edition

How to do it...

  1. We will create a new Python file and import the following packages into it:
import json 
import numpy as np  
  1. To calculate the Euclidean score between two users, we will define a new function. Let's check the presence of the users in the database:
# The following code will return the Euclidean distance score between user1 and user2: 
 
def euclidean_dist_score(dataset, FirstUser, SecondUser): 
  if FirstUser not in dataset: 
    raiseTypeError('User ' + FirstUser + ' not present in the dataset') 
  if SecondUser not in dataset: 
    raiseTypeError('User ' + SecondUser + ' not present in the dataset') 
  1. We will now extract the movies that have been rated by both users. Then we will compute the score:
 # Movies rated by both FirstUser and SecondUser ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Raspberry Pi for Python Programmers Cookbook - Second Edition

Raspberry Pi for Python Programmers Cookbook - Second Edition

Tim Cox

Publisher Resources

ISBN: 9781788629874Supplemental Content