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

removed "b"

parent b70952fc
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id:d8c5b7a8 tags: %% Cell type:markdown id:a016336c tags:
NAME: NAME:
%% Cell type:markdown id:db477b79 tags: %% Cell type:markdown id:db477b79 tags:
<center> <center>
<h3>ASSIGNMENT#1 (Algorithms) - Nov. 27, 2023</h3> <h3>ASSIGNMENT#1 (Algorithms) - Nov. 27, 2023</h3>
</center> </center>
Due date: **December 8th, 2023, 5pm** (no extension will be allowed). Due date: **December 8th, 2023, 5pm** (no extension will be allowed).
Submit your solution by email: romain.vuillemot@ec-lyon.fr Submit your solution by email: romain.vuillemot@ec-lyon.fr
You may work as a group (max 2) but all members are required to submit their solution and indicate their collaborator (if any). You may work as a group (max 2) but all members are required to submit their solution and indicate their collaborator (if any).
## Goal of this assignment ## 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).** You may then replace the code below with your answer for each question: 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).** You may then replace the code below with your answer for each question:
```python ```python
# YOUR CODE HERE # YOUR CODE HERE
raise NotImplementedError() raise NotImplementedError()
``` ```
## Grading ## Grading
- 20% for the results to the questions - 20% for the results to the questions
- 60% for the code quality - 60% for the code quality
- 20% for the notebook presentation - 20% for the notebook presentation
- +10% bonus question - +10% bonus question
## Getting started ## Getting started
We provide you with a dataset containing movie characters. Each character is represented as a row, along with connections to other characters, based on the movie script. You will use those connections to create a graph-based data structure and answer the questions. We provide you with a dataset containing movie characters. Each character is represented as a row, along with connections to other characters, based on the movie script. You will use those connections to create a graph-based data structure and answer the questions.
To get you started with the dataset, we provide you with the code that loads it: 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: %% Cell type:code id:cf409997-537f-4f89-a039-c2b3494972f2 tags:
``` python ``` python
data_file = 'users.csv' data_file = 'users.csv'
with open(data_file, 'r') as file: with open(data_file, 'r') as file:
lines = file.readlines()b lines = file.readlines()
data = [tuple(line.strip().split(',')) for line in lines[1:]] data = [tuple(line.strip().split(',')) for line in lines[1:]]
``` ```
%% Cell type:markdown id:c48b6391-d858-4a35-b428-b99434ee2d57 tags: %% 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: 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:
``` ```
[('Tony_Stark', [('Tony_Stark',
'40', '40',
'Male', 'Male',
'1.85', '1.85',
'Steve_Rogers Natasha_Romanoff Bruce_Banner Thor_Odinson'), 'Steve_Rogers Natasha_Romanoff Bruce_Banner Thor_Odinson'),
('Steve_Rogers', ('Steve_Rogers',
'98', '98',
'Male', 'Male',
'1.88', '1.88',
'Tony_Stark Natasha_Romanoff Sam_Wilson Bucky_Barnes'), 'Tony_Stark Natasha_Romanoff Sam_Wilson Bucky_Barnes'),
... ...
``` ```
%% Cell type:markdown id:70e93e78-f4dd-435f-b0f7-d56d928d7051 tags: %% Cell type:markdown id:70e93e78-f4dd-435f-b0f7-d56d928d7051 tags:
**Question 1 -** How many characters are there in the dataset? **Question 1 -** How many characters are there in the dataset?
%% Cell type:code id:9022b450-6fa6-41d0-999e-e019917cda79 tags: %% Cell type:code id:9022b450-6fa6-41d0-999e-e019917cda79 tags:
``` python ``` python
# YOUR CODE HERE # YOUR CODE HERE
raise NotImplementedError() raise NotImplementedError()
``` ```
%% Cell type:markdown id:0a1a4c6c-f95c-4dc3-8bb3-863d1048ae79 tags: %% 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. You may then be able to plot it with the `plot_character_connections` function provided in the next cell: **Question 2 -** Write a function that turns the `data` variable into a dictionnary data structure like the one below. You may then 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'], {'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: %% Cell type:code id:7139b3cf-1c00-43bb-bc1b-67b4a8e2a92d tags:
``` python ``` python
adjacency_list = {} adjacency_list = {}
# YOUR CODE HERE # YOUR CODE HERE
raise NotImplementedError() raise NotImplementedError()
``` ```
%% Cell type:code id:fbbdd57e-6895-4d3c-b561-406d5e6668a9 tags: %% Cell type:code id:fbbdd57e-6895-4d3c-b561-406d5e6668a9 tags:
``` python ``` python
# please run the cells below the "Utils" section first # please run the cells below the "Utils" section first
plot_character_connections(adjacency_list) plot_character_connections(adjacency_list)
``` ```
%% Cell type:markdown id:4a62b350-2bc8-476d-b9c6-13a08d649bdc tags: %% Cell type:markdown id:4a62b350-2bc8-476d-b9c6-13a08d649bdc tags:
**Question 3 -** Is there a character self-connected to her/himself? **Question 3 -** Is there a character self-connected to her/himself?
%% Cell type:code id:232f3d2a-8300-40c1-a908-ebfa5e380ae1 tags: %% Cell type:code id:232f3d2a-8300-40c1-a908-ebfa5e380ae1 tags:
``` python ``` python
# YOUR CODE HERE # YOUR CODE HERE
raise NotImplementedError() raise NotImplementedError()
``` ```
%% Cell type:markdown id:b79c97bc-e7d5-4ff4-bb1c-5bdf1e3abae2 tags: %% 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). **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: %% Cell type:code id:98186a3a-bd4c-4bf8-9ebd-2f350a83c856 tags:
``` python ``` python
# YOUR CODE HERE # YOUR CODE HERE
raise NotImplementedError() raise NotImplementedError()
``` ```
%% Cell type:markdown id:840a8875-2f71-4da9-bbe7-0f1aab5f612b tags: %% Cell type:markdown id:840a8875-2f71-4da9-bbe7-0f1aab5f612b tags:
**Question 5 -** Are connections mutual in the graph? **Question 5 -** Are connections mutual in the graph?
%% Cell type:code id:12d15b4d-cf98-45aa-994c-e41070b9ea3a tags: %% Cell type:code id:12d15b4d-cf98-45aa-994c-e41070b9ea3a tags:
``` python ``` python
# YOUR CODE HERE # YOUR CODE HERE
raise NotImplementedError() raise NotImplementedError()
``` ```
%% Cell type:markdown id:5e1b0409-1dff-4d8b-a5d8-a1efa1c10125 tags: %% Cell type:markdown id:5e1b0409-1dff-4d8b-a5d8-a1efa1c10125 tags:
**Question 6 (BONUS) -** Among the community of characters, is there a fully connected one? (i.e. where all characters are directly connected to the others). **Question 6 (BONUS) -** Among the community of characters, is there a fully connected one? (i.e. where all characters are directly connected to the others).
%% Cell type:code id:d8a1900d-c15f-4ef4-83d8-1ecfbc8bfcf8 tags: %% Cell type:code id:d8a1900d-c15f-4ef4-83d8-1ecfbc8bfcf8 tags:
``` python ``` python
# YOUR CODE HERE # YOUR CODE HERE
raise NotImplementedError() raise NotImplementedError()
``` ```
%% Cell type:markdown id:00c753ed-0905-4132-b276-4b415ba31408 tags: %% Cell type:markdown id:00c753ed-0905-4132-b276-4b415ba31408 tags:
## Utils ## Utils
%% Cell type:code id:d9f71538-98b6-4730-adc1-7ca84aa3748e tags: %% Cell type:code id:d9f71538-98b6-4730-adc1-7ca84aa3748e tags:
``` python ``` python
import networkx as nx import networkx as nx
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
def plot_character_connections(adjacency_list): def plot_character_connections(adjacency_list):
G = nx.DiGraph() G = nx.DiGraph()
for character, connections in adjacency_list.items(): for character, connections in adjacency_list.items():
G.add_node(character) G.add_node(character)
for connection in connections: for connection in connections:
G.add_edge(character, connection) G.add_edge(character, connection)
plt.figure(figsize=(12, 8)) plt.figure(figsize=(12, 8))
pos = nx.spring_layout(G, seed=42) pos = nx.spring_layout(G, seed=42)
nx.draw( nx.draw(
G, G,
pos, pos,
with_labels=True, with_labels=True,
node_size=500, node_size=500,
node_color='skyblue', node_color='skyblue',
font_weight='bold', font_weight='bold',
font_size=10 font_size=10
) )
plt.title('Movie characters') plt.title('Movie characters')
plt.show() plt.show()
``` ```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment