이 Assignment는 Coursera Jupyter 콘솔에서만 제대로 진행할 수 있습니다.
(데이터 파일을 따로 제공하지 않기 때문입니다.)
개괄 원본
Eight employees at a small company were asked to choose 3 movies that they would most enjoy watching for the upcoming company movie night. These choices are stored in the file `Employee_Movie_Choices.txt`. A second file, `Employee_Relationships.txt`, has data on the relationships between different coworkers. The relationship score has value of `-100` (Enemies) to `+100` (Best Friends). A value of zero means the two employees haven't interacted or are indifferent. Both files are tab delimited.
import networkx as nx
import pandas as pd
import numpy as np
from networkx.algorithms import bipartite
# This is the set of employees
employees = set(['Pablo',
'Lee',
'Georgia',
'Vincent',
'Andy',
'Frida',
'Joan',
'Claude'])
# This is the set of movies
movies = set(['The Shawshank Redemption',
'Forrest Gump',
'The Matrix',
'Anaconda',
'The Social Network',
'The Godfather',
'Monty Python and the Holy Grail',
'Snakes on a Plane',
'Kung Fu Panda',
'The Dark Knight',
'Mean Girls'])
# you can use the following function to plot graphs
# make sure to comment it out before submitting to the autograder
def plot_graph(G, weight_name=None):
'''
G: a networkx G
weight_name: name of the attribute for plotting edge weights (if G is weighted)
'''
%matplotlib notebook
import matplotlib.pyplot as plt
plt.figure()
pos = nx.spring_layout(G)
edges = G.edges()
weights = None
if weight_name:
weights = [int(G[u][v][weight_name]) for u,v in edges]
labels = nx.get_edge_attributes(G,weight_name)
nx.draw_networkx_edge_labels(G,pos,edge_labels=labels)
nx.draw_networkx(G, pos, edges=edges, width=weights);
else:
nx.draw_networkx(G, pos, edges=edges);
Question 1
Using NetworkX, load in the bipartite graph from Employee_Movie_Choices.txt and return that graph. This function should return a networkx graph with 19 nodes and 24 edges
Employee_Movie_Choices.txt 에서 데이터 읽어와서 Bipartite Graph를 만드는 함수를 만들어라
def answer_one():
G = nx.read_edgelist('Employee_Movie_Choices.txt', delimiter="\t")
return G
결과 확인
plot_graph(answer_one(), weight_name=None)
Question 2
Using the graph from the previous question, add nodes attributes named 'type' where movies have the value 'movie' and employees have the value 'employee' and return that graph. This function should return a networkx graph with node attributes {'type': 'movie'} or {'type': 'employee'}
Find a weighted projection of the graph from answer_two which tells us how many movies different pairs of employees have in common. This function should return a weighted projected graph.
employees기준으로 가중투영그래프 만들어라
(가중치: 사람A와 사람B가 각각 보겠다고 말한 영화 중, 몇 개가 일치하는가 = 공통영화 수)
Suppose you'd like to find out if people that have a high relationship score also like the same types of movies. Find the Pearson correlation ( using DataFrame.corr() ) between employee relationship scores and the number of movies they have in common. If two employees have no movies in common it should be treated as a 0, not a missing value, and should be included in the correlation calculation. This function should return a float.
관계점수가 높을수록 같은 유형의 영화를 좋아하는지 확인해라
"동료간 관계점수"와 "공통 영화 수" 사이의 Pearson 상관관계를 확인해라(DataFrame.corr() 사용)