Six Degrees of Kevin Bacon in Python: AI Project

Kevin Bacon

Introduction

Are you a Hollywood Movie lover? If you are, you must know about Kevin Bacon, a popular American Actor. I'm not gonna tell his biography here but I will discuss about a project named after him.

In this tutorial, we will discuss about Six Degrees of Kevin Bacon in Python. It's an advanced Python Project solved by Artificial Intelligence. You can use this AI project for your final year submission too.

Let's dig more deep into the working principle of the project.

Visit Also: Tic Tac Toe Game in Python with Artificial Intelligence

Project Details

The logic of this project is based on the six degrees of separation. The concept is, Every Person in the World is connected Less than Six or Six Social Connections away from each other.

Here, we will find the shortest distance between two actors via a film on which both actors have worked together(based on the given data). This time a movie will be the connection between two actors.

The program uses the Breath-First Search technique to find the shortest distance between two actors.

This project was given at CS50 Artificial Intelligence with Python, Project 0. There we have given two python files, and two folders, 'large' and 'small'. Both folders contain three CSV files(same file names): 'people.csv', 'movies.csv', 'stars.csv'. These files contain person id, person name, movie id, movie name, stars id, etc. 

Files present in the 'small' folder contain a few amount of data(for testing purpose only. It helps to find if the program is working or not) but in the 'large' folder, all the CSV files contain millions of data. With the help of these data, we will find the shortest distance between two actors

the project folder of six degrees of kevin bacon in python
Image - The Project Folder

Between these two python files: degrees.py, and util.py we will run the first one. The program takes two names as input. If both names are present in the people.csv file then the program will return the shortest path via they are connected otherwise, it will return the "The Person not found" message.

For example, you want to find the distance between Tom Cruise and Tom Hanks. For these two inputs the program may return the output like this.

2 degrees of separation.
1: Tom Hanks and Bill Paxton starred in Apollo 13
2: Bill Paxton and Tom Cruise starred in Edge of Tomorrow
 
distance between tom cruise and tom hanks with six degrees of kevin bacon project in python
Image - Distance between Tom Cruise and Tom Hanks

What can you learn from this project?

  • Working with millions of data
  • Working with CSV file using Python
  • Solving a real-world problem using Artificial Intelligence.
  • Application of Breadth-First Search.
  • Real-life problem solving with data structure: Queue, Stack, etc.

Source Code

Download the source code from my GitHub Page(https://github.com/subhankar-rakshit/) through the download button given below.

github page of the solution of six degrees of kevin bacon project using python
Image - GitHub Page

Output

Subhankar Rakshit

Meet Subhankar Rakshit, a Computer Science postgraduate (M.Sc.) and the creator of PySeek. Subhankar is a programmer, specializes in Python language. With a several years of experience under his belt, he has developed a deep understanding of software development. He enjoys writing blogs on various topics related to Computer Science, Python Programming, and Software Development.

Post a Comment (0)
Previous Post Next Post