日ごとに最も人気のフォーラムを見つける:I
素晴らしいです!いよいよ最後の2つの演習に入ります——といっても、実質はひと続きの演習です。ここまでのPythonスキルの良い復習になりますよ。
任意の時間ウィンドウにおいて「最も人気のフォーラム」の座を獲得したフォーラムがいくつあったかを調べていきます。
この演習はコースの一部です
Python 中級ネットワーク解析
演習の手順
- 日ごとの最も人気のフォーラムのリストを保持する
most_popular_forumsというリストを作成します。 - 最も人気のフォーラムの次数中心性スコアを保持する
highest_dcsというリストを作成します。 - 新しいグラフ
G_subを作成し、.add_nodes_from()メソッドで元のグラフGからノードを追加します。 - 前の演習とまったく同じ条件を満たす元のグラフ
Gのエッジを追加します。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Import necessary modules
from datetime import timedelta
import networkx as nx
import matplotlib.pyplot as plt
# Instantiate a list to hold the list of most popular forums by day: most_popular_forums
most_popular_forums = ____
# Instantiate a list to hold the degree centrality scores of the most popular forums: highest_dcs
highest_dcs = ____
curr_day = dayone
td = timedelta(days=1)
while curr_day < lastday:
if curr_day.day == 1:
print(curr_day)
# Instantiate new graph: G_sub
G_sub = ____
# Add in nodes from original graph G
____
# Add in edges from the original graph G that fulfill the criteria
G_sub.____([(____, ____, ____) for ____, ____, ____ in ____ if d['____'] >= ____ and d['____'] < ____ + ____])
# CODE CONTINUES ON NEXT EXERCISE
curr_day += td