diff --git a/Chatgpt_Assistance/Chatgpt Assitance.md b/Chatgpt_Assistance/Chatgpt Assitance.md new file mode 100644 index 0000000..45cdb5c --- /dev/null +++ b/Chatgpt_Assistance/Chatgpt Assitance.md @@ -0,0 +1,13 @@ +![alt text]() + +![alt text](image.png) + +![alt text](image.png) + +![alt text](image-1.png) + +![alt text](image-2.png) + +https://chatgpt.com/share/690d5399-81cc-800c-8da4-2d7bd14a1c58 + +![alt text]() \ No newline at end of file diff --git a/Chatgpt_Assistance/hi I'm doing a text-analysis assignment and I need code that matches.png b/Chatgpt_Assistance/hi I'm doing a text-analysis assignment and I need code that matches.png new file mode 100644 index 0000000..01c9ba4 Binary files /dev/null and b/Chatgpt_Assistance/hi I'm doing a text-analysis assignment and I need code that matches.png differ diff --git a/Chatgpt_Assistance/image-1.png b/Chatgpt_Assistance/image-1.png new file mode 100644 index 0000000..f4324ba Binary files /dev/null and b/Chatgpt_Assistance/image-1.png differ diff --git a/Chatgpt_Assistance/image-2.png b/Chatgpt_Assistance/image-2.png new file mode 100644 index 0000000..9ee16f2 Binary files /dev/null and b/Chatgpt_Assistance/image-2.png differ diff --git a/Chatgpt_Assistance/image.png b/Chatgpt_Assistance/image.png new file mode 100644 index 0000000..23efe7f Binary files /dev/null and b/Chatgpt_Assistance/image.png differ diff --git a/Code/Code/Part3_Chatgpt.py b/Code/Code/Part3_Chatgpt.py new file mode 100644 index 0000000..261f390 --- /dev/null +++ b/Code/Code/Part3_Chatgpt.py @@ -0,0 +1,394 @@ +#The following code is assited by Chatgpt to create a text analysis of James Harden's 2018 season and playoff performance +#Prompt + +######## +# I’m doing a text-analysis assignment and I need code that matches the instructions. Please generate two Python +# files. First, download_wiki.py that uses the mediawiki Python package to download exactly these Wikipedia pages: “James Harden”, +# “2017–18 Houston Rockets season”, and “2018 Western Conference Finals”; clean the text by removing bracketed citations like [1] +# and extra newlines; then save them to a JSONL file called harden_2018_season_vs_playoff.jsonl, one JSON object per line with "title" +# and "content". Second, text_analysis.py that loads that JSONL, tokenizes with a custom stopword list, builds bag-of-words per document, +# prints top 15 words per document, finds words frequent in the season page but not the WCF page (and vice versa), computes cosine similarity +# between the three page pairs, showing a text bar for the score, and extracts top 15 proper names (capitalized words) per document. Both files +# must end with if __name__ == "__main__": main() so they can be run directly. Don’t use pandas or numpy. Add brief comments noting that some functions +# (like cosine and JSONL saving) were learned from AI/online sources. + + + +import os +import json +import re +from collections import Counter +from math import sqrt +from typing import Dict, List + +from mediawiki import MediaWiki # type: ignore +import matplotlib.pyplot as plt # type: ignore + + +JSONL_NAME = "harden_2018_season_vs_playoff.jsonl" +TITLES = [ + "James Harden", + "2017–18 Houston Rockets season", + "2018 Western Conference Finals", +] +SEASON = "2017–18 Houston Rockets season" +WCF = "2018 Western Conference Finals" + +STOP = { + "the","and","a","an","of","for","to","in","on","at","as","by","from","with","it", + "its","is","are","was","were","be","been","being","that","this","these","those", + "or","not","no","but","so","if","into","than","then","their","his","her","they", + "them","he","she","we","you","your","our","i","over","after","before","during", + "within","without","between","about","also","such","there","here","up","down" +} + +_CIT = re.compile(r"\[.*?\]") +_NL = re.compile(r"\n+") + +#Follwing gets the current directory of this file + +HERE = os.path.dirname(os.path.abspath(__file__)) + +def find_jsonl() -> str: + """Return the path to the JSONL file, checking current and parent directory. + + Checks two candidate paths (local folder and parent folder). If neither exists, + returns the default expected location in the current folder. + """ + candidates = [ + os.path.join(HERE, JSONL_NAME), + os.path.join(HERE, "..", JSONL_NAME), + ] + for p in candidates: + p = os.path.abspath(p) + if os.path.exists(p): + return p + # default to current folder if not found + return os.path.join(HERE, JSONL_NAME) + +# Following function cleans the text by removing citations and replacing newlines with spaces. + +def clean_text(text: str) -> str: + """Remove bracketed citations like [1] and collapse repeated newlines into spaces. + + Returns cleaned text. Empty input returns an empty string. + """ + if not text: + return "" + text = _CIT.sub("", text) + text = _NL.sub(" ", text) + return text.strip() + +def fetch_page(title: str): + """Fetch a Wikipedia page object using the MediaWiki package.""" + wiki = MediaWiki() + return wiki.page(title) + +def harvest_titles(titles: List[str], preview_chars: int = 600) -> Dict[str, str]: + """ + Download Wikipedia pages, print short previews, clean text, and return a dict. + Args: + titles: list of Wikipedia page titles to fetch. + preview_chars: number of characters to preview in console. + Returns: + Dict mapping page title → cleaned text. + """ + docs: Dict[str, str] = {} + for t in titles: + page = fetch_page(t) + print(page.title) + print(page.content[:preview_chars], "...\n") + docs[page.title] = clean_text(page.content) + return docs + +def save_jsonl(docs: Dict[str, str], path: str): + """ + Save documents to a JSONL file, one JSON object per line. + + Note: + JSONL-saving logic was learned from AI/online tutorials. + """ + with open(path, "w", encoding="utf-8") as f: + for title, content in docs.items(): + f.write(json.dumps({"title": title, "content": content}, ensure_ascii=False) + "\n") + +def ensure_jsonl(path: str): + """ + Ensure the JSONL exists; if not, download pages and write them to disk. + """ + + if os.path.exists(path): + print(f"[info] using existing JSONL at {path}") + return + print("[info] JSONL not found, downloading from Wikipedia with mediawiki...") + docs = harvest_titles(TITLES, preview_chars=800) + save_jsonl(docs, path) + print(f"[info] saved {path} with {len(docs)} docs.") + +#Following function loads JSON lines from a file and returns a dictionary of titles and their corresponding content + +def load_jsonl(path: str): + + """ + Load a JSONL file and return a dict of title → content strings. + """ + + docs = {} + with open(path, "r", encoding="utf-8") as f: + for line in f: + obj = json.loads(line) + title = obj.get("title", "").strip() + if title: + docs[title] = obj.get("content", "") + return docs + +def tokens(text): + + """ + Tokenize text into lowercase words, removing punctuation and custom stopwords. + """ + out = [] + for w in text.split(): + w = w.strip(".,!?;:\"()[]{}<>''``“”’").lower() + if w and w not in STOP and len(w) > 1: + out.append(w) + return out + +def bow(text): + """ + Build a bag-of-words Counter from text tokens. + """ + return Counter(tokens(text)) + +def top_n(c, n=15): + """ + Return the top-n most common elements from a Counter. + """ + return c.most_common(n) + +def unique_freq(a, b, thr=5): + """ + Return items frequent in dict a but not in b, based on a threshold. + """ + items = [(w, ca) for w, ca in a.items() if ca >= thr and b.get(w, 0) < thr] + items.sort(key=lambda x: x[1], reverse=True) + return items + +def cosine(a, b): + """ + Compute cosine similarity between two bag-of-words Counters. + """ + if not a or not b: + return 0.0 + dot = sum(a[w]*b.get(w,0) for w in a) + na = sqrt(sum(v*v for v in a.values())) + nb = sqrt(sum(v*v for v in b.values())) + return 0.0 if na==0 or nb==0 else dot/(na*nb) + +def proper_names(text, k=15): + """ + Extract top-k capitalized words (length ≥ 3) interpreted as proper names. + """ + c = Counter() + for w in text.split(): + w = w.strip(".,!?;:\"()[]{}<>''``“”’") + if w.istitle() and len(w) >= 3: + c[w] += 1 + return c.most_common(k) + +def bar(x, scale=20): + """ + Return a simple unicode bar proportional to similarity score. + """ + return "█" * int(round(x * scale)) + +# Following function ensures that the figures directory exists + +def ensure_fig_dir(): + """ + Ensure that a ./figures directory exists; create it if needed and return path. + """ + figdir = os.path.join(HERE, "figures") + if not os.path.exists(figdir): + os.makedirs(figdir) + return figdir + +def slugify(s: str) -> str: + """ + Convert a title string into a filesystem-safe slug for filenames. + """ + return ( + s.lower() + .replace(" ", "_") + .replace("–", "-") + .replace("—", "-") + .replace("/", "_") + .replace("(", "") + .replace(")", "") + ) + +def shorten(s: str, maxlen=30) -> str: + """ + Shorten string for display if longer than maxlen. + """ + return s if len(s) <= maxlen else s[:maxlen-3] + "..." + +def plot_top_words_per_doc(bows, top=15): + """ + Generate horizontal bar charts of top words per document and save to ./figures. + """ + figdir = ensure_fig_dir() + for title, counter in bows.items(): + common = counter.most_common(top) + if not common: + continue + words = [w for w, _ in common][::-1] + counts = [c for _, c in common][::-1] + plt.figure(figsize=(8,5)) + plt.barh(words, counts) + plt.title(f"Top {top} words: {title}") + plt.xlabel("Count") + plt.tight_layout() + plt.savefig(os.path.join(figdir, f"topwords_{slugify(title)}.png"), dpi=150) + plt.close() + +def plot_season_vs_wcf(bows, thr=5, top=20): + """ + Plot words frequent in the SEASON doc but not WCF (and vice versa). + """ + if SEASON not in bows or WCF not in bows: + return + figdir = ensure_fig_dir() + season = bows[SEASON] + wcf = bows[WCF] + + season_unique = [(w, c) for w, c in season.items() if c >= thr and wcf.get(w, 0) < thr] + wcf_unique = [(w, c) for w, c in wcf.items() if c >= thr and season.get(w, 0) < thr] + + season_unique.sort(key=lambda x: x[1], reverse=True) + wcf_unique.sort(key=lambda x: x[1], reverse=True) + + season_unique = season_unique[:top] + wcf_unique = wcf_unique[:top] + + if season_unique: + words = [w for w, _ in season_unique][::-1] + counts = [c for _, c in season_unique][::-1] + plt.figure(figsize=(8,5)) + plt.barh(words, counts) + plt.title("Words common in SEASON but not WCF") + plt.xlabel("Count") + plt.tight_layout() + plt.savefig(os.path.join(figdir, "season_unique.png"), dpi=150) + plt.close() + + if wcf_unique: + words = [w for w, _ in wcf_unique][::-1] + counts = [c for _, c in wcf_unique][::-1] + plt.figure(figsize=(8,5)) + plt.barh(words, counts) + plt.title("Words common in WCF but not SEASON") + plt.xlabel("Count") + plt.tight_layout() + plt.savefig(os.path.join(figdir, "wcf_unique.png"), dpi=150) + plt.close() + +def plot_cosine_heatmap(bows): + """ + Plot a cosine similarity heatmap comparing all documents. + """ + figdir = ensure_fig_dir() + titles = list(bows.keys()) + n = len(titles) + if n == 0: + return + mat = [[0.0 for _ in range(n)] for _ in range(n)] + for i in range(n): + for j in range(n): + mat[i][j] = cosine(bows[titles[i]], bows[titles[j]]) + plt.figure(figsize=(5 + n*0.4, 5 + n*0.4)) + plt.imshow(mat, cmap="viridis", vmin=0, vmax=1) + plt.colorbar(label="Cosine similarity") + plt.xticks(range(n), [shorten(t) for t in titles], rotation=45, ha="right") + plt.yticks(range(n), [shorten(t) for t in titles]) + plt.title("Document similarity (cosine)") + plt.tight_layout() + plt.savefig(os.path.join(figdir, "cosine_heatmap.png"), dpi=150) + plt.close() + +def plot_proper_names_all(docs): + """ + Plot bar charts of the top proper names for each document. + """ + figdir = ensure_fig_dir() + for title, text in docs.items(): + names = proper_names(text, 15) + if not names: + continue + labels = [n for n, _ in names][::-1] + counts = [c for _, c in names][::-1] + plt.figure(figsize=(8,5)) + plt.barh(labels, counts) + plt.title(f"Top names in {title}") + plt.xlabel("Count") + plt.tight_layout() + plt.savefig(os.path.join(figdir, f"names_{slugify(title)}.png"), dpi=150) + plt.close() + +#Following is the main function that runs the entire analysis + +def main(): + """ + Plot bar charts of the top proper names for each document. + """ + # 1) find / make JSONL + jsonl_path = find_jsonl() + ensure_jsonl(jsonl_path) + + # 2) load docs + docs = load_jsonl(jsonl_path) + if not docs: + print("[error] Loaded 0 documents.") + return + + # 3) text analysis + bows = {t: bow(txt) for t, txt in docs.items()} + + print("\n=== Top Words per Document ===") + for t, c in bows.items(): + print(f"\n{t}") + for w, n in top_n(c, 15): + print(f" {w:<18} {n}") + + if SEASON in bows and WCF in bows: + print("\n=== Frequent in SEASON but not WCF (thr=5) ===") + for w, n in unique_freq(bows[SEASON], bows[WCF], 5)[:20]: + print(f" {w:<18} {n}") + + print("\n=== Frequent in WCF but not SEASON (thr=5) ===") + for w, n in unique_freq(bows[WCF], bows[SEASON], 5)[:20]: + print(f" {w:<18} {n}") + + print("\n=== Cosine Similarity ===") + pairs = [("James Harden", SEASON), ("James Harden", WCF), (SEASON, WCF)] + for a, b in pairs: + if a in bows and b in bows: + s = cosine(bows[a], bows[b]) + print(f" {a} ↔ {b}\n {s:.3f} {bar(s)}") + + print("\n=== Proper Names (top 15) ===") + for t, txt in docs.items(): + print(f"\n{t}") + for name, n in proper_names(txt, 15): + print(f" {name:<18} {n}") + + # 4) charts + print("\n[info] generating charts in ./figures ...") + plot_top_words_per_doc(bows) + plot_season_vs_wcf(bows) + plot_cosine_heatmap(bows) + plot_proper_names_all(docs) + print("[info] done. check the 'figures' folder.") + +if __name__ == "__main__": + main() diff --git a/Code/Code/Text_Analysis.py b/Code/Code/Text_Analysis.py new file mode 100644 index 0000000..7d1832c --- /dev/null +++ b/Code/Code/Text_Analysis.py @@ -0,0 +1,169 @@ +#This code is a text anlysis of 2017-2018 James Harden Wikipedia Article and also the 2018 Western Conference Finals. + +#Counter is recommended by chatgpt for word counting +from collections import Counter +from math import sqrt +import json, os + +#This explains which WCF it is and the JSONL and the Season +JSONL = "harden_2018_season_vs_playoff.jsonl" +SEASON = "2017-18 Houston Rockets season" +WCF = "2018 Western Conference Finals" + +# This is a stop list provided by chatgpt to remove common words from analysis +STOP = { + "the","and","a","an","of","for","to","in","on","at","as","by","from","with","it", + "its","is","are","was","were","be","been","being","that","this","these","those", + "or","not","no","but","so","if","into","than","then","their","his","her","they", + "them","he","she","we","you","your","our","i","over","after","before","during", + "within","without","between","about","also","such","there","here","up","down" +} + +def load_jsonl(path=JSONL): + """Load a JSONL file and return a dictionary mapping title → content. + + Reads UTF-8 to support special characters in Wikipedia text. + Each line is parsed as a JSON object containing "title" and "content". + """ + docs = {} + with open(path, "r", encoding="utf-8") as f: + for line in f: + obj = json.loads(line) + title = obj.get("title", "").strip() + if title: + docs[title] = obj.get("content", "") + return docs + +def tokens(text): + """Tokenize text into cleaned, lowercase words. + + Steps: + - Split on whitespace + - Remove punctuation characters + - Convert to lowercase + - Remove stopwords and single-character tokens + Returns: + A list of valid tokens. + """ + out = [] + for w in text.split(): + w = w.strip(".,!?;:\"()[]{}<>''``“”’").lower() + if w and w not in STOP and len(w) > 1: + out.append(w) + return out + +def bow(text): + """Return a bag-of-words Counter for the given text using tokenized words.""" + return Counter(tokens(text)) + +def top_n(c, n=15): + """Return the top n most common words from a Counter.""" + return c.most_common(n) + +def unique_freq(a, b, thr=5): + """Find words frequent in document A but not in B. + + Args: + a, b: Counter objects + thr: minimum count threshold + + Returns: + List of (word, count) pairs sorted by frequency. + """ + items = [(w, ca) for w, ca in a.items() if ca >= thr and b.get(w, 0) < thr] + items.sort(key=lambda x: x[1], reverse=True) + return items + +def cosine(a, b): + """Compute cosine similarity between two bag-of-words Counters. + + Formula: + dot(a, b) / (||a|| * ||b||) + + Notes: + - dot product sums shared word contributions + - learned from online/AI examples + """ + if not a or not b: return 0.0 + dot = sum(a[w]*b.get(w,0) for w in a) + na = sqrt(sum(v*v for v in a.values())) + nb = sqrt(sum(v*v for v in b.values())) + return 0.0 if na==0 or nb==0 else dot/(na*nb) + +def proper_names(text, k=15): + """Return the top-k capitalized words interpreted as proper names. + + A word qualifies if: + - It begins with an uppercase letter (Python's istitle()) + - Has length ≥ 3 + """ + c = Counter() + for w in text.split(): + w = w.strip(".,!?;:\"()[]{}<>''``“”’") + if w.istitle() and len(w) >= 3: + c[w] += 1 + return c.most_common(k) + +def bar(x, scale=20): + """Return a simple bar made of unicode blocks scaled to x (0–1 range).""" + return "█" * int(round(x*scale)) + +def analyze(docs): + """Run the full textual analysis workflow. + + Steps: + 1. Build bag-of-words for all documents. + 2. Print top frequent words per document. + 3. Print words frequent in Season but not WCF (and vice versa). + 4. Compute cosine similarity for key document pairs. + 5. Extract and print top proper names. + """ + bows = {t: bow(txt) for t, txt in docs.items()} + + print("\n=== Top Words per Document ===") + for t, c in bows.items(): + print(f"\n{t}") + for w, n in top_n(c, 15): + print(f" {w:<18} {n}") + + if SEASON in bows and WCF in bows: + print("\n=== Frequent in SEASON but not WCF (thr=5) ===") + for w, n in unique_freq(bows[SEASON], bows[WCF], 5)[:20]: + print(f" {w:<18} {n}") + + print("\n=== Frequent in WCF but not SEASON (thr=5) ===") + for w, n in unique_freq(bows[WCF], bows[SEASON], 5)[:20]: + print(f" {w:<18} {n}") + + print("\n=== Cosine Similarity ===") + pairs = [("James Harden", SEASON), ("James Harden", WCF), (SEASON, WCF)] + for a, b in pairs: + if a in bows and b in bows: + s = cosine(bows[a], bows[b]) + print(f" {a} ↔ {b}\n {s:.3f} {bar(s)}") + + print("\n=== Proper Names (top 15) ===") + for t, txt in docs.items(): + print(f"\n{t}") + for name, n in proper_names(txt, 15): + print(f" {name:<18} {n}") + +def main(): + """Load JSONL file and run the Harden season vs WCF text analysis. + + Ensures: + - JSONL exists + - At least one document is successfully loaded + Then calls analyze(). + """ + if not os.path.exists(JSONL): + print("[error] JSONL not found. Run Part 1 first.") + return + docs = load_jsonl(JSONL) + if not docs: + print("[error] Loaded 0 documents.") + return + analyze(docs) + +if __name__ == "__main__": + main() diff --git a/Code/Code/Wikipedia_Downlaod.py b/Code/Code/Wikipedia_Downlaod.py new file mode 100644 index 0000000..2a48b93 --- /dev/null +++ b/Code/Code/Wikipedia_Downlaod.py @@ -0,0 +1,67 @@ +# Within my Macbook Terminal, I have already downloaded "conda install -c conda-forge pymediawiki" + +from mediawiki import MediaWiki # type: ignore +w = MediaWiki() +p = w.page("James Harden") +print(p.title, " — chars:", len(p.content)) + +#"re" for (remove [1] style citations + newlines) (Chatgpt suggested) +import re + +# "json" to write our results to a .jsonl file (one JSON object per line)(Chatgpt suggested) +import json + + +from typing import Dict, List + +# _CIT will find anything inside square brackets (prompted by chatgpt) +#_NL will find one or more newline characters (prompted by chatgpt) +_CIT = re.compile(r"\[.*?\]") +_NL = re.compile(r"\n+") + +#The following function cleans the text by removing citations and replacing newlines with spaces. +def clean_text(text: str) -> str: + if not text: + return "" + text = _CIT.sub("", text) #Remoove bracketed citations + text = _NL.sub(" ", text) # Turn multiple newlines into one single space + return text.strip() + +#The following funtion searches for a Wikipedia page by its title and returns the page object. +#Page.Title is the title of the page and the page.content is the full text of the article +#Fetch is also suggested by Chatg +def fetch_page(title: str): + wikipedia = MediaWiki() + page = wikipedia.page(title) + return page + +#From what we learned in class, I will be using a dictionary to store the titles and their corresponding cleaned text. +#Multiple pages will be downloaded at a time in a loop and stored in a dictionary. +#The output should be {"title" : "cleaned article text"} +def harvest_titles(titles: List[str], preview_chars: int = 600) -> Dict[str, str]: + """Returns dict[title -> cleaned_text] and prints title + preview (per the doc).""" + docs: Dict[str, str] = {} + for t in titles: + page = fetch_page(t) + print(page.title) + print(page.content[:preview_chars], "...\n") + #Following line of code stores the cleaned text in the dictionary + docs[page.title] = clean_text(page.content) + return docs + +#Save the documents to a JSONL file, where each line is a JSON object with "title" and "content" fields. +def save_jsonl(docs: Dict[str, str], path: str) -> None: + with open(path, "w", encoding="utf-8") as f: + for title, content in docs.items(): + f.write(json.dumps({"title": title, "content": content}, ensure_ascii=False) + "\n") + +# --- tiny runner so the file actually does something when executed --- +if __name__ == "__main__": + TITLES = [ + "James Harden", + "2017–18 Houston Rockets season", + "2018 Western Conference Finals" + ] + docs = harvest_titles(TITLES, preview_chars=800) + save_jsonl(docs, "harden_2018_season_vs_playoff.jsonl") + print("\nSaved harden_2018_season_vs_playoff.jsonl with", len(docs), "docs.") diff --git a/Code/figures/cosine_heatmap.png b/Code/figures/cosine_heatmap.png new file mode 100644 index 0000000..aea58d8 Binary files /dev/null and b/Code/figures/cosine_heatmap.png differ diff --git a/Code/figures/harden_2018_season_vs_playoff.jsonl b/Code/figures/harden_2018_season_vs_playoff.jsonl new file mode 100644 index 0000000..5408a89 --- /dev/null +++ b/Code/figures/harden_2018_season_vs_playoff.jsonl @@ -0,0 +1,3 @@ +{"title": "James Harden", "content": "James Edward Harden Jr. (born August 26, 1989) is an American professional basketball player for the Los Angeles Clippers of the National Basketball Association (NBA). He is widely regarded as one of the greatest shooting guards and scorers in NBA history. In 2021, Harden was honored as one of the league's top 75 players by being named to the NBA 75th Anniversary Team. Harden is also a two-time member of the United States national team, winning gold medals at the 2012 Summer Olympics and 2014 FIBA World Cup. Harden is nicknamed \"the Beard\" after his characteristic facial hair. Harden played college basketball for the Arizona State Sun Devils, where he was named a consensus All-American and Pac-10 Player of the Year in 2009. Harden was selected with the third overall pick in the 2009 NBA draft by the Oklahoma City Thunder. In 2012, he was named NBA Sixth Man of the Year and helped Oklahoma City reach the NBA Finals, where they lost to the Miami Heat in five games. After the Thunder refused to offer him a max contract extension, Harden was unwilling to take a pay cut and was subsequently traded to the Houston Rockets before the 2012–13 season. In his first season with the Rockets, Harden set or matched several team records and was named to his first All-NBA Team (a third-team selection), as well as his first NBA All-Star team. Over the next seven full seasons with Houston, Harden led the league in scoring three times and assists once, and was named the NBA Most Valuable Player in 2018 while leading the Rockets to the Western Conference Finals. He was also named to seven consecutive NBA All-Star teams and earned All-NBA First Team honors six times. After requesting a trade at the beginning of the 2020–21 season, Harden was traded to the Brooklyn Nets as part of a four-team trade. With Brooklyn, he was named to his ninth and tenth consecutive All-Star games before being traded to the Philadelphia 76ers at the 2022 trade deadline. In 2023, Harden led the league in assists for the second time in his career. He was traded to the Clippers at the start of the 2023–24 season and was named to his 11th All-Star Game in 2025. == High school career == Harden attended Artesia High School in Lakewood, California. In his sophomore year, he averaged 13.2 points as Artesia went 28–5. He improved his stats to 18.8 points, 7.7 boards and 3.5 assists in his junior season and led Artesia to the California state title and a 33–1 record. Artesia repeated as state champions in Harden's final year after going 33–2. Harden had similar stats during the previous season: 18.8 points, 7.9 rebounds, and 3.9 assists. He was named a McDonald's All-American, and also earned second-team Parade All-American honors. He also helped his AAU team, Pump-N-Run Elite, to the 2006 Las Vegas Adidas Super 64 championship. Harden had 34 points in the victory over a DC Assault team which included Michael Beasley, Nolan Smith and Austin Freeman. In the game against Houston Hoops, played on the same day, Harden had 33 points. In the final, Pump-N-Run Elite beat Kevin Love's Southern California All-Stars. == College career == In Harden's freshman year, Arizona State was picked to finish ninth in the Pac-10 Conference. Behind his 17.8 points, 5.3 rebounds and 3.2 assists per game, the Sun Devils went 21–13 (9–9) and finished tied for fifth in the Pac-10. They were considered a bubble team for the 2008 NCAA tournament. Left out of the tournament, they were selected to the 2008 NIT field and defeated Alabama State and Southern Illinois before falling to defending national champion Florida. After his freshman year, Harden was named first-team All-Pac-10 and was named to the conference all-freshman team. He was also named first team All-District by the NABC and the USBWA. Entering his sophomore year, Harden appeared on many pre-season All-American lists and on the cover of the Sports Illustrated college basketball preview issue. He was named to the Wooden Award preseason watch list. On November 30, 2008, Harden scored a career-high 40 points in an 88–58 victory over UTEP. Harden finished his sophomore campaign with averages of 20.1 points, 5.6 rebounds, and 4.2 assists. He was named to the 2009 All-Pac 10 Tournament Team following Arizona State's defeat by USC at the Staples Center. Following the conference season, Harden was named the Pacific-10 Conference's Player of the Year. He was also named a consensus All-American. After the conclusion of the season (a second-round NCAA tournament loss to Syracuse), Harden declared for the 2009 NBA draft. He employed Rob Pelinka as his agent. == Professional career == === Oklahoma City Thunder (2009–2012) === Harden was selected with the third overall pick in the 2009 NBA draft by the Oklahoma City Thunder. He recorded the fourth highest 3-point percentage in NBA history (.375) for a player under the age of 21 (minimum of 150 attempts) during the 2009–10 season. He connected on seven straight 3-point field goals over two games (November 18 and 20), recording the most consecutive 3-point makes by a rookie since Houston guard Michael Dickerson made eight straight in May 1999. He was named to the NBA All-Rookie Second Team at the conclusion of the season. During the 2010–11 season, he scored 10-plus points on 54 occasions, including a season-high 26 points against the Phoenix Suns on March 6, 2011. Harden averaged 16.8 points, 4.1 rebounds and 3.7 assists in 62 games (two starts) during the lockout-shortened 2011–12 season, as he received the NBA Sixth Man of the Year Award. Harden scored in double-figures in all but four of his appearances during the season. He scored a season-high 40 points against Phoenix on April 18, 2012, becoming the first NBA player in a reserve role to score 40 points since Dallas guard Rodrigue Beaubois in March 2010. Harden helped the Thunder reach the 2012 NBA Finals, where they were defeated in five games by the Miami Heat. During the 2012 free agency period, Oklahoma City attempted to sign Harden to a four-year contract extension worth between $52 and $55 million. Harden later contended that he was given too little time to consider the offer. === Houston Rockets (2012–2021) === ==== 2012–2013: First All-Star and All-NBA selections ==== After failing to agree on a contract extension with the Thunder, Harden was traded to the Houston Rockets on October 27, 2012, along with Daequan Cook, Cole Aldrich and Lazar Hayward, in exchange for Kevin Martin, Jeremy Lamb, two first round picks (which became Steven Adams in 2013 and Mitch McGary in 2014), and a second round pick (which became Álex Abrines in 2013). Rockets general manager Daryl Morey called Harden a \"foundational\" player and expected him to be Houston's featured player despite previously only playing a supporting role behind Kevin Durant and Russell Westbrook. On October 31, 2012, Harden signed a contract extension with the Rockets for five years worth $80 million. That same day, he became the first-ever NBA player to score 37 or more points while registering a double-digit assist total in his team debut, posting 37 points, a career-high 12 assists, six rebounds, four steals and one block in a 105–96 win over the Detroit Pistons. He became just the fourth NBA player in the last 25 years to post those totals in a single game and matched the third-highest point total for any NBA player in his team debut (most for Rockets debut). Two days later, he scored 45 points against the Atlanta Hawks. His 82 total points were the most scored by a player in his first two games with a team in NBA history, surpassing the previous mark held by Wilt Chamberlain, who scored 79 points in his first two career games with the Philadelphia Warriors in 1959. He registered the first triple-double of his career on February 2, 2013, against the Charlotte Bobcats, recording 21 points, 11 rebounds and 11 assists. Harden was named as a reserve for the 2013 NBA All-Star Game, marking his first All-Star selection. He recorded 15 points, six rebounds and three assists in a 143–138 win by the West over the East. On February 20, 2013, Harden scored a career-high 46 points in a 122–119 win over his former team, the Oklahoma City Thunder. Harden had one of the greatest statistical seasons in team history in his first campaign with Houston. He became just the fifth player in team history to reach 2,000 points in one campaign (2,023 points). He surpassed Moses Malone's team mark for free throws made in a season (630 FTM in 1981–82), joining Malone as the only two Rockets players to ever reach 600 free throws made in a single season. Harden joined Gilbert Arenas (2005–06 and 2006–07), Kobe Bryant (2005–06 and 2007–08) and Jerry Stackhouse (2000–01) as the only four players in NBA history to record at least 600 free throws made and hit 150 or more 3-pointers in one season. Harden joined Tracy McGrady (four times in 2004–05) and Hakeem Olajuwon (three times in 1992–93) as the only Rockets to ever capture Player of the Week honors three or more times in one season. He was named to the 2012–13 All-NBA Third Team, marking his first career All-NBA Team selection while becoming just the seventh player in Rockets history to earn All-NBA recognition. ==== 2013–2014: First All-NBA First Team selection ==== Harden was selected by the head coaches as a reserve for the 2014 NBA All-Star Game, which marked his second consecutive All-Star selection. He was later named as a replacement starter for the All-Star Game. He was the first Rockets player ever to pick up Western Conference Player of the Week honors in consecutive weeks in the same season (February 24 – March 2; March 3–9). On December 26, 2013, against the Memphis Grizzlies, Harden became the first player in NBA history to register at least 27 points on two or fewer field goals made (2–9 FG), finishing with a career best 22-of-25 from the stripe and tying the Rockets single-game record for free throws made (22–27 FT by Sleepy Floyd in February 1991). On February 5, 2014, against the Phoenix Suns, Harden became just the third player to score at least 3,000 points in his first 120 games played with the Rockets, joining Elvin Hayes (3,320) and Tracy McGrady (3,056). On February 25, 2014, he scored a season-high 43 points in a 129–103 win over the Sacramento Kings. At the season's end, he earned All-NBA First Team honors. ==== 2014–2016: Second in MVP voting and turnovers record ==== Over the first two months of the season, Harden was in MVP contention with scoring over 40 points 3 times in a 6 game stretch. In April 2015, he became the first player in franchise history to have two 50-point games in a season. He helped the Rockets win their first division title since 1994 and clinched the No. 2 seed in the Western Conference. Harden was again named to the All-NBA First Team, and finished second in the NBA MVP voting behind Stephen Curry. Harden was later voted the inaugural National Basketball Players Association's MVP for the 2014–15 season. In Game 5 of the Rockets' second round playoff series against the Los Angeles Clippers, Harden recorded his first career playoff triple-double with 26 points, 11 rebounds and 10 assists. McHale benched Harden in the 4th quarter when the Rockets came back to win Game 6 against the Clippers. In Game 4 of the Western Conference Finals against the Golden State Warriors, Harden scored a playoff career-high 45 points. In Game 5 of the Western Conference Finals, Harden had a forgettable finale, with a playoff-record 13 turnovers and 14 points on 2-of-11 shooting. In November 2015, Harden became the first Rocket to score 43-plus points in consecutive games since Malone had two streaks of three games doing so during the 1981–82 season. On November 18, head coach Kevin McHale was fired after the Rockets began the season with a 4–7 record. McHale later believed Harden had intentionally showed up to camp overweight to get McHale fired in retaliation for benching him in the Clippers series. On January 20, Harden became the first player to have at least 33 points, 17 rebounds and 14 assists in a game since Wilt Chamberlain had 53 points, 32 rebounds and 14 assists for Philadelphia in March 1968. Harden finished March with 457 points, 152 assists and 102 rebounds, becoming the first player to record at least 450 points, 150 assists and 100 rebounds in a single month since Oscar Robertson did it in December 1967. Harden finished the 2015–16 season with 374 turnovers, beating Artis Gilmore's mark of 366 in 1977–78, the first season the NBA recorded turnovers. Harden set career marks in points (29), assists (7.5) and rebounds (6.1) to join LeBron James, Michael Jordan and Oscar Robertson as the only players in NBA history to average at least 29 points, seven assists and six rebounds in a season. ==== 2016–2017: Point guard role and leading the NBA in assists ==== On July 9, 2016, Harden signed a four-year, $118.1 million contract extension with the Rockets. In September 2016, new Rockets head coach Mike D'Antoni announced that Harden would take on the point guard role to begin the 2016–17 season. In the Rockets' season opener on October 26, Harden had 34 points, a career-high 17 assists, and eight rebounds in a 120–114 loss to the Los Angeles Lakers, becoming just the second player in NBA history to record at least 30 points and 15 assists in an opener; Tim Hardaway had 32 and 18 for the Golden State Warriors in 1990. On December 14, he recorded 15 points, 14 assists and 11 rebounds against the Sacramento Kings, the 14th triple double of his career, tying him with Hakeem Olajuwon for most in franchise history. He set the franchise record two days later in the Rockets' 122–110 win over the New Orleans Pelicans, Harden helped the team set an NBA-record with 24 three-pointers, as he finished with 29 points, 11 rebounds and 13 assists. On December 23, he tied a career high with 17 assists in a 115–109 loss to the Memphis Grizzlies. On December 31, 2016, Harden recorded another triple-double with 53 points, 17 assists and 16 rebounds in a 129–122 win over the New York Knicks, becoming the first player in NBA history to finish with a 50–15–15 stat line. He tied Wilt Chamberlain for the most points in a triple-double in NBA history—Chamberlain pulled the feat during the 1967–68 season, with 53 points, 32 rebounds and 14 assists. Harden set career highs for points and three-pointers (with nine) and matched his career best for assists. It was his 17th career triple-double and his fourth career 50-point game. Two days later, he recorded his ninth triple-double of the season in a win over the Washington Wizards and was named Western Conference Player of the Week for a third time. It was Harden's 12th Player of the Week honor, matching Hakeem Olajuwon for the most Player of the Week awards in franchise history. Harden's career-best December run earned him Western Conference Player of the Month honors. His 10th and 11th triple-doubles on January 8 and 10 in Rockets wins saw him become the fourth player in NBA history with at least 40 points, 10 rebounds and 10 assists in consecutive games—Pete Maravich, Michael Jordan and Russell Westbrook are the three others to do it. On January 27, he recorded his 14th triple-double of the season with 51 points, 13 rebounds and 13 assists in a 123–118 win over the Philadelphia 76ers, becoming the first player in NBA history with multiple 50-point triple-doubles in a season. On February 3 against the Chicago Bulls, Harden scored his 10,000th point as a Rocket, passing Yao Ming for sixth place in franchise history. On February 11, he scored 40 points in three quarters (his ninth 40-point game of the season) to help the Rockets win 133–102 over the Phoenix Suns. He played just 29 minutes against the Suns to become the first Rockets player since Sleepy Floyd in 1991 to score 40 points in less than 30 minutes. Between March 12 and 18, he had four straight triple-doubles, giving him 19 for the season. He finished the regular season with 22 triple-doubles and became the first player in NBA history to finish the regular season with at least 2,000 points (2,356), 900 assists (907) and 600 rebounds (659). He also ended the regular season as the league leader in assists, averaging 11.2 assists per game. He placed second in league MVP voting to former teammate Westbrook. In Game 5 of the Rockets' second round playoff series against the San Antonio Spurs, Harden recorded his second career postseason triple-double with 33 points, 10 rebounds and 10 assists in a 110–107 overtime loss; the loss saw the Rockets go down 3–2 in the series. The Rockets were eliminated by the Spurs with a 114–75 loss in Game 6. Harden tied his season low of 10 points, shooting 2-of-11 before fouling out with 3:15 remaining. ==== 2017–2018: MVP season and scoring title ==== On July 8, 2017, Harden signed a four-year contract extension with the Rockets for approximately $160 million, giving him a total six-year deal with $228 million guaranteed—the richest contract in NBA history. On November 5, he scored a career-high 56 points in a 137–110 win over the Utah Jazz, falling just shy of Calvin Murphy's 57-point franchise record set in 1978. Harden joined Wilt Chamberlain as the only players in NBA history to have at least 10 assists and shoot better than 75 percent from the field in a 50-point performance. He went on to become the first player in team history to score at least 20 points in each of the team's first 20 games of a season. Harden was named Western Conference Player of the Month for games played in October and November, marking the fifth time Harden has received the honor, all coming as a Rocket. On December 9, he scored 48 points against the Portland Trail Blazers to become only the second player to score at least 20 points in each of the first 24 games since the 1990–91 season. On December 20, despite Harden's 51 points, the Rockets were defeated 122–116 by the Los Angeles Lakers, ending their 14-game winning streak. Harden set a franchise record by scoring at least 20 points in his 30th straight game. The previous record was held by Malone, who did it in 29 straight games in the 1981–82 season. Two days later, Harden had a second straight 51-point performance in a 128–118 loss to the Los Angeles Clippers. It was Harden's third 50-point game of the season and he became the first player in franchise history to have two straight 50-point games. He also became the first NBA player to score 50 or more in consecutive games since Kobe Bryant did so in four straight in March 2007. On December 31 against the Lakers, Harden left with a hamstring injury late in the fourth quarter. Without Harden, the Rockets won 148–142 in double overtime. The following day, he was ruled out for two weeks with a Grade 2 hamstring strain. He missed seven games as a result. On January 26, Harden moved into second in Rockets history in assists with 3,347, passing Allen Leavell's 3,339. On January 30, in a 114–107 win over the Orlando Magic, Harden became the first player in NBA history to score 60 points as part of a triple-double, finishing with 10 rebounds and 11 assists for his third triple-double of the season. Harden scored 18 points in the fourth quarter to eclipse the 57 points Calvin Murphy scored in 1978 to break Houston's single-game scoring record. It was his fourth 50-point game of the season and bested his previous career high of 56 points set in November against Utah. On March 25, he helped the Rockets reach 60 wins in a season for the first time in franchise history, recording a triple-double (fourth of season, 35th of career) with 18 points, 15 assists and 10 rebounds in three quarters in a 118–99 win over the Atlanta Hawks. The Rockets finished the regular season as the No. 1 seed for the first time in franchise history, with a franchise-best 65–17 record. Harden won his first scoring title, averaging 30.4 points per game, second in franchise history to Malone's 31.1 in 1981–82. In Game 1 of the Rockets' first-round playoff series against the Minnesota Timberwolves, Harden scored 44 points in a 104–101 win. In Game 1 of their second-round series against the Jazz, Harden scored 41 points in a 110–96 win. It was his sixth 40-point playoff game of his career. In Game 1 of the Western Conference Finals, Harden scored 41 points in a 119–106 loss to the Golden State Warriors. In Game 4 against the Warriors, Harden scored a game-high 30 points to help the Rockets even the series at 2–2 with a 95–92 win. In Game 6, he recorded 32 points, nine assists and seven rebounds in a 115–86 loss. Despite a 32-point effort from Harden in Game 7, the Rockets were eliminated from the playoffs with a 101–92 defeat. He was only 2-of-13 on 3-pointers, and Houston made just 7 of 44, including 27 straight misses. In June, Harden was named the NBA Most Valuable Player for the 2017–18 season, becoming the third player in franchise history to receive the award, joining Moses Malone (1978–79 and 1981–82) and Hakeem Olajuwon (1993–94). That same month, he was voted the National Basketball Players Association's MVP for the 2017–18 season, earning the honor for a second time. ==== 2018–2019: Career high in scoring ==== The Rockets started the season with an 11–14 record. By the end of December, Harden had carried the Rockets to a 21–15 record with fellow All-Star Chris Paul out with a hamstring injury. On January 11, he had 43 points, 10 rebounds and 12 assists in a 141–113 win over the Cleveland Cavaliers. He also made eight 3-pointers to extend his NBA record to 12 games in a row with at least five. It was Harden's 13th game of the season with 40 points, surpassing Malone's franchise record, and his seventh in the previous nine games as he continued to carry the team with Paul and Eric Gordon out with injuries. On January 23, Harden scored a career-high 61 points to go with 15 rebounds in a 114–110 win over the New York Knicks, thus setting the fourth-longest streak for 30-point games in NBA history at 21—at the time, Wilt Chamberlain held the three longer streaks (65, 31 and 25). With 43 points against the Utah Jazz on February 2, Harden set the third-longest streak in NBA history for games with 30-plus points. On February 21, in the Rockets' first game after the All-Star break, Harden scored 30 points against the Los Angeles Lakers for his 32nd consecutive game with 30-plus points surpassing Chamberlain's for the second-longest streak in league history. After missing the Rockets' next game with an illness and a strained neck, his return game on February 25 saw him score 28 points against the Atlanta Hawks, snapping his 32-game streak with at least 30. On March 19, he scored 31 points in a win against the Hawks and became the first player in NBA history to score 30 or more points against all 29 other teams in a single season. On March 20, he scored 57 points in a 126–125 overtime loss to the Memphis Grizzlies, marking his seventh 50-point game of the season. Two days later, he matched his career high with 61 points, including 27 in the first quarter, to lead the Rockets to a 111–105 victory over the San Antonio Spurs. For these performances, he received his fourth Western Conference Player of the Week honor of the 2018–19 season. On March 31, Harden had 50 points, 11 rebounds and 10 assists in a 119–108 win over the Sacramento Kings to record his ninth 50-point game of the regular season. It was his fifth career 50-point triple-double, the most of any player in NBA history. He also became the ninth player in NBA history to make 2,000 3-pointers in their career. After a 135–103 victory against the Los Angeles Clippers on April 3, he became the third person in NBA history to record 2,700+ points and 500+ assists in a single season. In a 149–113 blowout win against the Phoenix Suns on April 7, Harden's 30-point, 13-rebound, nine-assist, and two-steal performance matched and broke several records: he tied Kobe Bryant for the most 30-point games in one season for any NBA player in the past 30 years with 56 games; became the second player in NBA History (Michael Jordan, 1989–90) to record 2,700 points, 500 assists, and 500 rebounds in one season; and joined Michael Jordan as the only player to average at least 30 points, seven assists, five rebounds and two steals in one season. He finished the season with the largest scoring margin (8.1 points per game) over the second-leading scorer since Wilt Chamberlain in 1962–63. Harden led the Rockets to a Game 2 win against the Utah Jazz with 32 points, 13 rebounds, and 10 assists—his third career triple-double during the postseason—to give the Rockets a 2–0 series lead in the first round. In Game 3 against the Jazz, he had one of the worst shooting nights of his career when he started the game 0-of-15, a figure breaking the NBA playoff record for most missed consecutive shots without a make in a game since Michael Jordan went 0-of-11 in an 87–80 loss against the Miami Heat in the 1997 Eastern Conference Finals. However, he finished the game with 22 points on 3-of-20 shooting, 10 assists, six steals, and four rebounds to lead the Rockets to a 104–101 win, putting the series at 3–0. The Rockets went on to lose 4–2 to the Warriors in the conference semifinals. At the season's end, he was unanimously selected to his fifth All-NBA First Team, and he was announced a finalist for the MVP award. ==== 2019–2021: Third consecutive scoring title and trade request ==== After a disappointing start to the season shooting 28.6% from the field and 15% from the three-point line in the first three games, Harden scored 59 points on 18–32 shooting from the field, along with nine assists in a 159–158 win against the Washington Wizards on October 30, 2019—two points away from his career-high. With this game, Harden extended a streak of having a 50-point game in 6 straight seasons, the 2nd-longest streak in NBA history behind Wilt Chamberlain (10 straight seasons, 1959–69). On November 11, 2019, he was named the Western Conference's Player of the Week after the Rockets went 3–0, Harden recording a double-double in each game and averaging 40.7 points, scoring 22 3-pointers on 43.1% shooting; 9.3 assists; 8.0 rebounds; 2.33 steals; and 1.33 blocks. Harden has scored a total of 334 points in 318 minutes of play this season, the highest total through the first nine games of a season since Michael Jordan scored 337 in 1988–89. Harden, at this point in the season, hit 39 3-pointers, marking the fourth-highest total through the first nine games of a season and the most by a player besides Stephen Curry. On November 30, 2019, in a 158–111 blowout win against the Atlanta Hawks, Harden got his fourth career 60-point game—tied for third-most with Michael Jordan—with a season-high 60 points along with 8 assists in 31 minutes. With this game, Harden joins Klay Thompson and Kobe Bryant as the only players to hit 60 points in just three quarters. His 24 shot attempts are the fewest ever in a 60-point game in NBA history. On December 11, 2019, Harden got his fourth 50-point game of the season with 55 points on an efficient 20-of-34 field goal shooting and 10-of-18 from three in a 116–110 win against the Cleveland Cavaliers. He became the fourth player in NBA history with multiple games of 10 or more 3-pointers, joining Stephen Curry (15), Klay Thompson (5), and J.R. Smith (3). He continued his scoring rampage in the following 130–107 win against the Orlando Magic on December 13, 2019, where he got his second 50-point game in a row—the third time in his career where he has scored back-to-back 50-point games—with 54 points on 19-of-31 field goal shooting and 10-of-15 from three, in addition to seven assists, and five rebounds. In this game, Harden became the second player in NBA history to score 10+ 3PM in consecutive games, joining Stephen Curry, who did this in February 2016, and he also passed Paul Pierce for eighth in the all-time career three-pointers made list. He also became the first player in NBA history to have 50+ points and 10+ 3PM in back-to-back games. Before those last two performances, only three times had a player attempted seven or less free throws while scoring 54 or more points in a game; Harden did it twice that week. On December 21, 2019, Harden passed Elgin Baylor for most 40-point games in NBA history with 40 points a 139–125 win against the Phoenix Suns. He became the Western Conference player of the month for December for his historical and efficient scoring tear during the month. He finished the decade as the NBA's leading scorer with 19,578 points going back to January 1, 2010, despite beginning his career as a sixth man with the Oklahoma City Thunder. In the Rockets’ first game after the suspension of the season due to COVID-19, Harden became the second highest scorer in franchise history after a 49 point, 9 rebound, 8 assist, 3 steal, 3 block, and 1 turnover performance on 70% shooting from the field in a 153–149 comeback overtime victory over the Dallas Mavericks. During the 2018–2020 seasons, Harden became the first player since Wilt Chamberlain with at least 20 games of 40+ points over a three-year period. He became the league's scoring champion for the third season in a row and the league leader in total steals. He additionally became a finalist for the MVP award and was named to the NBA's All-Seeding First Team. Houston was eliminated from the playoffs in the second round by the Lakers. During the off-season, general manager Morey and head coach D'Antoni left the Rockets. Harden demanded a trade in November 2020, and reported to training camp late. On December 26, he put up a season-high 44 points and tied a career-high 17 assists in a 128–126 overtime loss to the Portland Trail Blazers. === Brooklyn Nets (2021–2022) === Near the end of 2020, Harden requested a trade to the Brooklyn Nets, intending to form a superteam with former teammate Kevin Durant and Kyrie Irving. On January 14, 2021, Harden was traded to the Nets in a four-team deal which involved the Cleveland Cavaliers and Indiana Pacers, sending Rodions Kurucs, Dante Exum, Victor Oladipo, four first-round draft picks and four first-round pick swaps to the Rockets. On January 16, he recorded 32 points, 12 rebounds and 14 assists in a 122–115 win over the Orlando Magic, becoming the first player in franchise history and the seventh player in NBA history to log a triple-double in their team debut. Harden also set the record for being the first player in NBA history to post a 30-point triple-double debut performance, while also setting a franchise record for the most assists in a player's first game with the Nets. On February 2, Harden earned his first Eastern Conference Player of the Week honor, after logging a double-double average with 25.3 points and 11.3 assists over three games. On February 19, Harden posted a double-double with 23 points and 11 assists in a 108–98 win over the Los Angeles Lakers, becoming the first player in franchise history to log a double-double in eleven consecutive games. On February 22, Harden was named Eastern Conference Player of the Week, after leading the Nets to four straight wins. He averaged 31.8 points, 9.0 rebounds, 10.8 assists and 1.3 steals per game. The following day, Harden was named an Eastern Conference reserve for the 2021 NBA All-Star Game, marking his ninth consecutive All-Star selection. On March 1, Harden logged his seventh career triple-double as a Net with 30 points, 15 assists and 14 rebounds in a 124–113 overtime victory against the San Antonio Spurs, giving the franchise their first win in San Antonio in 19 years. In his efforts, Harden became the first player in league history to post a 30–15–10 stat line with zero turnovers in a game since individual turnovers were first tracked during the 1977–78 season. The following day, Harden was named Eastern Conference Player of the Month for the month of February. The honor was the eleventh of his career and first as a Net, making him the first Net to win the award since Vince Carter in April 2007. Harden led the franchise to an Eastern Conference-best 9–4 record in February, recording averages of 25.6 points, 8.8 rebounds, an Eastern Conference-leading 10.7 assists and 1.2 steals in 36.8 minutes per game. On March 13, Harden logged his ninth triple-double as a Net with 24 points, 10 rebounds and 10 assists in a 100–95 win against the Detroit Pistons, surpassing Larry Bird on the league's all-time scoring list. He now sits at 34th overall with 21,792 points, one more point than Bird. On March 15, Harden registered his tenth triple-double as a Net with 21 points, 15 assists and 15 rebounds in a 117–112 victory against the New York Knicks, becoming the first player in franchise history to log at least 15 points, 15 rebounds and 15 assists in a game. On March 17, Harden posted a season-high 40 points, 10 rebounds and 15 assists in a 124–115 win over the Indiana Pacers, joining Carter as the only Nets players with a 40-point triple-double. He also became the fourth player in NBA history with 100 40-point games and became second all-time in 40-point triple-doubles with 16, behind only Oscar Robertson who had 24. In his efforts, Harden's first two points of the game give him 21,815 points in his career, moving him past Gary Payton into 33rd overall in the league's all-time scoring list while his fourth assist of the first quarter was the 5,637th of his career, moving him past Chauncey Billups into 45th place in the NBA's all-time assist leader. On March 26, Harden, who missed a game against the Utah Jazz due to neck soreness, returned to the Nets and logged a season-high 44 points, 14 rebounds and eight assists in a 113–111 win over the Detroit Pistons. On March 29, Harden logged his twelfth triple-double in 32 games as a Net with 38 points, 11 rebounds and 13 assists in a 112–107 victory against the Minnesota Timberwolves, tying Jason Kidd's franchise record for triple-doubles in a season who did it twice in 80 and 51 games, respectively. On April 1, Harden was named Eastern Conference Player of the Month for the month of March. The honor was Harden's second as a Net, becoming the first player in league history to earn Player of the Month honors in each of his first two full months with a new team since the award's inception in 1979–80. He also set a record for being the first player in franchise history to earn Player of the Month honors in consecutive months. Harden led the Nets to an NBA-best 11–2 record in March, recording averages of 27.9 points on 43.8 percent shooting from the field and 87.7 percent shooting from the free-throw line, 9.8 rebounds, 11.5 assists, 1.6 steals in 38.8 minutes per game. Harden's franchise-record six triple-doubles of the month carried the Nets into first place in the Eastern Conference for the first time since 2003. After missing 18 games due to a strained hamstring, Harden returned to action on May 12. Coming off the bench for the first time since 2012, Harden posted a double-double with 18 points and 11 assists in a 128–116 win over the San Antonio Spurs. In Game 5 of the first round of the playoffs, Harden posted a triple-double with 34 points, 10 rebounds, and 10 assists in a 123–109 win to close out the series. In the first minute of Game 1 against the Milwaukee Bucks in the conference semifinals, Harden re-injured his hamstring and missed the remainder of the game, as well as the next three games of the series. Harden made his return in Game 5 of the series, a 114–108 comeback win. In Game 7, Harden had 22 points, 9 rebounds, and 9 assists in the 111–115 overtime loss. On October 22, 2021, Harden put up 20 points, seven rebounds and eight assists in a 114–109 win over the Philadelphia 76ers, moving past Kyle Korver for fourth on the all-time three-pointers made list. On November 12, Harden had a season-high 39 points, 5 rebounds and 12 assists in a 120–112 win over the New Orleans Pelicans. On November 19, Harden recorded 36 points, 10 rebounds and 8 assists in a 115–113 win against the Orlando Magic. On December 14, Harden entered health-and-safety protocols, causing him to miss the next three games. Harden made his return against the Los Angeles Lakers on December 25, where he recorded 36 points, 10 rebounds, 10 assists and 3 blocks in the 122–115 win. On December 27, Harden had 39 points, 8 rebounds and a season-high 15 assists in a 124–108 win over the Los Angeles Clippers. On January 15, 2022, Harden had 27 points, 8 rebounds and tied a season-high 15 assists in a 120–105 win over the New Orleans Pelicans. On January 21, Harden scored 37 points, grabbed 10 rebounds and dished out 11 assists in a 117–102 win over the San Antonio Spurs. On February 3, Harden was named an Eastern Conference reserve for the 2022 NBA All-Star Game, making his tenth straight All-Star selection. === Philadelphia 76ers (2022–2023) === On February 10, 2022, the Nets traded Harden and Paul Millsap to the Philadelphia 76ers in exchange for Ben Simmons, Seth Curry, Andre Drummond, and two first-round selections. Harden switched to No. 1 from the No. 13 he had worn through his entire professional career up to that point, as No. 13 was retired by the 76ers for Wilt Chamberlain. On February 25, Harden made his Sixers debut, putting up 27 points, 12 assists, and eight rebounds in a 133–102 win over the Minnesota Timberwolves. In the following game on February 27, Harden logged his 68th career triple-double and first as a 76er with a season-high 16 assists to go with his 29 points, 10 rebounds and five steals in a 125–109 win against the New York Knicks. He became the first player in NBA history to record 25 plus points and 10 or more assists in his first two games with a new team. On March 10, in a game against the Nets, Harden made his 2,561st career three-pointer to pass Reggie Miller (2,560) for third place in total NBA career three-pointers made, behind Ray Allen and Stephen Curry. On April 16, during Game 1 of the first round of the playoffs, Harden recorded a double-double of 22 points and 14 assists in a 131–111 win over the Toronto Raptors. On April 28, Harden had 22 points, 6 rebounds and 15 assists in a 132–97 Game 6 win, to help the Sixers advance to East semifinals. On May 8, Harden had 31 points, seven rebounds and nine assists in a 116–108 Game 4 win over the Miami Heat. Harden scored 16 of his 31 points in the fourth quarter to tie the series at 2–2. Philadelphia was eliminated by Miami in Game 6, when Harden scored 11 points and committed four turnovers. His last basket came with 3:31 left in the second quarter. On July 27, 2022, Harden re-signed with the 76ers on a two-year, $68.6 million deal which includes a player option for the 2023–24 season. On December 9, Harden scored 28 points and delivered 12 assists in a 134–133 overtime win over the Los Angeles Lakers. He joined LeBron James, Russell Westbrook and Oscar Robertson as the only players in NBA history with 23,000 career points and 6,500 career assists. On December 23, Harden put up a triple-double with 20 points, 21 assists, and 11 rebounds in a 119–114 win over the Los Angeles Clippers. He joined Wilt Chamberlain as the only players in Sixers history to put up a 20-assist triple-double and his 21 assists tied Chamberlain and Maurice Cheeks for the most assists in a game in Sixers history. On February 23, Harden posted 31 points, seven rebounds and seven assists in a 110–105 win over the Memphis Grizzlies. He passed Allen Iverson for No. 26 on the league's all-time scoring list. On March 6, Harden recorded his second 20-assist game of his career with a near triple-double, recording 14 points and nine rebounds to go along with the 20 assists in a victory over the Indiana Pacers. It was also the second time during the season where Joel Embiid recorded 40+ points to go along with Harden's 20+ assists, marking it the first time in NBA history being done by a pair of teammates multiple times in the same season. On April 9, Harden ended the regular season as the league leader in assists, averaging 10.7 assists per game. He also joined Joel Embiid as the first pair of teammates to lead the NBA in scoring and assists in a season since George Gervin and Johnny Moore did so in the 1981–82 season. In Game 1 of the Eastern Conference Semifinals, Harden tied a playoff career high 45 points in a 119–115 victory against the Boston Celtics. He hit a go-ahead three-pointer in the final seconds of the fourth in a game heavily favored towards Boston due to an injury to Joel Embiid. In Game 4, Harden put up 42 points, eight rebounds, nine assists, four steals, one block, and a game-winning three-pointer in a 116–115 overtime win. He also joined Jerry West, Michael Jordan, and Kobe Bryant as the only guards in NBA history to put up at least 10 40-point playoff games. The 76ers eventually lost the series to the Celtics in seven games. Following the 2022–23 season, Harden picked up his $35.6 million option to remain with the 76ers but eventually requested a trade. After trade talks with the Los Angeles Clippers stalled, Harden stated \"Daryl Morey is a liar and I will never be a part of an organization that he's a part of\". === Los Angeles Clippers (2023–present) === On November 1, 2023, the Los Angeles Clippers acquired Harden, P. J. Tucker, and Filip Petrušev from the 76ers in exchange for Marcus Morris Sr., Nicolas Batum, Kenyon Martin Jr. and Robert Covington. As part of the trade, the Clippers dealt a first-round pick, two second-round picks, a pick swap, and cash considerations to the 76ers, while sending a pick swap and cash considerations to the Oklahoma City Thunder. The trade reunited Harden with Russell Westbrook for the second time in their careers. Harden made his Clippers debut on November 6 against the New York Knicks, finishing with 17 points and six assists in 31 minutes as the Clippers lost 111–97. On November 17, Harden put up 24 points, nine rebounds, seven assists, and a game-winning three-pointer in a 106–100 win over the Houston Rockets. On December 14, Harden posted 28 points, 15 assists, seven rebounds and four blocks in a 121–113 win over the Golden State Warriors. He became the 24th player in NBA history to score 25,000 career points. On December 18, Harden scored 21 of his season-high 35 points in the fourth quarter, and dished out nine assists on 12-of-16 shooting, 8-of-11 from three, 3-of-3 from the free throw line in a 151–127 win over the Indiana Pacers. On January 26, 2024, Harden recorded his 75th career triple-double with 26 points, 10 rebounds and 13 assists in a 127–107 win over the Toronto Raptors. On February 2, Harden and Russell Westbrook became the third pair of 25,000-point scorers to play together in NBA history in a 136–125 win over the Detroit Pistons. They joined LeBron James and Carmelo Anthony for the 2021–22 Lakers and Kevin Garnett and Paul Pierce for the 2013–14 Nets. On March 17, Harden passed Vince Carter for the 20th place on the league's all-time scoring list. On April 4, in a game against the Denver Nuggets, Harden became the fourth player in NBA history to achieve at least 25,000 career points, 7,000 career assists, and 6,000 career rebounds, joining LeBron James, Oscar Robertson, and Russell Westbrook. On July 10, 2024, Harden re-signed with the Clippers on a two-year, $70 million contract. On November 2, 2024, Harden recorded his 78th career triple-double, tying Wilt Chamberlain for seventh in NBA history, as he finished with 25 points, 10 rebounds and 13 assists in a 125–119 loss against the Phoenix Suns. He also became the 20th player in NBA history to reach 26,000 points in his career. On November 15, Harden tied Ray Allen's record of second place in total NBA career three-pointers made, behind Stephen Curry, in a 125–104 loss against his former team the Houston Rockets. On November 17, Harden broke a tie with Ray Allen to solely secure second place in total NBA career three-pointers made, behind Stephen Curry, in a game against the Utah Jazz. On November 27, Harden put up 43 points in a 121–96 win over the Washington Wizards. It was his 100th career 40-point game, joining Wilt Chamberlain, Michael Jordan, and Kobe Bryant as the only players in NBA history with at least 100 40-point games. On December 1, Harden posted a near triple-double with 39 points, 9 rebounds and 11 assists in a 126–122 win over the Denver Nuggets. He also scored his 3,000th career three-pointer, joining Curry as the only players to reach the milestone. On January 30, 2025, Harden was named as reserve for the 2025 NBA All-Star Game, his eleventh selection. On February 20, Harden had 24 points, five rebounds and eight assists in a 116–110 loss against the Milwaukee Bucks. He became the 13th player in NBA history to score 27,000 career points. On March 5, Harden posted his first 50-point game since 2019 in a 123–115 win over the Detroit Pistons. On April 11, Harden logged his 80th career triple-double with 23 points, 11 rebounds and 10 assists in 101–100 win over the Sacramento Kings. On April 13, Harden recorded 39 points, seven rebounds, 10 assists, two steals and two blocks in a 124–119 overtime win over the Golden State Warriors in the regular-season finale to clinch the No. 5 seed in the Western Conference. He scored 12 of the Clippers' 13 overtime points. Harden started 79 games for the Clippers during the 2024–25 NBA season, averaging 22.8 points, 5.8 rebounds, and 8.7 assists. On June 29, 2025, Harden declined his player option and re-signed with Los Angeles on a new two-year, $81.5 million contract. == Player profile == Standing at 6 feet 5 inches tall (1.96 m) in shoes and weighing 220 pounds (100 kg), Harden plays mostly at the shooting guard position, but he is capable of playing the point guard position. He is the highest all-time left-handed scorer in NBA history. With season averages of over 25 points per game from the 2012–13 season to the 2019-2020 season, Harden is considered one of the most versatile and dangerous scorers in the NBA. ESPN named him the 5th best shooter in the NBA throughout the entire 2010s decade. He possesses a wide array of offensive moves; two of the most prominent among them being his Euro step and his step-back jumper. Since his trade to the Houston Rockets in the 2012–13 NBA season, he has scored the most points in the NBA. He is the all-time NBA leader in unassisted three-point makes. He has also gained notoriety for his ability to exploit league rules in order to more efficiently draw fouls and get to the free throw line, from which he is a career 85.7% shooter. He is the all-time leader in 3-point shooting fouls drawn, and he led the NBA in free throw attempts and makes every year from the 2014–15 season until the 2019–20 season. Though primarily a scorer, Harden is also known for his playmaking ability, orchestrating the Rockets' offense with his elevated assist numbers. During the early portion of the 2016–17 season, Rockets head coach Mike D'Antoni played Harden at point guard, which resulted in him averaging over 10 assists per game for the first time in his career. He is also the all-time franchise leader in assists for the Rockets. While he has garnered acclaim for his prowess on the offensive end, Harden has built a reputation as a poor defender. Criticism of his defense intensified in early 2014, when a video titled \"James Harden: Defensive Juggernaut\" featuring eleven minutes worth of clips of Harden conceding field goals, was circulated on the Internet. During the 2014 offseason, he committed to an improvement on defense, which manifested as early as August of that year as a member of the United States men's national basketball team. His improved defense carried over to the following season, and has been cited as a major reason for the Rockets' regular season success. Another negative aspect of his game that is sometimes brought up by pundits are his turnovers. Harden set the NBA record for turnovers during the 2015–16 season and broke it again the following season. Harden has also received criticism for not being clutch in key playoff games. == National team career == Harden was a member of the United States national team that won a gold medal at the 2012 Olympics, and was also a member of the team that won the FIBA Basketball World Cup in 2014. Harden was a candidate for the 2016 Olympics, but he withdrew from the team. == Career statistics == === NBA === ==== Regular season ==== ==== Playoffs ==== === College === == Personal life == Harden was born in Los Angeles, California. He is the youngest of three children. Before his birth, after that of his older sister, their mother suffered a string of miscarriages. Harden is a Christian. He has talked about his faith, saying, \"I just want to thank God for everything he has done in my life\". Harden started growing his trademark beard in 2009 after being too lazy to shave. His beard has appeared in songs and T-shirts, and it earned him an endorsement and a unique candy with Trolli's where a depiction of his face and beard was shown on each gummy. On August 3, 2015, the sports apparel company Adidas submitted an endorsement deal to Harden worth $200 million over the next 13 years. On July 18, 2019, Harden became a part owner in Houston's professional soccer teams; the Houston Dynamo of MLS and the Houston Dash of NWSL. Harden explained his decision by saying \"Houston is my home now, and I saw this as a way to invest in my city and expand my business interests at the same time\" as well as \"This is my city and I'm here to stay\". Harden revealed on the TV series Starting 5 that he has a son named Jace. === Politics === On October 4, 2019, Houston Rockets general manager Daryl Morey issued a tweet that supported the 2019–20 Hong Kong protests. Morey's tweet resulted in the Chinese Basketball Association's suspension of its relationship with the Houston Rockets. Harden later apologized to China, saying, \"We apologize. We love China.\" On July 17, 2020, Harden was widely criticized and mocked online for wearing a pro-police mask, which has been said to be related to white supremacy and the Blue Lives Matter movement. Atlanta rapper Young Thug stated on Twitter that \"he don't have internet\" in defense of Harden and indicated that he had not been aware of the controversy. The interaction became a widely shared internet meme among social media users, specifically in online rap and NBA groups. == See also == == References == == External links == Career statistics from NBA.com · Basketball Reference Arizona State Sun Devils bio James Harden at Olympics.com James Harden at Olympedia"} +{"title": "2017–18 Houston Rockets season", "content": "The 2017–18 Houston Rockets season was the 51st season of the franchise in the National Basketball Association (NBA), and their 47th in the Houston area. The Rockets acquired star point guard Chris Paul from the Los Angeles Clippers due to a multitude of trades after the 2017 NBA draft on June 28, 2017, as well as for being the team's first under current owner Tilman Fertitta. The Rockets also broke their franchise record for most wins in a season with their 59th win against the New Orleans Pelicans, eventually totalling 65 wins on the season. With a loss by the Warriors on March 29, the Rockets clinched the No. 1 seed for the first time in franchise history, which then followed to clinch the best record in this season following a Raptors loss against the Celtics. In the playoffs, the Rockets defeated the 8th-seeded Minnesota Timberwolves in the First round in five games, advancing to the conference semifinals, where they defeated the Utah Jazz in five games. They lost the conference finals to the eventual NBA champion Golden State Warriors in seven games. During game seven of that series, with the chance to go to the NBA Finals for the first time since 1995, the Rockets lost 101–92 and set an NBA Playoff record by missing 27 straight 3-point shots. == Draft picks == == Roster == == Standings == === Division === === Conference === == Game log == === Preseason === === Regular season === === Playoffs === == Player statistics == === Regular season === === Playoffs === == Transactions == === Trades === === Free agency === ==== Re-signed ==== ==== Additions ==== ==== Subtractions ==== == Awards == == References == == External links == \"The Rockets rode 3-pointers from the highest of highs to the depths of Hell\". SB Nation. June 21, 2018 – via YouTube."} +{"title": "2018 NBA playoffs", "content": "The 2018 NBA playoffs was the postseason tournament of the National Basketball Association's 2017–18 season. The playoffs began on April 14, 2018, and ended on June 8, with the Western Conference champion Golden State Warriors sweeping the Eastern Conference champion Cleveland Cavaliers 4–0. Kevin Durant was named the NBA Finals MVP for the second straight year. == Overview == === Western Conference === The Houston Rockets entered the playoffs with their best regular–season record in franchise history and appeared in their sixth consecutive postseason. They also finished with the best record in the NBA. The Golden State Warriors entered their sixth consecutive postseason, tying their franchise streak of 6 straight postseason appearances since the league's first six years of existence (1946–47 to 1951–52). The San Antonio Spurs entered their 21st consecutive postseason. The Minnesota Timberwolves qualified for the playoffs for the first time since 2004 and snapped the league's longest active streak of seasons without a playoff appearance. The New Orleans Pelicans qualified for the playoffs for the first time since 2015. === Eastern Conference === The Toronto Raptors also finished with a franchise record for single-season victories, winning 59 games and finished with the best record in the Eastern Conference. The Philadelphia 76ers qualified for the playoffs for the first time since 2012. The Miami Heat returned to the NBA playoffs after a one-season absence. === First Round === With their first round sweep of the Portland Trail Blazers, the New Orleans Pelicans won their first playoff series since 2008. Game 5 of the Sixers–Heat series was Dwyane Wade's final NBA postseason game. He would retire the following season. In Game 5 of their series against the Utah Jazz, the Oklahoma City Thunder rallied from a 25-point deficit in the second half to win the game 107–99. Game 7 between the Boston Celtics and the Milwaukee Bucks ensured a 19th–straight postseason in which at least one Game 7 was played; 1999 was the most recent postseason to not feature a Game 7. Game 6 of the Celtics–Bucks series was the last game played at the Bradley Center. For the first time in his career, LeBron James was forced to play a Game 7 in the first round of the playoffs, courtesy of the Indiana Pacers’ 121–87 victory in Game 6 over the Cleveland Cavaliers. This would be their last postseason victory until game 2 of the 2024 postseason against the Milwaukee Bucks. === Conference semifinals === Game 2 of the Raptors–Cavaliers series was the last game before the Air Canada Centre was renamed to Scotiabank Arena. Game 3 of the Raptors–Cavaliers series was extremely notable for LeBron James’ floater to win the game 105–103 for the Cleveland Cavaliers. The Toronto Raptors became the first top seeded team to be swept from the conference semifinals, earning LeBron James the nickname \"LeBronto\", as well as the first top seed to be swept out of the playoffs since the 2015 Atlanta Hawks (who were also swept by the Cleveland Cavaliers). With their Game 5 win over the Utah Jazz, the Houston Rockets made the Western Conference finals for the first time since 2015. === Conference finals === For the first time since 1994, the Houston Rockets held home court advantage in the Western Conference finals. Game 6 and Game 7 of the Western Conference finals was extremely notable for the Golden State Warriors’ second half comebacks to beat the Houston Rockets. The Warriors trailed the Rockets by as many as 17 points in Game 6 and as many as 11 points in Game 7 before coming back to win 115–86 and 101–92, respectively. Klay Thompson helped the Warriors force Game 7 by putting up another notable performance in Game 6. He dropped 35 to defeat the Houston Rockets. The Houston Rockets set an NBA record 27 missed threes in Game 7. James Harden, Trevor Ariza and Eric Gordon shot a combined 4-34 from 3. For the first time since 1979 both Conference finals series went to a deciding Game 7. In both Conference finals series, the road teams won both Game 7s. In the other two instances in which both Conference finals series went to a Game 7, the home team won each Conference finals Game 7 in the 1963 and 1979 Playoffs. The Cleveland Cavaliers and Golden State Warriors advanced to their fourth consecutive NBA Finals appearances. This also marked the first time the same two NBA teams met in the NBA Finals four seasons in a row. === NBA Finals === Game 1 of the NBA Finals was notable for JR Smith's infamous play that cost the Cleveland Cavaliers the game in the waning moments in regulation (they would lose in Overtime to the Golden State Warriors). LeBron James scored 51 points in the losing effort. Game 4 of the 2018 NBA Finals was the last game LeBron James played as a member of the Cleveland Cavaliers. This was also the first time a team was swept in the NBA Finals since 2007. Like in 2007, the Cleveland Cavaliers were also the team that got swept in the 2018 NBA Finals. The Golden State Warriors won their second consecutive championship, their third in four seasons. == Format == Within each conference, the eight teams with the most wins qualify for the playoffs. The seedings are based on each team's record. Each conference's bracket is fixed; there is no reseeding. All rounds are best-of-seven series; the team that has four wins advances to the next round. All rounds, including the NBA Finals, are in a 2–2–1–1–1 format. Home court advantage in any round belong to the higher-seeded team, who has the better regular season record (number 1 is the highest). If two teams with the same record meet in a round, standard tiebreaker rules are used. The rule for determining home court advantage in the NBA Finals is winning percentage, then head-to-head record, followed by intra-conference record. == Playoff qualifying == On March 7, 2018, the Toronto Raptors became the first team to clinch a playoff spot. On March 30, 2018, the Houston Rockets clinched the Western Conference ending a three-year run by the Golden State Warriors as the top seed. The Rockets clinched the best record in the NBA a day later on March 31, 2018. For the first time since the 1996–97 NBA season, two teams played their last game against each other for the 8th and final spot in the playoffs. The Minnesota Timberwolves defeated the Denver Nuggets 112–106 in overtime to clinch the final playoff seed in the West. This also ended Minnesota's 13-year drought without a playoff appearance having last played in 2003–04 season. For the first time since the 2010–11 NBA season, the Los Angeles Clippers would miss the postseason following a loss to the Denver Nuggets on April 7, 2018. This is the first time since 1960 that none of the teams from New York, Los Angeles, or Chicago made the playoffs. For the first time since 2005, both the Lakers and Clippers missed the playoffs in the same season. === Eastern Conference === === Western Conference === == Bracket == Teams in bold advanced to the next round. The numbers to the left of each team indicate the team's seeding in its conference, and the numbers to the right indicate the number of games the team won in that round. The division champions are marked by an asterisk. Teams with home court advantage, the higher seeded team, are shown in italics. == First round == Note: Times are EDT (UTC−4) as listed by the NBA. If the venue is located in a different time zone, the local time is also given. === Eastern Conference first round === ==== (1) Toronto Raptors vs. (8) Washington Wizards ==== This was the second playoff meeting between these two teams, with the Wizards winning the first meeting in 2015. ==== (2) Boston Celtics vs. (7) Milwaukee Bucks ==== This was the sixth playoff meeting between these two teams, with the Celtics winning four of the first five meetings. ==== (3) Philadelphia 76ers vs. (6) Miami Heat ==== With the win, the Sixers won their first playoff series since 2012. This was the second playoff meeting between these two teams, with the Heat winning the first meeting. ==== (4) Cleveland Cavaliers vs. (5) Indiana Pacers ==== LeBron James capped off his heroic Game 5 performance with a game-winning 3 at the buzzer to put the Cavaliers up 3–2 in the series. This was the fourth time James has hit a game-winning buzzer beater in the playoffs. This was the third playoff meeting between these two teams, with each team winning one series. === Western Conference first round === ==== (1) Houston Rockets vs. (8) Minnesota Timberwolves ==== This was the second playoff meeting between these two teams, with the Rockets winning the first meeting. ==== (2) Golden State Warriors vs. (7) San Antonio Spurs ==== Game 5 is Manu Ginóbili's final NBA game. This was the fourth playoff meeting between these two teams, with the Warriors winning two of the first three meetings. ==== (3) Portland Trail Blazers vs. (6) New Orleans Pelicans ==== The Pelicans completed a sweep of the Trail Blazers for their 1st series win in the playoffs since the 2008 NBA playoffs against the Dallas Mavericks as the New Orleans Hornets. This was the first playoff meeting between the Trail Blazers and Pelicans. ==== (4) Oklahoma City Thunder vs. (5) Utah Jazz ==== The Thunder trailed by as much as 25 points in the 3rd quarter. However, Russell Westbrook and Paul George combined for 47 second-half points to help keep their season alive. The Thunder outscored the Jazz 61-28 since the comeback started with 8:32 left in the 3rd quarter. The 25-point rally was their largest in franchise history and one of the biggest comebacks for a team facing elimination in playoff history. This was the fifth playoff meeting between the SuperSonics/Thunder franchise and the Jazz, but the first since the Seattle SuperSonics relocated to Oklahoma City and became the Thunder in 2008. The two teams have split their previous four playoff matchups. == Conference semifinals == Note: Times are EDT (UTC−4) as listed by the NBA. If the venue is located in a different time zone, the local time is also given. === Eastern Conference semifinals === ==== (1) Toronto Raptors vs. (4) Cleveland Cavaliers ==== LeBron James capped off a 38-point performance with a fadeaway bank shot floater at the buzzer to lead the Cavs to a commanding 3–0 series lead. This was the third playoff meeting between these two teams, with Cleveland winning the first two meetings. ==== (2) Boston Celtics vs. (3) Philadelphia 76ers ==== This was the 21st playoff meeting between these two teams, with the Celtics winning 12 of the first 20 meetings. === Western Conference semifinals === ==== (1) Houston Rockets vs. (5) Utah Jazz ==== This was the eighth playoff meeting between these two teams, with the Jazz winning five of the first seven meetings. ==== (2) Golden State Warriors vs. (6) New Orleans Pelicans ==== This was the second meeting in the playoffs between the two teams, with the Warriors winning the first meeting. == Conference finals == Note: Times are EDT (UTC−4) as listed by the NBA. If the venue is located in a different time zone, the local time is also given. === Eastern Conference finals === ==== (2) Boston Celtics vs. (4) Cleveland Cavaliers ==== It marked the first time since the 1987–88 season that the Celtics made two consecutive Conference finals. It was also the Celtics' first home loss of the postseason. Their loss at home after leading 3–2 in the series was the first time that had happened since 2009. This was the fifth time in NBA history that the road team won a Game 7 after the home team had won each of the first six games. LeBron James became the first non-Celtic to advance to 8 consecutive NBA Finals. It was also the second time in the Celtics' history that they had lost a playoff series in which they had taken a 2–0 lead. This was the eighth playoff meeting between these two teams, with the Celtics winning four of the first seven meetings. === Western Conference finals === ==== (1) Houston Rockets vs. (2) Golden State Warriors ==== The game was a memorable back-and-forth affair that came down to the wire. In the final seconds (6.7 seconds to be exact) with the Rockets up 96–94, the Warriors had one last chance to tie or take the lead in the game, Draymond Green however lost his balance and turned the ball over to Eric Gordon who was then fouled and sealed the game making both of his free throws sending Houston within 1 game to their first trip to the NBA Finals since 1995, but it came at a cost however as Chris Paul suffered a \"right hamstring injury\" in the final minute, he did not play for the rest of the series. Kevin Durant scored 29 points while Draymond Green had 15 rebounds & Stephen Curry had 6 assists for the Warriors Eric Gordon scored 24 points while Clint Capela scored 14 rebounds & Chris Paul with 6 assists for the Rockets. Golden State rallied from a 17-point first quarter deficit by outscoring Houston 64–25 in the second half to force a Game 7. The Rockets' 25 second-half points tied a franchise record low for scoring in any half in the postseason. The Rockets controlled the 1st half, leading by as much as 15 points, the half ended on an Eric Gordon buzzer-beating layup putting the score at halftime 54–43 in Favor of Houston. However, the game took a drastic change from that point as the Warriors would once again rally and took the lead with 4 minutes left in the 3rd quarter, a lead they never relinquished as they continued to cruise throughout the rest of the game to win their 4th Consecutive Western Conference title. For The Warriors: Kevin Durant scored 34 points, Draymond Green scored 13 rebounds & Steph Curry scored 10 assists, the Team went 16-of-39 from the 3-point line during the game For The Rockets: Although James Harden scored 32 points & 6 Assists with P.J. Tucker securing 12 rebounds, the Rockets missed 27 consecutive 3-pointers, which is a record for most ever missed consecutively in a playoff game. They also went 1-of-30 from the 3-point line to close out the game. This is the Warriors' first game 7 road win since 1948 and the first Western Conference team to win a conference finals game 7 on the road since the 2001–02 Los Angeles Lakers. This was the third playoff meeting between these two teams, with the Warriors winning the first two meetings. == 2018 NBA Finals: (E4) Cleveland Cavaliers vs. (W2) Golden State Warriors == Note: Times are EDT (UTC−4) as listed by the NBA. If the venue is located in a different time zone, the local time is also given. Game 1 would go on to be an instant classic, with LeBron James scoring 51 points. The game was tight throughout, as neither team was able to gain separation. However, the final minutes did not come without controversy as Durant seemingly charged onto James when driving to the basket. The officials reviewed that James was not within the restricted area, and the call was then reversed into a blocking foul, thus allowing Durant to tie the game with a pair of free throws. Eventually, when the Warriors were leading 107–106, James passed the ball that went out of bounds while George Hill was fouled, thus giving him a pair of free throws. After making the first free throw to tie it at 107, he missed the second free throw, which was rebounded by J.R. Smith, who ran the clock as it was perceived that he believed the Cavaliers had the lead. He passed the ball to Hill, whose shot was blocked by Draymond Green at the buzzer. The Warriors dominated overtime 17–7 as they won the series opener 124–114. Stephen Curry, Kevin Durant, and Klay Thompson respectively scored 29, 26, and 24 points. In Game 2, the Warriors blew out the Cavs 122–103 as Curry sinked in 9 three-pointers and finished with 33 points and Durant dropped 26 points. The Warriors sent more double teams on James, holding him to 29 points. As Game 3 shifted to Cleveland, the Cavaliers dominated the first half, leading by as many as 13. Curry and Thompson, the Splash Brothers, had a bad night only combining for only 21 points on 7-27 shooting. However, in the second half, the Warriors fought back, making it a back-and-forth game as Kevin Durant scored 43 points, and made a key clutch shot in the closing minutes that put the Warriors up 106–100, and eventually winning 110–102 to put the Warriors up 3–0 for the second straight year. After a close first half in Game 4, the Warriors dominated the third quarter and routed the Cavaliers 108–85 behind Stephen Curry's 37 points and seven three-pointers, as well as a triple-double by Durant, thus completing the sweep. Durant won Finals MVP for the second straight year behind averages of 28.8 points, 10.8 rebounds and 7.5 assists, while Curry averaged 27.5 points for the series. LeBron James led both teams in scoring and assists, putting up averages of 34.0 points and 10.0 assists in a losing effort. This was the fourth meeting in the NBA Finals between these two teams, with the Warriors winning two of the first three meetings. == Statistical leaders == == Media coverage == === Television === ESPN, TNT, ABC, NBA TV, ESPN2, and ESPNews televised the playoffs nationally in the United States. In the first round, regional sports networks affiliated with the teams also broadcast the games, except for games televised on ABC. Throughout the first two rounds, TNT televised games Sunday through Wednesday(2nd round), Thursday (1st round), ESPN televised games Thursday (2nd round)and Friday, and ABC televised selected games on Saturday and Sunday, usually in the afternoon. NBA TV, ESPN2 and ESPNEWS has aired select weekday games in the first round. ESPN/ABC televised the Eastern Conference finals, while the Western Conference finals was televised by TNT. ABC had exclusive television rights to the 2018 NBA Finals, which was the 16th consecutive year for the network. == See also == == References == == External links == Basketball – Reference.com's 2018 Playoffs section"} diff --git a/Code/figures/names_2017-18_houston_rockets_season.png b/Code/figures/names_2017-18_houston_rockets_season.png new file mode 100644 index 0000000..3f3324c Binary files /dev/null and b/Code/figures/names_2017-18_houston_rockets_season.png differ diff --git a/Code/figures/names_2018_nba_playoffs.png b/Code/figures/names_2018_nba_playoffs.png new file mode 100644 index 0000000..62a0186 Binary files /dev/null and b/Code/figures/names_2018_nba_playoffs.png differ diff --git a/Code/figures/names_james_harden.png b/Code/figures/names_james_harden.png new file mode 100644 index 0000000..edacb3c Binary files /dev/null and b/Code/figures/names_james_harden.png differ diff --git a/images/text_clustering.png b/Code/figures/text_clustering.png similarity index 100% rename from images/text_clustering.png rename to Code/figures/text_clustering.png diff --git a/Code/figures/topwords_2017-18_houston_rockets_season.png b/Code/figures/topwords_2017-18_houston_rockets_season.png new file mode 100644 index 0000000..f6a10b7 Binary files /dev/null and b/Code/figures/topwords_2017-18_houston_rockets_season.png differ diff --git a/Code/figures/topwords_2018_nba_playoffs.png b/Code/figures/topwords_2018_nba_playoffs.png new file mode 100644 index 0000000..56254e6 Binary files /dev/null and b/Code/figures/topwords_2018_nba_playoffs.png differ diff --git a/Code/figures/topwords_james_harden.png b/Code/figures/topwords_james_harden.png new file mode 100644 index 0000000..1c080ba Binary files /dev/null and b/Code/figures/topwords_james_harden.png differ diff --git a/README.md b/README.md index 05aa109..955fe6b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,34 @@ -# Text-Analysis-Project +### Text-Analysis-Project -Please read the [instructions](instructions.md). +# Project Overview +For this specific Python project, I decided to use one of the data sources suggested by the project instructions, which is Wikipedia. I decided to explore about specifically “James Harden,” “2017–18 Houston Rockets season,” and “2018 Western Conference Finals.” The reason why I am choose this is because I have been a basketball fan for over 10 years and I have also played varsity basketball in my highschool team. My favorite player inside of the National Basketball League is James Harden and he has been someone that I really look up to. Something that has been in my mind for a long time is how James Harden despite having a lot of achievements like MVP and Allstar, people would not put him on par as other greatest of all time player because he has never won a championship team. The closest he has ever gone in the playoffs is the 2018 Western Conference Finals and for me everytime I have flashbacks watching the playoffs in 2018 I get very sad because it was a perfect oppurtunity for James Harden to prove himself to be one of the best playser in the League. Without the championship, also James Harden is considered a great player during regular season, he will be labeled as a playoff choker who never really proved himself when things really mattered. + +For this Python project, I want to download the articles on Wikipedia using the mediawiki python package and clean the text by removing citation brackets in order for it to be easier processed. From my machine learning class QTM3635 we learned a lot of data cleaning and tokenization, so I want to perform a tokenization process with a stopword list simialr to my QTM class. However, rather than having a URL for the stoplist, I have used Chatgpt to create a tiny stoplist for my project. I am also performing bag of words representation, comparing which words are the most frequent within the season and which words are most frequent within the playoffs. From this project, I really want to see how different do people think James Harden performs during the playoffs compared to the regular season. I will do so by changing the raw data from the web text into structured data. + +# Implementation +For implementation, I decided to have two python files, one on downloading the information from wikipedia and the other on text analysis. For the first data acquisition code, I used python to do some data acquisition and cleaning by the recommended mediawiki feature within python. I fetched information from three wikipedia pages regarding James Harden and the 2017-2018 Houston Rockets Season. I was able to strip all of the citation markers and was able to store the data within a Python dictionary. Additionally, Chatgpt recommended that I used the JSONL feature where it will have one JKSOn object per line consisting of the title and the content. Secondly, I had code for analysis, which tokenize the data and uses bag of words representation. The stop list I used allows me to identify actual words that are useful for the experiment and get rid of random words such as "that, and, of". I coded the data so that it will print top 15 words per document, compare the season page and the WCF page to find words that are common in one but not the other , compute cosine similarity for the three document pairs, and scan for capitalized tokens to get likely proper names. + +At the same time, I have gave my code for the two documents and asked Chatgpt to give me more detailed and complex code for better graphs and models and it was able to produce very interesting results, where I added a page called "part 3 chatgpt". I used a detailed prompt to chatgpt to do more detailed data cleaning and tokenization. I was able to explore the feature of "matplotlib" where it adds a lot of visualization layer to my code. It also added "ensure_fig_dir()" to make a figure folder within the respository and use "slugif" to turn titles into file names. All of those features are beyond my knowledge of python but I appreciate that the professor allows us to use Chatgpt to help us because it can really teach me how I can improve my code and introduce me to very useful and interesting code and features that I have not know before. With the guidance of chatgpt, I was able to create a lot of visual graphs, plos for top words used per document, plot for season versus the western eastern conference, plot for cosine heatmap, and plot for proper names of all. + + +# Results +![alt text](Code/figures/cosine_heatmap.png) +![alt text](Code/figures/names_2017-18_houston_rockets_season.png) +![alt text](Code/figures/names_2018_nba_playoffs.png) +![alt text](Code/figures/names_james_harden.png) +![alt text](Code/figures/text_clustering.png) +![alt text](Code/figures/topwords_2017-18_houston_rockets_season.png) +![alt text](Code/figures/topwords_2018_nba_playoffs.png) +![alt text](Code/figures/topwords_james_harden.png) + + + + +With the help of Chatgpt, I was able to create a lot of the plots however, I was unable to find the statistical differences of James Harden but shows more of the textual differences. For example, the cosine similarity heatmap allows me to se that the words within the wikipedia page 2017-2018 rockets season and the playoffs are more similiar to each other compared to the page directly about James Harden. With this skill, we are able to compare documents in the futher and determine their similarity. Although the harden page was still related to the seasons page, the harden page focused more on his personal statistics. +The bar chart for the top 15 shows us that the most popular words are like "harden", "point", "assist", etc. This also shows us the article is more surrounded the specific matchups rather than the specific player. However, I noticed that it included "=" and "==" within the bar chart and realized the limiation of my data cleaning where I was unable to merely tokenize the basketball related insights where I believe a longer stop list would be better. +On the proper names chart, I am able to identify the opponents of the Housten Rockets of that year which is the Warriors and Cavaliers, which where all teams that the Rockets have faced in that season. + +# Reflection +I feel like what went well of the project is that I was able to data clean and successfully draw data from the files and I was also able to use Chatgpt to create plots that were very interesting for me. It showed me a more advanced version of my data and it really allowed me to explore my project even more. However, I believe there is room for improvement for data cleaning where a lot of the common words within the charts are punctuation or words that is not really related to basketball. I would imagine a longer stop list will help this and clean the data and only include the data I want. At the same time, my code and the extent of the data I am pulling is unable to tell me the differences between the lanaguge used in the 2017-2018 season compared to the playoffs. I would imagine that I should probably get the data from social media like reddit rather than wikipedia because wikipedia is all unbiased facts where reddit has more personal bias and emotions where I can analye people's comments on James Harden and the difference of their attitude towards James Harden during the playoffs. If I could do this again, I would focus more on statistics where I can compare the statistics of James Harden and analyze how much worse of a player he becomes when he played the playoffs throughout his career. + +Other than that, I feel like I had a lot of fun doing this project and definetly was able to explore more skills and strengthen my textbook knowledge of python. \ No newline at end of file diff --git a/instructions.md b/instructions.md deleted file mode 100644 index 1356910..0000000 --- a/instructions.md +++ /dev/null @@ -1,597 +0,0 @@ -# Text Analysis Project - -## Introduction - -In this project, you will learn how to use computational techniques to analyze text. You will access text from a variety of sources, including websites and APIs, and run computational analyses to create some sort of deliverable, such as interesting results from a text analysis, a visualization, or even a Python program that manipulates language in some interesting way. As part of the project, you are encouraged to use AI tools to explore how to talk to APIs and how to use Python libraries that have not been covered in class yet. This assignment is an **individual project**. - -**Skills Emphasized**: - -- Accessing data programmatically from various sources on the Internet -- Parsing text and storing it in appropriate data structures -- Selecting the most suitable data structures for a specific task (e.g. dictionaries versus lists) -- Applying computational methods to analyze, characterize, and compare text -- Experimenting with AI tools to enhance the learning process and explore new tools and techniques. - ---- - -## How to Proceed - -To get started on the assignment, you should first **fork** this base repository. Once you've forked the repository, **clone** the **forked** repository (the one under your GitHub profile) to your computer. You need to create one or multiple `.py` files in the **forked** repository. - -You should read this document in a somewhat non-linear/spiral fashion: - -1. Scan through **Part 1** to get a sense of what data sources are available. You can select one or two sources that interests you and try to retrieve text from them. Note that you do not need to try all the data sources. -2. Scan through **Part 2** to see a bunch of cool examples for what you can do with your text. You can also ask AI tools what else you can do with Python to process, analyze or visulize the text. -3. Choose (at least) one data source from **Part 1** and apply required techniques from **Part 2**, plus any additional techniques that interest you, to analyze, manipulate, transform or visualize the text. -4. Make sure there is one clear entry `.py` file for the entire project. Multiple `.py` files are encouraged to break the project into smaller, modular components. -5. Use the `if __name__ == "__main__"` idiom in the `.py` files. Your code should be executed when the entry Python file is run. - ```python - if __name__ == "__main__": - main() - ``` -6. You are required to experiment with learning from AI tools (see more in **Part 3**). -7. Write a brief document (**Part 4**) describing your process and your reflection. -8. If you use any code or solutions that is not written by you (or that you learned from other places such as StackOverFlow/GitHub), please add Python comments (before the block of code) describing where you got/learned it from. -9. Generally I **DO NOT** recommend using `numpy`, `pandas`, `sklearn` or `matplotlib` in this project, unless there is no other alternative way of processing and analyazing your data. For instance, if you need to perform complex matrix computations, text clustering (like MDS), or advanced visualizations, it is acceptable to use these libraries. Please justify your choice in your project documentation. - -### Jupyter Notebook vs .py Files: Which to Use? - -**Required for Submission**: Your final project **must** include `.py` files as described above. This is a mandatory requirement. - -**Optional for Development**: You are encouraged to use Jupyter Notebooks (`.ipynb` files) during the development and exploration phase. Here's a recommended workflow: - -**Use Jupyter Notebooks for:** - -- **Exploratory Data Analysis**: Quickly test API connections, explore text data characteristics, and experiment with different processing methods -- **Interactive Visualization**: Adjust chart parameters in real-time and immediately see the results -- **Learning and Experimentation**: Test new libraries (NLTK, TextBlob, etc.) and debug code step-by-step -- **Documentation**: Keep notes and screenshots showing how you used AI tools to learn and solve problems - -**Use .py Files for:** - -- **Final Submission**: This is required by the project specifications -- **Production Code**: Well-organized, modular functions with proper error handling -- **Code Reusability**: Functions and classes that can be imported and reused -- **Version Control**: Git-friendly format for tracking changes - -**Workflow Recommendation:** - -1. **Explore in Jupyter**: Test APIs, experiment with text processing techniques, create visualizations interactively -2. **Refactor to .py**: Move successful code into well-organized Python modules with proper functions and documentation -3. **Submit Both** (optional): Include both `.ipynb` files (to show your learning process) and `.py` files (required for grading). You can reference your notebooks in the README to demonstrate how you used AI tools for learning. - -This approach allows you to leverage the interactive benefits of Jupyter Notebooks while meeting the project's requirements for well-structured Python code. - ---- - -## Part 1: Harvesting text from the Internet - -The goal for Part 1 is to collect some text from the Internet that you can later use for text analysis. Before diving deep into any particular method of text acquisition, it is recommended that you explore the different APIs and Python libraries available to extract text from the web. However, before spending too much time going down a particular path on the text acquisition component, you should look ahead to Part 2 to understand some of the things you can do with text you are harvesting. The key to a successful project is combining a relevant source of text with an appropriate technique for analysis (see Part 2). - -**Note**: Some APIs (such as Twitter and Reddit) may require a paid subscription or a lengthy application process. It is recommended to apply for API credentials in advance or choose alternative free data sources to avoid delays later in the project. - -### Installing Python Packages - -Throughout this project, you will need to install various Python libraries. Here are the recommended methods: - -**If you are using Anaconda** (recommended for this course): - -```shell -# Use conda to install packages (preferred method for Anaconda users) -conda install -c conda-forge package_name - -# If the package is not available in conda, use pip with Anaconda's Python -python -m pip install package_name -``` - -**If you are using standard Python installation** (not Anaconda, not for this course): - -```shell -# For Windows users -python -m pip install package_name - -# For macOS/Linux users -python3 -m pip install package_name -``` - -**Important Notes**: - -- Always use `python -m pip install` instead of just `pip install` to ensure you're installing to the correct Python environment -- If you're using Anaconda, try `conda install` first, as it handles dependencies better -- You can check which Python you're using by running `python --version` or `which python` (macOS/Linux) or `where python` (Windows) - -### Data Source: Project Gutenberg - -Project Gutenberg () is a website that provides over 55,000 e-books that are freely available to the public. Unlike some sites, all of the texts on Project Gutenberg are in the public domain, which means they are no longer protected by copyright. For example, the site offers 171 works by Charles Dickens. The best thing about these texts is that they are available in plain text format, which makes them easy to analyze using Python. - -To download a book from Project Gutenberg, first use the search engine on the Project Gutenberg website to find a book you are interested in downloading. For example, if you want to download *Oliver Twist* by Charles Dickens, search for it on the website. Once you have found the book you want to download, go to its page on the Project Gutenberg website. Find the "Plain Text UTF-8" link on the book's page. Copy the link to the plain text version of the book. In the case of *Oliver Twist*, the link to the plain text version is `"https://www.gutenberg.org/cache/epub/730/pg730.txt"`. - -To download the text inside Python, you can use the following code: - -```python -import urllib.request - -url = 'https://www.gutenberg.org/cache/epub/730/pg730.txt' -try: - with urllib.request.urlopen(url) as f: - text = f.read().decode('utf-8') - print(text) # for testing -except Exception as e: - print("An error occurred:", e) -``` - -**Security Note**: When working with APIs that require credentials (Twitter, Reddit, News API, etc.), never commit your API keys to version control. Use environment variables or separate configuration files (e.g., `config.py`) and add them to `.gitignore`. - -Note that there is a preamble (boilerplate on Project Gutenberg, table of contents, etc.) that has been added to the text that you might want to strip out using Python code when you do your analysis. There is similar material at the end of the file. - -One limitation of using Project Gutenberg is that they impose a limit on how many texts you can download in a 24-hour period. If you are analyzing many texts, it may be more efficient to download them once and load them off disk, rather than fetching them from Project Gutenberg's servers every time you run your program. See the **Pickling Data** section below on how to save data to files and load it back into your program. Additionally, there are many mirrors of the Project Gutenberg site available if you want to get around the download restriction. - -### Data Source: Wikipedia - -Wikipedia is another valuable source of data that can be easily accessed and parsed using the [mediawiki library](https://github.com/barrust/mediawiki) which is a python wrapper and parser for the **MediaWiki API**. To install the library: - -```shell -# If using Anaconda (recommended) -conda install -c conda-forge pymediawiki - -# Or using pip -python -m pip install pymediawiki -``` - -Once you have installed the library, you can use it to search Wikipedia, get article summaries, and extract data like links and images from a page. To fetch a particular article and print out its sections, you can use the following Python code: - -```python -from mediawiki import MediaWiki - -wikipedia = MediaWiki() -babson = wikipedia.page("Babson College") -print(babson.title) -print(babson.content) -``` - -This code will fetch the article with the given title and print its title and content. The output will look like this: - -```txt -Babson College (Babson) is a private business school in Wellesley, Massachusetts. Established in 1919, Babson's central focus is on entrepreneurship education and its use in creating economic and social value. The college was founded by Roger W. Babson as an all-male business institute and became coeducational in 1970. -... -``` - -You can also access other properties of a page, such as its categories, sections, and links. See the mediawiki package [documentation](https://pymediawiki.readthedocs.io/en/latest/quickstart.html#other-properties) for more information on available properties and methods. - -### Data Source: Twitter - -(**Note**: I have not tested this API since the announcment of shutting down free Twitter API. The free version of Twitter API has been deprecated and replaced with a new version that requires application approval and authentication with a paid subscription. To use the Twitter API, you need to apply to Twitter for a developer account and explain the purpose of what you are doing with the data, which Twitter will manually review.) - -(**Update**: You'll need at least the Basic access tier to search recent tweets, which isn't free. You can subscribe to it in your [Dashboard](https://developer.twitter.com/en/portal/dashboard) in the Developer Portal.) - -If you have access to a Twitter developer account and the necessary API keys and tokens, you can use the `tweepy` library to search for tweets. - -To install tweepy: - -```shell -# If using Anaconda (recommended) -conda install -c conda-forge tweepy - -# Or using pip -python -m pip install tweepy -``` - -Here is a simple example for searching tweets containing `Babson College`: - -```python -import tweepy - -# Replace the following strings with your own keys and secrets -TOKEN = 'Your TOKEN' -TOKEN_SECRET = 'Your TOKEN_SECRET' -CONSUMER_KEY = 'Your CONSUMER_KEY' -CONSUMER_SECRET = 'Your CONSUMER_SECRET' - -# Authenticate to Twitter -auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) -auth.set_access_token(TOKEN,TOKEN_SECRET) - -api = tweepy.API(auth) - -for tweet in api.search_tweets(q="babson college", lang="en", count=10): - print(f"{tweet.user.name}: {tweet.text}") -``` - -### Data Source: Reddit - -Note: Reddit also requires users to register and create an application in order to obtain API credentials. After creating an application, you can obtain the necessary credentials such as `client_id`, `client_secret`, `username`, `password`, and `user_agent`. You can learn more about this process on the [Reddit API documentation](https://www.reddit.com/dev/api/). - -To get reddit data, you need to install the [PRAW library](https://github.com/praw-dev/praw): - -```shell -# If using Anaconda (recommended) -conda install -c conda-forge praw - -# Or using pip -python -m pip install praw -``` - -Here's an example from the [PRAW docs page](https://praw.readthedocs.io/en/stable/getting_started/quick_start.html): - -```python -import praw -import config - - -reddit = praw.Reddit(client_id=config.client_id, - client_secret=config.client_secret, - username=config.username, - password=config.password, - user_agent=config.user_agent) - -sub = 'learnpython' -submissions = reddit.subreddit(sub).top('day', limit=5) -for submission in submissions: - print(submission.title) - print(submission.selftext) -``` - -### Data Source: News API - -You can use `newsapi-python` library to fetch news articles from [News API](https://newsapi.org/docs/). You need to install the [newsapi-python library](https://github.com/mattlisiv/newsapi-python): - -```shell -# If using Anaconda (recommended) -conda install -c conda-forge newsapi-python - -# Or using pip -python -m pip install newsapi-python -``` - -Here's an example from the [Python client library page](https://newsapi.org/docs/client-libraries/python) in News API Documentation: - -```python -from newsapi import NewsApiClient - -# Init -newsapi = NewsApiClient(api_key='API_KEY') - -# /v2/top-headlines -top_headlines = newsapi.get_top_headlines(q='bitcoin', - sources='bbc-news,the-verge', - category='business', - language='en', - country='us') - -# /v2/everything -all_articles = newsapi.get_everything(q='bitcoin', - sources='bbc-news,the-verge', - domains='bbc.co.uk,techcrunch.com', - from_param='2017-12-01', - to='2017-12-12', - language='en', - sort_by='relevancy', - page=2) - -# /v2/top-headlines/sources -sources = newsapi.get_sources() -``` - -### Data Source: Newspaper Articles - -You can also use `Newspaper4k` package to scrape and curate news articles. You need to install the [Newspaper4k library](https://github.com/AndyTheFactory/newspaper4k): - -```shell -# If using Anaconda (recommended) -conda install -c conda-forge newspaper4k - -# Or using pip -python -m pip install newspaper4k -``` - -Here's an example from the [Newspaper4k Docs page](https://newspaper4k.readthedocs.io/en/latest/): - -```python -import newspaper - -article = newspaper.article('https://edition.cnn.com/2023/10/29/sport/nfl-week-8-how-to-watch-spt-intl/index.html') - -print(article.authors) -# ['Hannah Brewitt', 'Minute Read', 'Published', 'Am Edt', 'Sun October'] - -print(article.publish_date) -# 2023-10-29 09:00:15.717000+00:00 - -print(article.text) -# New England Patriots head coach Bill Belichick, right, embraces Buffalo Bills head coach Sean McDermott ... -``` - -### Data Source: IMDB Movie Reviews - -To get the IMDB data, you need to install [`cinemagoer` library](https://github.com/cinemagoer/cinemagoer): - -```shell -# If using Anaconda (recommended) -conda install -c conda-forge cinemagoer - -# Or using pip -python -m pip install cinemagoer -``` - -Here's an example to print the first review of the movie "The Dark Knight": -```python -from imdb import Cinemagoer - -# create an instance of the Cinemagoer class -ia = Cinemagoer() - -# search movie -movie = ia.search_movie("The Dark Knight")[0] -print(movie.movieID) -# '0468569' - -# Get reviews -movie = ia.get_movie('0468569', info=['reviews']) # Make sure to add the second argument -reviews = movie.get('reviews', []) - -for review in reviews: - print(review['content']) - print() - - -# Get actor -matt_damon = ia.get_person_filmography('0000354') - -# Get Matt Damon's movies -data = matt_damon['data'] -filmography = data['filmography'] -films_as_actor = filmography['actor'] -print(films_as_actor) -``` - -### Data Source: More Data Sources - -There are many other data sources that you can utilize in your project: - -- [Hugging Face Hub](https://huggingface.co/datasets) - - [Tutorial](https://huggingface.co/docs/datasets/en/load_hub) on How to Load a dataset from the Hub -- [Kaggle datasets](https://www.kaggle.com/datasets), which includes a variety of text datasets, such as news articles and movie reviews. -- [Yelp dataset](https://www.yelp.com/dataset) -- [SMS Spam Collection](https://www.kaggle.com/datasets/uciml/sms-spam-collection-dataset) is composed by 5,574 English, real and non-enconded messages, tagged according being legitimate (ham) or spam. -- [Enron email dataset](https://www.cs.cmu.edu/~./enron/) -- [News articles](https://archive.ics.uci.edu/dataset/137/reuters+21578+text+categorization+collection) in UCI Machine Learning Repository -- [Awesome Public Datasets](https://github.com/awesomedata/awesome-public-datasets) -- [Amazon AWS Registry of Open Data](https://registry.opendata.aws/), which includes several text datasets, such as Wikipedia and Common Crawl. -- ... - -Feel free to explore and choose the data source that fits your project's needs. - -### Pickling Data - -When you download text data from the Internet, it is often useful to save it to disk so that you do not have to re-download it every time you run your program. One way to do this in Python is to use the built-in `pickle` library, which allows you to serialize Python objects and save them to a file. - -In addition to pickling, you can also save files using JSON format. To explore more about the built-in `json` library, feel free to ask AI tools or visit the official Python documentation website. - ---- - -## Part 2: Analyzing Your Text - -This part consists of **required steps** that all students must complete, and **optional techniques** that you can choose from to extend your analysis. - -### Required Steps - -All students must complete the following steps: - -#### 1. Text Cleaning and Preprocessing - -(**Note**: This step is required.) - -Before analyzing your text, you need to clean and preprocess it. This includes: - -- Removing unwanted content (e.g., Project Gutenberg preambles, HTML tags, special characters) -- Converting text to lowercase for consistency -- Handling punctuation appropriately -- Dealing with encoding issues if any - -Real-world text data is often messy, and proper cleaning is essential for accurate analysis. - -#### 2. Removing Stop Words - -(**Note**: This step is required.) - -Stop words are words that occur frequently in text but do not provide useful information for analysis. Examples of stop words include "the", "and", "a", "is", etc. Removing stop words helps to: - -- Reduce the size of the text data -- Improve the accuracy of analysis -- Focus on meaningful words that carry semantic value - -You can use built-in stop word lists from libraries like NLTK, or create [your own custom list](https://github.com/OIM3640/resources/blob/main/code/data/stopwords.txt). - -#### 3. Word Frequency Analysis - -(**Note**: This step is required.) - -One way to begin to process your text is to take each unit of text (for instance, books from Project Gutenberg, or perhaps a collection of movie reviews) and summarize it by counting the number of times a particular word appears in the text. A natural way to approach this in Python would be to use a **dictionary** where the keys are words that appear and the values are frequencies of words in the text. If you want to do something fancier, you can use [TF-IDF features](https://en.wikipedia.org/wiki/Tf%E2%80%93idf). - -#### 4. Computing Summary Statistics - -(**Note**: This step is required.) - -Beyond calculating word frequencies, there are other methods to summarize text. For instance, you may want to: - -- Identify the top 10 or top 20 most frequent words in each text -- Determine words that appear frequently in one text but not in others -- Calculate average word length, sentence length, or document length -- Compare vocabulary richness across different texts - -We practiced this using Jane Austen's novel in class, so I recommend starting with that example. - -#### 5. Data Visualization - -(**Note**: This step is required.) - -You must create at least one visualization to present your analysis results. This could include: - -- Bar charts showing top N most frequent words -- Word clouds (can use the `wordcloud` library) -- Line graphs comparing statistics across different texts -- Simple ASCII-based visualizations if you want to avoid matplotlib - -Visualizations help communicate your findings effectively and make your analysis more engaging. - -### Optional Techniques - -Choose **at least one** of the following advanced techniques to extend your analysis: - -### Optional Technique 1: Natural Language Processing - -(**Note**: Choose at least one optional technique.) - -[NLTK](https://www.nltk.org/) - the Natural Language Toolkit - is a powerful tool for processing human language data. It provides a wide range of capabilities, such as part-of-speech tagging, sentiment analysis, and full sentence parsing. - -To use NLTK, you need to install `nltk`: - -```shell -# If using Anaconda (recommended) -conda install -c conda-forge nltk - -# Or using pip -python -m pip install nltk -``` - -Here is an example of doing [sentiment analysis](https://en.wikipedia.org/wiki/Sentiment_analysis) using the `VADER` library in NLTK: - -```python -import nltk -nltk.download('vader_lexicon') # Download required data -from nltk.sentiment.vader import SentimentIntensityAnalyzer - -sentence = 'Software Design is my favorite class because learning Python is so cool!' -score = SentimentIntensityAnalyzer().polarity_scores(sentence) -print(score) -# Output -# {'neg': 0.0, 'neu': 0.614, 'pos': 0.386, 'compound': 0.7417} -``` - -Notice: If you receive `Resource vader_lexicon not found` error when using `nltk`, you need to enter `python` in **Command Prompt** (or `python3` in **Terminal** on macOS), then enter `import nltk` and `nltk.download('vader_lexicon')` in Python interactive shell. - -You can also use [TextBlob](https://github.com/sloria/TextBlob) library, which is built on top of NLTK, for almost everything that NLTK does. Below is the brief introduction of TextBlob from its GitHub page: - -> TextBlob is a Python library for processing textual data. It provides a simple API for diving into common natural language processing (NLP) tasks such as part-of-speech tagging, noun phrase extraction, sentiment analysis, classification, and more. - -If you perform natural language processing, you can draw interesting insights from text data collected from the web. For instance, if you monitor a specific subreddit related to a political topic, you can gauge the sentiment of the community by analyzing the text of each post and comment. Similarly, you can analyze discussions on subreddits dedicated to movies to identify which recent movies have received the most negative reviews. There are tons of cool options here! - -### Optional Technique 2: Text Similarity - -(**Note**: Choose at least one optional technique.) - -It is potentially quite useful to be able to compute the similarity of two texts. Suppose that we have characterized some texts from Project Gutenberg using word frequency analysis. One way to compute the similarity of two texts is to test to what extent when one text has a high count for a particular word the other text also a high count for a particular word. Specifically, we can compute the cosine similarity between the two texts. This strategy involves thinking of the word counts for each text as being high-dimensional vectors where the number of dimensions is equal to the total number of unique words in your text dataset and the entry in a particular element of the vector is the count of how frequently the corresponding word appears in a specific document. If you find this approach unclear and wish to try it, you can either reach out to the professor, or ask AI tools for assistance. - -For a simple text similarity task, you can use external libraries, like [`TheFuzz` library](https://github.com/seatgeek/thefuzz), which uses [Levenshtein Distance](https://en.wikipedia.org/wiki/Levenshtein_distance) to calculate the differences between sequences. - -```python -from thefuzz import fuzz - -print(fuzz.ratio("this is a test", "this is a test!")) # 97 -print(fuzz.partial_ratio("this is a test", "this is a test!")) # 100 -print(fuzz.ratio("fuzzy wuzzy was a bear", "wuzzy fuzzy was a bear")) # 91 -print(fuzz.token_sort_ratio("fuzzy wuzzy was a bear", "wuzzy fuzzy was a bear")) # 100 -``` - -### Optional Technique 3: Text Clustering - -(**Note**: Choose at least one optional technique.) - -If you can generate pairwise similarities (say using the technique above), you can use Metric Multi-dimensional Scaling (MDS) to visualize the texts in a 2-dimensional space. This can help identify clusters of similar texts. - -In order to apply MDS to your data, you can use the machine learning toolkit `scikit-learn`. Here is some code that uses the similarity matrix defined in the previous section to create a 2-dimensional embedding of the four *Charles Dickens* and 1 *Charles Darwin* texts. - -```python -import numpy as np -from sklearn.manifold import MDS -import matplotlib.pyplot as plt - -# these are the similarities computed from the previous section -S = np.asarray([[1., 0.90850572, 0.96451312, 0.97905034, 0.78340575], - [0.90850572, 1., 0.95769915, 0.95030073, 0.87322494], - [0.96451312, 0.95769915, 1., 0.98230284, 0.83381607], - [0.97905034, 0.95030073, 0.98230284, 1., 0.82953109], - [0.78340575, 0.87322494, 0.83381607, 0.82953109, 1.]]) - -# dissimilarity is 1 minus similarity -dissimilarities = 1 - S - -# compute the embedding -coord = MDS(dissimilarity='precomputed').fit_transform(dissimilarities) - -plt.scatter(coord[:, 0], coord[:, 1]) - -# Label the points -for i in range(coord.shape[0]): - plt.annotate(str(i), (coord[i, :])) - -plt.show() -``` - -This will generate the following plot. The coordinates don't have any special meaning, but the embedding tries to maintain the similarity relationships that we computed via comparing word frequencies. Keep in mind that the point labeled 4 is the work by *Charles Darwin* and the other are by *Charles Dickens*. -text clustering - -### Optional Technique 4: Markov Text Synthesis - -(**Note**: Choose at least one optional technique.) - -You can use Markov analysis to learn a generative model of the text that you collect from the web and use it to generate new texts. You can even use it to create mashups of multiple texts. One of possibilities in this space would be to create literary mashups automatically. Again, let professor know if you go this route and we can provide more guidance. - -### Optional Technique 5: LLM (Large Language Model) Text Generation - -(**Note**: Choose at least one optional technique.) - -You can explore further possibilities by using the [OpenAI API](https://platform.openai.com/docs/overview). Feel free to ask for an API token if you're interested, and I'd be happy to provide it. I highly encourage you to give this a try! - ---- - -## Part 3: Learning with AI - -As you work through this project and experiment with different libraries in Python, you may encounter roadblocks or have questions about your code. That's when you can use AI tools, like ChatGPT to clear out any issues. You are also encouraged to learn other approaches, besides the techniques mentioned above, to process, analyze and visualize your own text dataset in Python from ChatGPT or other AI tools, who will serve as your assistant, providing helpful suggestions, aiding your learning process. - -**Reminder**: While AI tools can be incredibly helpful in resolving issues or suggesting new approaches, it’s important not to rely too heavily on them. Always test and validate the generated code, making sure it meets the project requirements and that you fully understand how the code works. Include comments in your code that indicate which parts were generated with AI assistance, and provide links or references to the sources if applicable. This practice not only helps maintain academic integrity but also demonstrates your learning process. - -Here's how to make the most out of AI tools (using ChatGPT as an example): - -- **Clearly Define Your Problem**: Take detailed notes on where you're stuck or what you're trying to achieve before asking ChatGPT for assistance. -- **Craft Detailed Prompts**: When asking ChatGPT for help, provide a clear and thorough description of the issue. The better you frame your question, the more helpful the response will be. -- **Review and Verify**: After receiving a response, carefully read the suggestions. Remember, AI-generated solutions may not always be accurate, so it's important to test the code and consult additional official documentation if needed. -- **Document Your Learning Process**: To track your progress, include ChatGPT Shared Links in your code comments or maintain a separate document. You may also take screenshots during your ChatGPT session and include them in your project write-up. - ---- - -## Part 4: Project Writeup and Reflection - -Write a summary of your project and your reflections on it in [`README.md`](README.md), using [Markdown format](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax). There is no need to use fancy words or ChatGPT. The [`README.md`](README.md) file should consist of the following sections: - -**1. Project Overview** (~1 paragraph) - -What data source(s) did you use? What technique(s) did you use to process or analyze them? What did you hope to create or learn through this project? - -**2. Implementation** (~1-2 paragraphs) - -Describe your implementation at a system architecture level. You should NOT walk through your code line by line, or explain every function (we can get that from your docstrings). Instead, talk about the major components, algorithms, data structures and how they fit together. You should also discuss at least one design decision where you had to choose between multiple alternatives, and explain why you made the choice. Use shared links and/or screenshots to describe how you used AI tools to help you or learn new things. - -**3. Results** (~1-3 paragraphs + figures/examples) - -Present what you accomplished in your project: - -- If you did some text analysis, what interesting things did you find? Graphs or other visualizations may be very useful here for showing your results. -- If you created a program that does something interesting (e.g. a Markov text synthesizer), be sure to provide a few interesting examples of the program's output. - -**4. Reflection** (~1-2 paragraphs) - -From a process point of view, what went well? What was the biggest challenge? How did you solve it? What could you improve? Was your project appropriately scoped? Did you have a good testing plan? - -From a learning perspective, what was your biggest takeaway from this project? How did AI tools help you? How will you use what you learned going forward? What do you wish you knew beforehand that would have helped you succeed? - ---- - -## Submitting your Project - -1. Push all the code and updated `README.md` to the GitGub repository. -2. Create a pull request to the upstream repository. Please learn how to create a pull request by following [this instruction](https://docs.github.com/en/desktop/working-with-your-remote-repository-on-github-or-github-enterprise/creating-an-issue-or-pull-request-from-github-desktop#creating-a-pull-request). -3. Submit your project's GitHub repository URL to Canvas. - ---- -*Updated*: *2025/10/26*