Coders Packet

Cook Recommendation System in Python using scikit-learn

By Sahil Raj

A recommendation system that provides recommendations based on nearest location, specialty, and rating provided by users.

INTRODUCTION

This project contains a Jupyter Notebook that recommends a cook to users based on the nearest location, specialty required, and rating of the cook given by other users. This recommendation uses two datasets namely cook.csv and ratings.csv for model building. 

There are two Python scripts namely getLocation.py which shows how latitude and longitude data is generated using the geopy library and get_csv_file.py which generates a CSV file named output.csv which is generated as a ratings dataset. get_csv_file.py uses numpy and pandas libraries to create a dataset.

Note: The dataset does not depict real-life data and is a result of the merging of multiple datasets and the generation of datasets using programming tools.

HOW TO RUN THE CODE

1. Extract the zipped file given below.

2. Open the extracted folder.

3. Open the file named "recommend.ipynb" on Jupyter Notebook or Google Collaboratory or any other preferred platform.

4. Modify the address and specialty values in the last cell of the notebook as required.

5. Execute each of the cells given in the notebook.

6. See the recommendation at the end of last cell.

 

DEMO EXECUTION

Modify input

Run all cells

See output

CODE EXPLANATION

recommend.ipynb

This file involves the following steps:

  1. Preprocessing and combining the data: First, the data from these CSV files are loaded into pandas dataframes. The 'cook' and 'ratings' dataframes are then merged based on the 'cookId' column, creating a new dataframe that includes all the relevant information about each cook and their ratings. Additionally, the 'Specialty' column is transformed into a numerical format using a label encoder. A new 'Location' column is created by combining the 'City', 'State', and 'Country' columns.
  2. Generating location data from the address: A geocoder from the 'geopy' library is used to convert the location of each cook into latitude and longitude coordinates, which are added to the dataframe in new 'Latitude' and 'Longitude' columns. In order to improve the efficiency of the geocoding process, we get the unique locations first, convert them to latitude and longitude, and then map these values back to your original dataframe. This is done using geopy library. The working of geopy library is given in getLocation.py.
  3. Creating the recommendation function:: The 'recommend_cooks' function is defined to take a user's address and required specialty as inputs, and return a list of recommended cooks. This function first converts the user's address into latitude and longitude coordinates. Then, it filters the dataframe for cooks that match the required specialty. It calculates the Euclidean distance between the user and each cook using their latitude and longitude coordinates. The cooks are then sorted by their distance from the user and their rating.
  4. Recommending the nearest cooks, sorted by their predicted ratings: The 'recommend_cooks' function can be called with a specific address and specialty to get a list of recommended cooks. The results are displayed in a table showing the name, location, distance, and rating of each recommended cook.

 

getLocation.py

This file uses the geopy library to provide longitude and latitude data from the given location as text.

The `geolocator` is an object of the Nominatim class from the `geopy.geocoders` module, which allows you to use the OpenStreetMap Nominatim API to convert an address into latitude and longitude.

get_csv_file.py

In this script, we are using `np.random.randint` to generate random integers. The `np.arange` function is used to generate a sequence of increasing integers. Finally, the data frame is saved to a CSV file using `df.to_csv`.

 

Download Complete Code

Comments

No comments yet

Download Packet

Reviews Report

Submitted by Sahil Raj (rajsahilcoder)

Download packets of source code on Coders Packet