Fix formatting issues and inconsistencies
This commit is contained in:
parent
229ae636c9
commit
7fb4a40727
|
@ -3,8 +3,6 @@
|
|||
Below is the assignment specification, in full, slightly edited for context and
|
||||
appearence.
|
||||
|
||||
---
|
||||
|
||||
## Introduction
|
||||
|
||||
This project is all about "social networks", and the power of social
|
||||
|
@ -21,17 +19,17 @@ network, and (mutual) friendship connections as "edges" connecting those nodes.
|
|||
|
||||
## Part 1 - Friends
|
||||
|
||||
Write a function get_friendly_dict() that calculates the degree-one friends of
|
||||
Write a function `get_friendly_dict()` that calculates the degree-one friends of
|
||||
each individual in a social network. The function takes one argument:
|
||||
|
||||
- friend_list, a list of reciproal friendship links between individuals.
|
||||
- `friend_list`, a list of reciproal friendship links between individuals.
|
||||
|
||||
The function should return a dictionary of sets, containing the set of all
|
||||
"degree-one" (immediate) friends for each individual in the social network.
|
||||
Note that the specific order of the individuals in the dictionary, and also the
|
||||
ordering of the friends in each set does not matter.
|
||||
|
||||
The structure of friend_list is as follows: each element is a 2-tuple of
|
||||
The structure of `friend_list` is as follows: each element is a 2-tuple of
|
||||
strings, representing a pairing of names of individuals in the social network
|
||||
who are friends. Note that as friendship links are reciprocal, the 2-tuple
|
||||
('kim', 'sandy') indicates that 'kim' is a friend of 'sandy', and also that
|
||||
|
@ -49,12 +47,12 @@ Example function calls are:
|
|||
|
||||
## Part 2 - Social Network Besties
|
||||
|
||||
Write a function friend_besties() that calculates the "besties" (i.e.,
|
||||
Write a function `friend_besties()` that calculates the "besties" (i.e.,
|
||||
degree-one friends) of a given individual in a social network. The function
|
||||
takes two arguments:
|
||||
|
||||
- individual, an individual in the social network, in the form of a string ID;
|
||||
- bestie_dict, a dictionary of sets of friends of each individual in the
|
||||
- `individual`, an individual in the social network, in the form of a string ID;
|
||||
- `bestie_dict`, a dictionary of sets of friends of each individual in the
|
||||
social network.
|
||||
|
||||
The function should return a sorted list, made up of all "degree-one" friends
|
||||
|
@ -73,12 +71,12 @@ Example function calls are:
|
|||
|
||||
## Part 3 - Social Network Second Besties
|
||||
|
||||
Write a function friend_second_besties() that calculates the "second-besties"
|
||||
Write a function `friend_second_besties()` that calculates the "second-besties"
|
||||
(i.e. degree-two friends) of a given individual in a social network. The
|
||||
function takes two arguments:
|
||||
|
||||
- individual, an individual in the social network, in the form of a string ID;
|
||||
- bestie_dict, a dictionary of sets of friends of each individual in the
|
||||
- `individual`, an individual in the social network, in the form of a string ID;
|
||||
- `bestie_dict`, a dictionary of sets of friends of each individual in the
|
||||
social network.
|
||||
|
||||
The function should return a sorted list, made up of all "degree-two" friends
|
||||
|
@ -98,21 +96,21 @@ Example function calls are:
|
|||
|
||||
## Part 4 - Network Coverage
|
||||
|
||||
Write a function besties_coverage() that computes the "coverage" of nodes
|
||||
Write a function `besties_coverage()` that computes the "coverage" of nodes
|
||||
within a social network that are connected via predefined relationships to a
|
||||
given list of individuals (i.e., the proportion of connected individuals, to the
|
||||
total size of the network, which is the total number of people in the social
|
||||
network). The function takes three arguments:
|
||||
|
||||
- individuals, a list of individuals, each in the form of a string ID;
|
||||
- bestie_dict, a dictionary of sets of friends of each individual in the
|
||||
- `individuals`, a list of individuals, each in the form of a string ID;
|
||||
- `bestie_dict`, a dictionary of sets of friends of each individual in the
|
||||
social network;
|
||||
- relationship_list, a list of functions defining relationships in the
|
||||
- `relationship_list`, a list of functions defining relationships in the
|
||||
social network, selected from friend_besties and friend_second_besties.
|
||||
|
||||
The function should return a float, corresponding to the proportion of the
|
||||
total number of individuals who are either a member of individuals or connected
|
||||
via one of the relationships in relationship_list.
|
||||
via one of the relationships in `relationship_list`.
|
||||
|
||||
Example calls to the function are:
|
||||
|
||||
|
@ -145,14 +143,14 @@ based on the attributes of their social network, and the observation that a
|
|||
user's friends often have very similar interests and background to that user
|
||||
(what is formally called homophily).
|
||||
|
||||
Write a function friendly_prediction() which takes four arguments:
|
||||
Write a function `friendly_prediction()` which takes four arguments:
|
||||
|
||||
- unknown_user, a string indicating the identity of the user you are to predict
|
||||
attributes for;
|
||||
- features, a set of features you are to predict attributes for;
|
||||
- bestie_dict, a dictionary of sets of the besties for each user in the
|
||||
- `unknown_user`, a string indicating the identity of the user you are to
|
||||
predict attributes for;
|
||||
- `features`, a set of features you are to predict attributes for;
|
||||
- `bestie_dict`, a dictionary of sets of the besties for each user in the
|
||||
dataset, following the same format as the earlier questions in the project;
|
||||
- feat_dict, a dictionary containing the known attributes for each user in the
|
||||
- `feat_dict`, a dictionary containing the known attributes for each user in the
|
||||
training data, across a range of features; note that there is no guarantee
|
||||
that the attribute for a given feature will be known for every training user.
|
||||
|
||||
|
@ -175,9 +173,9 @@ Your function should make its predictions as follows:
|
|||
Note that all attributes will take the form of strings, with the empty string
|
||||
representing the fact that the user explicitly has no value for that feature
|
||||
(e.g., if the user did not go to university, the value for university would be
|
||||
''), and the lack of an attribute for a given feature indicating that the
|
||||
attribute is unknown. Note further that even if the attribute for unknown_user
|
||||
is available in feat_dict, you should predict based on the attributes of
|
||||
`''`), and the lack of an attribute for a given feature indicating that the
|
||||
attribute is unknown. Note further that even if the attribute for `unknown_user`
|
||||
is available in `feat_dict`, you should predict based on the attributes of
|
||||
besties and second besties.
|
||||
|
||||
Example calls to the function are:
|
||||
|
|
|
@ -7,11 +7,11 @@ from typing import Callable
|
|||
def flatten_network(bestie_dict: dict[str, set[str]]) -> list[str]:
|
||||
"""Creates a list of everyone in a social network.
|
||||
|
||||
Args:
|
||||
### Parameters:
|
||||
bestie_dict (dict): A dictionary of sets of friends of each individual
|
||||
in the social network.
|
||||
|
||||
Returns:
|
||||
### Returns:
|
||||
individuals (list): A list of every person in a social network.
|
||||
"""
|
||||
people = set()
|
||||
|
|
43
src/part5.py
43
src/part5.py
|
@ -11,12 +11,13 @@ def predict_feature(feature: str, people: list[str],
|
|||
feat_dict: dict[str, dict[str, str]]) -> list[str] | None:
|
||||
"""Predicts the value of a feature given a list of people to search through.
|
||||
|
||||
Args:
|
||||
### Parameters:
|
||||
feature (str): The feature of interest to predict.
|
||||
people (list): The list of people to search through.
|
||||
feat_dict (dict[str, dict[str, str]]): The list of features for the people.
|
||||
feat_dict (dict[str, dict[str, str]]): The list of features for the
|
||||
people.
|
||||
|
||||
Returns:
|
||||
### Returns:
|
||||
feature (list or None): Returns a sorted list of predictions of features
|
||||
if people had that attribute. Otherwise returns None.
|
||||
"""
|
||||
|
@ -48,7 +49,7 @@ def friendly_prediction(unknown_user: str, features: set[str],
|
|||
"""Predicts a set of features for a user based on the features that their
|
||||
friends have.
|
||||
|
||||
Args:
|
||||
### Parameters:
|
||||
unknown_user (str): The user who you are predicting attributes for.
|
||||
features (set): A set of features to predict.
|
||||
bestie_dict (dict): A dictionary of sets of friends of each individual
|
||||
|
@ -56,9 +57,41 @@ def friendly_prediction(unknown_user: str, features: set[str],
|
|||
feat_dict (dict): A dictionary containing the known attributes for each
|
||||
user in the social network.
|
||||
|
||||
Returns:
|
||||
### Returns:
|
||||
predictions (dict): A dictionary of features with a predicted list of
|
||||
values for each feature.
|
||||
|
||||
### Examples:
|
||||
>>> friendly_prediction('glenn', {'favourite author', 'university'},
|
||||
{'kim': {'sandy', 'alex', 'glenn'}, 'sandy': {'kim', 'alex'},
|
||||
'alex': {'kim', 'sandy'}, 'glenn': {'kim'}},
|
||||
{'glenn': {'university': ''}, 'kim': {'favourite author': 'AA Milne'},
|
||||
'sandy': {'favourite author': 'JRR Tolkien',
|
||||
"university": "University of Melbourne"},
|
||||
'alex': {'favourite author': 'AA Milne',
|
||||
'university': 'Monash University'}})
|
||||
{'university': ['Monash University', 'University of Melbourne'],
|
||||
'favourite author': ['AA Milne']}
|
||||
|
||||
>>> friendly_prediction('kim', {'university'},
|
||||
{'kim': {'sandy', 'alex', 'glenn'}, 'sandy': {'kim', 'alex'},
|
||||
'alex': {'kim', 'sandy'}, 'glenn': {'kim'}},
|
||||
{'glenn': {'university': ''}, 'kim': {'favourite author': 'AA Milne'},
|
||||
'sandy': {'favourite author': 'JRR Tolkien',
|
||||
"university": "University of Melbourne"},
|
||||
'alex': {'favourite author': 'AA Milne',
|
||||
'university': 'Monash University'}})
|
||||
{'university': ['', 'Monash University', 'University of Melbourne']}
|
||||
|
||||
>>> friendly_prediction('kim', {'birthplace'},
|
||||
{'kim': {'sandy', 'alex', 'glenn'}, 'sandy': {'kim', 'alex'},
|
||||
'alex': {'kim', 'sandy'}, 'glenn': {'kim'}},
|
||||
{'glenn': {'university': ''}, 'kim': {'favourite author': 'AA Milne'},
|
||||
'sandy': {'favourite author': 'JRR Tolkien',
|
||||
"university": "University of Melbourne"},
|
||||
'alex': {'favourite author': 'AA Milne',
|
||||
'university': 'Monash University'}})
|
||||
{'birthplace': []}
|
||||
"""
|
||||
|
||||
predictions = {}
|
||||
|
|
Loading…
Reference in New Issue