Computer Engineering is coming soon

We're still writing and reviewing the notes for every subject, and we'll open it when every subject is ready. Meanwhile you can practise aptitude, ask Aria about any subject, or see the branches that are ready.

Mining LinkedIn and GitHub

How to collect, represent and mine LinkedIn and GitHub data: APIs, bipartite / projected networks, common measures (co-contribution, Jaccard, cosine), privacy/legality, and example Python code to build user–user networks from sample GitHub JSON.

Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.

Why it matters

Mining LinkedIn and GitHub lets engineers build networks of people, skills and projects to detect communities, recommend collaborators, analyse influence, or find hiring signals. LinkedIn provides professional graph and skill metadata; GitHub provides code collaboration and contribution trails — both are central data sources in social network analysis and mining.

Key ideas

  • Scraping: automated extraction from web pages. Scraping is often against a site’s terms of service (ToS) and may be illegal; prefer official APIs and respect robots.txt and rate limits.

  • Bipartite (two-mode) graph: a graph with two disjoint node sets U and V where edges connect nodes only across sets, not within. Example: users (U) and repositories (V). Draw two vertical columns labeled U (left) and V (right), draw edges between them.

  • Incidence / affiliation matrix B: an n×m matrix where bij = 1 if user i is affiliated to item j (e.g., contributed to repo j), 0 otherwise. If contributions have counts or weights, bij can store those weights.

  • Projection: converting a bipartite graph into a one-mode graph on one set by connecting nodes that share neighbours. For user–user projection, when B is binary the weight of edge (i,k) is the number of shared items: P = B·Bᵀ (then set diagonal to zero if self-edges not wanted). With weighted B, P gives weighted co-affiliations via dot products. Assumptions: contributions are independent, B is correctly constructed (binary or weighted).

    Step-by-step derivation (commonly asked):

    1. Let B be n×m with bij ∈ {0,1}.
    2. Compute multiplication C = B·Bᵀ. Element cik = Σ_j bij·bkj.
    3. cik counts number of items j that both i and k are connected to, therefore the co-affiliation count.
    4. For an unweighted user network, set adjacency A where aik = 1 if cik > 0, else 0. For weighted network use cik as weight.
  • Normalization / similarity measures to avoid bias from prolific users or large repos:

    • Jaccard similarity between users i and k: |N(i) ∩ N(k)| / |N(i) ∪ N(k)|. Use when you care about relative overlap.
    • Cosine similarity (for weighted B): (B_i · B_k)/(||B_i||·||B_k||).
  • Directed vs undirected edges: GitHub follows/forks are directed concepts; contributions and co-contributions produce undirected affiliation edges unless temporal or directionality matters.

  • Metadata and enrichment: user attributes (location, company, skills) and repo attributes (language, topics, stars) help label nodes and produce typed edges or weighted features for clustering or link prediction.

  • Practical constraints: APIs have rate limits, authentication requirements, and privacy restrictions. LinkedIn data access is tightly controlled (most profile fields require partner access). Always document assumptions about access and privacy. For GitHub REST v3, typical limits are 60 requests/hour unauthenticated and 5000/hour with an access token.

Diagrams to draw in answers:

  • For a bipartite graph: draw two columns, left label Users U1..U4, right label Repos R1..R3. Draw edges showing which user contributed to which repo. Then draw projected user–user graph showing edge weights equal to count of shared repos.

Formulas

P = B · Bᵀ — P is the user–user co-affiliation matrix; B is the user×item incidence matrix. (Applies to binary or weighted incidence; set diagonal to zero when self-edges not needed.) c_ik = Σ_j b_ij · b_kj — for binary B, c_ik is the number of shared items between users i and k (dimensionless count); for weighted B, it is the weighted co-affiliation (dot product). (Derived from matrix product.) J(i,k) = |N(i) ∩ N(k)| / |N(i) ∪ N(k)| — Jaccard similarity between users i and k (value between 0 and 1). (Unitless; use when sets are binary.) cos(i,k) = (B_i · B_k) / (||B_i|| · ||B_k||) — Cosine similarity where B_i is i’s row vector in B (unitless). (Use for weighted contributions.)

Syntax and endpoints to remember (examples): GET https://api.github.com/users/{username}/repos — list public repos of username (use Authorization header for higher rate limit). curl -H "Authorization: token <TOKEN>" https://api.github.com/user — get authenticated user in GitHub API. LinkedIn OAuth 2.0 — typical flow: obtain authorization code via user consent, exchange for access token, call endpoints with Authorization: Bearer <token>. (Exact scopes and endpoints may vary.)

