Skip to content
Snippets Groups Projects
Commit 5473a1b6 authored by Romain Vuillemot's avatar Romain Vuillemot
Browse files

update assignment

parent bdc4bf24
No related branches found
No related tags found
No related merge requests found
...@@ -102,12 +102,13 @@ Video on [Binary Tree](https://www.youtube.com/watch?v=pkYVOmU3MgA&t=11510s) ...@@ -102,12 +102,13 @@ Video on [Binary Tree](https://www.youtube.com/watch?v=pkYVOmU3MgA&t=11510s)
📝 Quizz 8 📝 Quizz 8
📝 Assignment 1 - Analyzing a dataset
📝 [Assignment 1 - Analyzing a dataset](assignments/assignment-01.ipynb)
### Exam (december 5th) ### Exam (december 5th)
- Final written exam - Final written exam on paper
- 2h - 2h
- No document - No document
......
%% Cell type:markdown id:6e53f6de tags:
NAME:
%% Cell type:markdown id:db477b79 tags:
<center>
<h3>ASSIGNMENT#1 (Algorithms) - Nov. 27, 2023</h3>
</center>
Due date: **December 6th, 2023, 5pm** (no extension will be allowed).
Submit your solution by email: romain.vuillemot@ec-lyon.com
## Goal of this assignment
In this assignment we provide you with a dataset of characters from a movie. Your role will be to answer the questions below programmatically, using Pyhon. **Please note you need to answer with fully working python code embedded in this notebook as solution (no external modules or files can be included).**
## Grading
- 30% on the results to the questions
- 50% on the code quality
- 20% on the notebook presentation
- \+ 10% bonus question
## Getting started
We provide you with a dataset containing movie characters on each row. Each character has connections, based on the movie script, from which you will create a graph-based data structure. To get you started with the dataset, we provide you with the code that loads it:
%% Cell type:code id:cf409997-537f-4f89-a039-c2b3494972f2 tags:
``` python
data_file = 'users.csv'
with open(data_file, 'r') as file:
lines = file.readlines()b
data = [tuple(line.strip().split(',')) for line in lines[1:]]
```
%% Cell type:markdown id:c48b6391-d858-4a35-b428-b99434ee2d57 tags:
The `data` variable contains the list of characters. You may look at the `users.csv` file to grasp the values of this variable. Here is a sample of the dataset:
```
[('Tony_Stark',
'40',
'Male',
'1.85',
'Steve_Rogers Natasha_Romanoff Bruce_Banner Thor_Odinson'),
('Steve_Rogers',
'98',
'Male',
'1.88',
'Tony_Stark Natasha_Romanoff Sam_Wilson Bucky_Barnes'),
...
```
%% Cell type:markdown id:70e93e78-f4dd-435f-b0f7-d56d928d7051 tags:
**Question 1 -** How many characters are in the dataset?
%% Cell type:code id:9022b450-6fa6-41d0-999e-e019917cda79 tags:
``` python
# YOUR CODE HERE
raise NotImplementedError()
```
%% Cell type:markdown id:0a1a4c6c-f95c-4dc3-8bb3-863d1048ae79 tags:
**Question 2 -** Write a function that turns the `data` variable into a dictionnary data structure like the one below below. You may be able to plot it with the `plot_character_connections` function provided in the next cell:
```
{'Tony_Stark': ['Steve_Rogers', 'Natasha_Romanoff', 'Bruce_Banner', 'Thor_Odinson'], 'Steve_Rogers': ['Tony_Stark', 'Natasha_Romanoff', 'Sam_Wilson', 'Bucky_Barnes'],
..
```
%% Cell type:code id:7139b3cf-1c00-43bb-bc1b-67b4a8e2a92d tags:
``` python
adjacency_list = {}
# YOUR CODE HERE
raise NotImplementedError()
```
%% Cell type:code id:fbbdd57e-6895-4d3c-b561-406d5e6668a9 tags:
``` python
# please run the cells below the "Utils" section first
plot_character_connections(adjacency_list)
```
%% Cell type:markdown id:4a62b350-2bc8-476d-b9c6-13a08d649bdc tags:
**Question 3 -** Is there a character self-connected to her/himself?
%% Cell type:code id:232f3d2a-8300-40c1-a908-ebfa5e380ae1 tags:
``` python
# YOUR CODE HERE
raise NotImplementedError()
```
%% Cell type:markdown id:b79c97bc-e7d5-4ff4-bb1c-5bdf1e3abae2 tags:
**Question 4 -** How many communities can you identify? We define a community as a sub-graph of connected people by a path (i.e. a connected component).
%% Cell type:code id:98186a3a-bd4c-4bf8-9ebd-2f350a83c856 tags:
``` python
# YOUR CODE HERE
raise NotImplementedError()
```
%% Cell type:markdown id:840a8875-2f71-4da9-bbe7-0f1aab5f612b tags:
**Question 5 -** Are connections mutual in the graph?
%% Cell type:code id:12d15b4d-cf98-45aa-994c-e41070b9ea3a tags:
``` python
# YOUR CODE HERE
raise NotImplementedError()
```
%% Cell type:markdown id:5e1b0409-1dff-4d8b-a5d8-a1efa1c10125 tags:
**Question 6 (BONUS) -** Among the community of characters, is there one fully connected? (i.e. where all characters are directly connected to the others).
%% Cell type:code id:d8a1900d-c15f-4ef4-83d8-1ecfbc8bfcf8 tags:
``` python
# YOUR CODE HERE
raise NotImplementedError()
```
%% Cell type:markdown id:00c753ed-0905-4132-b276-4b415ba31408 tags:
## Utils
%% Cell type:code id:d9f71538-98b6-4730-adc1-7ca84aa3748e tags:
``` python
import networkx as nx
import matplotlib.pyplot as plt
def plot_character_connections(adjacency_list):
G = nx.DiGraph()
for character, connections in adjacency_list.items():
G.add_node(character)
for connection in connections:
G.add_edge(character, connection)
plt.figure(figsize=(12, 8))
pos = nx.spring_layout(G, seed=42)
nx.draw(
G,
pos,
with_labels=True,
node_size=500,
node_color='skyblue',
font_weight='bold',
font_size=10
)
plt.title('Movie characters')
plt.show()
```
Name,Age,Gender,Height,Connections
Tony_Stark,40,Male,1.85,Steve_Rogers Natasha_Romanoff Bruce_Banner Thor_Odinson
Steve_Rogers,98,Male,1.88,Tony_Stark Natasha_Romanoff Sam_Wilson Bucky_Barnes
Natasha_Romanoff,35,Female,1.65,Clint_Barton Bruce_Banner Tony_Stark Steve_Rogers
Bruce_Banner,42,Male,1.75,Tony_Stark Natasha_Romanoff Thor_Odinson
Thor_Odinson,1500,Male,1.98,Tony_Stark Bruce_Banner Loki Odin
Clint_Barton,40,Male,1.83,Natasha_Romanoff Laura_Barton
Sam_Wilson,35,Male,1.83,Steve_Rogers Bucky_Barnes Sergent_Rhodes
Bucky_Barnes,106,Male,1.83,Steve_Rogers Sam_Wilson
Thanos,Unknown,Male,2.13,Gamora Nebula Loki
Loki,Unknown,Male,1.82,Thanos Thor_Odinson
Gamora,Unknown,Female,1.83,Thanos Nebula
Nebula,Unknown,Female,1.78,Thanos Gamora
Odin,5000,Male,2.05,Thor_Odinson Loki
Sergent_Rhodes,50,Male,1.85,Tony_Stark Sam_Wilson
Shuri,18,Female,1.68,T_Challa Okoye
T_Challa,45,Male,1.83,Shuri Okoye
Okoye,38,Female,1.75,Shuri T_Challa
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment