शुरू करेंमुफ़्त में शुरू करें

Students पार्टिशन पर दिन-प्रतिदिन mean degree centrality निकालें

यहाँ, आप जाँचेंगे कि सभी nodes पर mean degree centrality समय के साथ प्लॉट की गई edges की संख्या से सहसंबद्ध है या नहीं। जरूरी नहीं कि मज़बूत सहसंबंध हो — आप ग्राफ़ देखकर समझेंगे कि ऐसा है या नहीं.

यह अभ्यास पाठ्यक्रम का हिस्सा है

इंटरमीडिएट Network Analysis in Python

पाठ्यक्रम देखें

अभ्यास निर्देश

  • G_sub नाम का एक नया ग्राफ बनाएँ जिसमें edges का एक subset हो.
  • node metadata सहित, G से nodes जोड़ें.
  • तय मानदंड पूरे करने वाली edges को .add_edges_from() मेथड से जोड़ें.
  • nx.bipartite.projected_graph() फंक्शन का उपयोग करके G_sub से students प्रोजेक्शन G_student_sub प्राप्त करें.
  • nx.degree_centrality() से students प्रोजेक्शन की degree centrality निकालें (bipartite वाला संस्करण न लें).
  • mean degree centrality को सूची mean_dcs में append करें। ध्यान रखें, पहले dc.values() को list में बदलें.
  • प्लॉट देखने के लिए 'उत्तर सबमिट करें' दबाएँ!

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

from datetime import datetime, timedelta
import numpy as np
import networkx as nx
import matplotlib.pyplot as plt

# Initialize a new list: mean_dcs
mean_dcs = []
curr_day = dayone
td = timedelta(days=2)

while curr_day < lastday:
    if curr_day.day == 1:
        print(curr_day)  
    # Instantiate a new graph containing a subset of edges: G_sub
    G_sub = ____
    # Add nodes from G
    G_sub.____(____)
    # Add in edges that fulfill the criteria
    G_sub.____([(u, v, d) for u, v, d in G.edges(data=True) if d['date'] >= curr_day and d['date'] < curr_day + td])
    
    # Get the students projection
    G_student_sub = ____
    # Compute the degree centrality of the students projection
    dc = ____
    # Append mean degree centrality to the list mean_dcs
    mean_dcs.____(np.mean(____(dc.values())))
    # Increment the time
    curr_day += td
    
plt.plot(mean_dcs)
plt.xlabel('Time elapsed')
plt.ylabel('Degree centrality.')
plt.show()
कोड संपादित करें और चलाएँ