Worked examples

Example 1 — build a user–user weighted projection from sample GitHub contribution data (complete Python program). This reads static JSON created below and prints the projected adjacency and similarity.

Program:

# sample_github_projection.py
import json
from math import sqrt

data = {
    "users": ["alice","bob","carol"],
    "repos": ["r1","r2","r3"],
    "contribs": [
        {"user":"alice","repo":"r1"},
        {"user":"alice","repo":"r2"},
        {"user":"bob","repo":"r2"},
        {"user":"bob","repo":"r3"},
        {"user":"carol","repo":"r3"}
    ]
}

users = data["users"]
repos = data["repos"]
idx_u = {u:i for i,u in enumerate(users)}
idx_r = {r:i for i,r in enumerate(repos)}

# Build incidence matrix B (rows users, cols repos)
B = [[0]*len(repos) for _ in users]
for e in data["contribs"]:
    B[idx_u[e["user"]]][idx_r[e["repo"]]] = 1

# Compute P = B·B^T
n = len(users)
P = [[0]*n for _ in range(n)]
for i in range(n):
    for k in range(n):
        s = 0
        for j in range(len(repos)):
            s += B[i][j]*B[k][j]
        P[i][k] = s

# Print weighted adjacency and Jaccard similarity
print("Users:", users)
print("Weighted projection P (counts of shared repos):")
for i in range(n):
    print(users[i], P[i])

print("Jaccard similarity matrix:")
for i in range(n):
    row = []
    for k in range(n):
        inter = P[i][k]
        union = sum(B[i][j] for j in range(len(repos))) + sum(B[k][j] for j in range(len(repos))) - inter
        jacc = inter/union if union>0 else 0.0
        row.append(round(jacc,3))
    print(users[i], row)

Sample input: (none; program uses embedded data)

Exact output:

Users: ['alice', 'bob', 'carol'] Weighted projection P (counts of shared repos): alice [2, 1, 0] bob [1, 2, 1] carol [0, 1, 1] Jaccard similarity matrix: alice [1.0, 0.333, 0.0] bob [0.333, 1.0, 0.5] carol [0.0, 0.5, 1.0]

Bold final answers students should note: user–user shared repo counts are in P; Jaccard shows relative overlap.

Example 2 — prepare GitHub-style attributes for a small link-prediction task (model exam answer): Question: Given user–repo affiliation lists, compute candidate edge score between Alice and Carol using Jaccard and cosine. Model answer (steps):

  1. Lists: N(Alice) = {r1,r2}, N(Carol) = {r3}. Intersection = 0, union = 3 => Jaccard = 0/3 = 0.
  2. B_A = [1,1,0], B_C = [0,0,1], dot = 0, norms = sqrt(2) and 1 => cosine = 0. Conclusion: score 0 (no shared repos), low likelihood of a tie under co-contribution models.

Common mistakes

  • Confusing GitHub stars/forks/watchers with contribution edges — these are different relations and produce different network meanings.
  • Attempting to scrape LinkedIn publicly without checking ToS; student answers must mention policy/authorization requirements.
  • Mixing directed and undirected semantics (e.g., treating follower graph as undirected when computing degree centrality).

For your exam

Types of questions:

  • Definitions: e.g., define bipartite graph, projection, incidence matrix.
  • Short notes: e.g., describe GitHub data fields useful for network mining.
  • Derivations: show algebraic derivation of P = B·Bᵀ and explain diagonal handling.
  • Numericals: compute P and Jaccard on small sample; draw bipartite and projected graphs.
  • Programs: small Python script to parse JSON and compute a projection (like Example 1).

What earns full marks:

  • Precisely define terms (bold them in notes), clearly state assumptions (binary vs weighted B, directedness), show step-by-step matrix multiplication, and include correct handling of diagonal and normalization. If a program is required, make it complete, explain sample input and exact output, and discuss API/legal issues for real data collection.

Quick check

  1. What is a bipartite graph?
  2. Write the matrix formula for user–user co-affiliation counts given incidence matrix B.
  3. Why use Jaccard rather than raw shared-counts when comparing users?

Answers: 1) A graph with two disjoint node sets and edges only across sets. 2) P = B · Bᵀ (then optionally set diagonal to 0). 3) Jaccard normalises for differing activity sizes (it measures relative overlap), avoiding bias from prolific users.

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?