Homework Assignments

Homework assignments in this course are individual tasks designed to enhance student learning and provide opportunities for independent practice. Detailed instructions for completing each assignment, along with submission guidelines, will be made available on the class website.

It is essential for students to adhere strictly to these submission instructions, as assignments that fail to comply or are submitted past the deadline will not be considered for grading.

This policy ensures fairness and consistency in the evaluation process while emphasizing the importance of personal responsibility in meeting academic expectations.

The instructions and grading criteria are subject to change. Please check this site for updates and follow announcement in class and on iCollege


Assignments

Table with Homework Assignments and Due Dates
AssignmentDue DateStatus
Homework 1: Text Analysis of the 20 Newsgroups CorpusWednesday, September 16, 2026 at 23:59Posted
Homework 2: Bike-Share Trip AnalysisWednesday, September 23, 2026 at 23:59Posted
Homework 3: Ranking Scholarship ApplicationsWednesday, September 30, 2026 at 23:59Posted
Homework 4: A Pipeline Through Five Gigabytes of ReviewsWednesday, October 7, 2026 at 23:59Posted
Homework 5: A Query Engine Made of PipesWednesday, October 14, 2026 at 23:59Posted
Homework 6: Northwind, Audited and JoinedWednesday, October 21, 2026 at 23:59Posted
Homework 7: Invasive Plants, from Raw File to ReportWednesday, October 28, 2026 at 23:59Posted
Homework 8: Same Numbers, Different PicturesWednesday, November 4, 2026 at 23:59Posted
Homework 9: An Answer with Error BarsWednesday, November 11, 2026 at 23:59Posted
Homework 10: Three Ways to Find ItWednesday, November 18, 2026 at 23:59Posted
Homework 11: Fewest HopsWednesday, December 2, 2026 at 23:59Posted
Homework 12: Does It Beat Guessing?Wednesday, December 9, 2026 at 23:59Posted

Please review instructions for completing and submitting each of the assignments.

Homework 1: Text Analysis of the 20 Newsgroups Corpus

Due: Wednesday, September 16, 2026 at 23:59 (Posted)
Build a complete command-line program that analyzes a corpus of newsgroup messages using nothing but core Python — no machine learning libraries, no regular expressions. Across ten test-driven phases you will read and tokenize text files, score each article for sentiment against the AFINN-111 lexicon, count terms with nested dictionaries, and rank the most distinctive keywords of each newsgroup by TF–IDF, then assemble everything into a single deterministic report. Every phase ships with its own tests, so you find out whether the piece you just wrote works before you build the next one on top of it.

Homework 2: Bike-Share Trip Analysis

Due: Wednesday, September 23, 2026 at 23:59 (Posted)
Analyze a month of campus bike-share trips using nothing but core Python — no pandas, no NumPy, no file reading, just a list of dictionaries and the loop patterns from

Homework 3: Ranking Scholarship Applications

Due: Wednesday, September 30, 2026 at 23:59 (Posted)
Order a list of scholarship applications from the lowest review score to the highest, without sorted(), .sort(), min(), or max(). Across seven test-driven phases you will build the solution out of small functions with clear contracts: one comparison rule that settles what a tie means, a function that combines two ordered groups, a function that splits a group in two, a function that orders the groups too small to split, and a function that uses all of them to order a group of any size. Then you will add a policy for applications with missing or unusable scores and print an exactly formatted ranking report. Each phase ships with its own tests, and only at the end are you asked to name the method you have built.

Homework 4: A Pipeline Through Five Gigabytes of Reviews

Due: Wednesday, October 7, 2026 at 23:59 (Posted)
Find the restaurants Yelp reviewers disagreed about most in 2018 and 2019, working from the 5.3 GB review file on the cluster, which is far too large to load into memory. Across nine test-driven phases you will build a pipeline of stages in core Python, each reading the file the stage before it wrote, one record at a time. You will filter the business and review files, join reviews to a small lookup table, compute count, mean, and standard deviation for thousands of restaurants without storing the values, and sort a file of any size by reusing your HW03 merge sort on files. Finally you will run the whole pipeline from the command line and print a ranked report. Every phase is tested on a small sample of the dataset before you run it on the real thing.

Homework 5: A Query Engine Made of Pipes

Due: Wednesday, October 14, 2026 at 23:59 (Posted)
Answer one question about 863,077 US Forest Service records of invasive plants — which ones cover the most ground, and where — by building the machine that runs the SQL rather than writing the SQL. Across eight test-driven phases you will write a single Python file that becomes seven command-line tools, each reading CSV on stdin and writing CSV on stdout, then compose them into a pipeline with Unix pipes: filter, select, group-by, aggregate, order-by, head. Along the way you will parse CSV correctly including quoted fields with embedded commas and newlines, decide what a text field actually means and handle nulls the way SQL does, stream rows so memory does not grow with the file, sort by several keys in either direction, and compute count, sum, avg, min, and max for a group without ever holding the group’s rows.

Homework 6: Northwind, Audited and Joined

Due: Wednesday, October 21, 2026 at 23:59 (Posted)
Somebody hands you four CSV files from Northwind, the small food importer from Session 7, and asks which product category earns the most. The answer is one groupby away; this assignment is about everything that has to be true before that groupby can be trusted. Across seven test-driven phases you will write a single pandas program that audits the tables, splits a file stored at the wrong grain into the two tables it really is, finds rows whose foreign key points at nothing, joins four tables into one view without dropping or repeating a row, and then groups, counts, and ranks to produce a report. Along the way you will meet four things wrong with the data: freight repeated on every order line, rows with no partner, a unitprice column that exists twice and means two different things, and lines with no category whose revenue disappears without an error if you group carelessly.

Homework 7: Invasive Plants, from Raw File to Report

Due: Wednesday, October 28, 2026 at 23:59 (Posted)
In HW05 you built a query engine for the Forest Service file of invasive plants, one row at a time. This week you meet the same 863,069 records again with pandas, where a question that took a pipeline takes a line — and a line of pandas will always give you a number, whether or not the number means anything. Across seven test-driven phases you will write a single program that inspects the raw table, cleans it (text into dates, missing values disguised as the word Unknown, values that cannot be true), computes whole columns at once with no loop, and summarises the records by forest, by species, and by year. The assignment turns on one column: half of the records have no cover_pct, and the average cover is 17.1 %, 8.5 %, or 18.4 % depending on what you decide a blank means.

Homework 8: Same Numbers, Different Pictures

Due: Wednesday, November 4, 2026 at 23:59 (Posted)
Describe the Forest Service file of invasive plants first in a handful of numbers, then in pictures, and find out that each hides things the other shows. The mean size of an infestation is 9.12 acres and the median is 0.114 — both are “the average”, and one is 80 times the other. Meanwhile four small datasets share the same means, the same standard deviation, and the same correlation, and look nothing alike once drawn. Across seven test-driven phases you will compute centre and spread from their definitions, find quartiles and flag outliers without removing them, measure correlation, and then draw a histogram, a bar chart, a line, and a scatter plot with matplotlib. You will also write a function that audits any figure for what a reader needs — labels, a title, and bars that start at zero — and save a set of figures from the real data.

Homework 9: An Answer with Error Bars

Due: Wednesday, November 11, 2026 at 23:59 (Posted)
A coffee cart sells pastries that cost $1 to bake and sell for $3, and whatever is left in the evening is thrown away. About forty customers a day want one. How many should the cart bake each morning? There is no column to look this up in; the way to get the answer is to let the computer live through ten thousand mornings and count. That is a simulation, and its result has a property no result in this course has had so far: run it again and it changes — one seed says 42, another says 43. Across seven test-driven phases you will check a simulation against a problem with a known answer, run many trials from one seeded generator, attach a standard error and an interval to every estimate, build a model of the cart, compare batch sizes on the same random days, and apply the same idea to real data with the bootstrap.

Homework 10: Three Ways to Find It

Due: Wednesday, November 18, 2026 at 23:59 (Posted)
Almost every program you have written this term looks something up: if word in words, businesses[business_id]. This week you build what is inside, three times, and count the work each way takes. On 100,000 Yelp business ids, looking at every item costs about 50,000 comparisons per lookup, halving a sorted list costs 16, and a hash table costs about one — a difference that does not depend on how fast the computer is. Across seven test-driven phases you will write linear search, binary search, and a search for where a value belongs in a sorted list; a hash function for strings; and a hash table of buckets that grows as it fills. Then you will compare the three by counting comparisons, and work out when sorting pays for itself.

Homework 11: Fewest Hops

Due: Wednesday, December 2, 2026 at 23:59 (Posted)
You are in Atlanta and want to get to Sydney, and there is no direct flight. A booking site answers in a second; how did it find that among 37,041 routes between 3,257 airports? A table has rows, but this data has connections, and the question is about following them. Across seven test-driven phases you will read a file of airline routes into an edge list, build a graph as a dictionary of dictionaries, and find the fewest flights between any two airports with a search that spreads outward from the start one flight at a time. Then you will reconstruct the route itself, find which airports hang together at all, and discover that the route with the fewest flights from Atlanta to Sydney goes the wrong way round the planet, 9,066 km longer than another with just as many flights.

Homework 12: Does It Beat Guessing?

Due: Wednesday, December 9, 2026 at 23:59 (Posted)
A third of the restaurants in the Yelp data have closed. From what is known about a restaurant — its rating, its number of reviews, its price level, whether it lists opening hours — can a program learn to tell the ones that close from the ones that stay open? Getting a model to produce predictions takes three lines; this assignment is about the question that matters afterwards: are the predictions any good, and compared with what? Across six test-driven phases you will turn a table into features and a target, put a share of the rows aside for testing, compute the baseline that any model has to beat, count the four kinds of right and wrong prediction, and train decision trees of increasing depth with scikit-learn. A tree allowed 30 questions is right on 98.9 % of the restaurants it studied and on 64.9 % of the ones it has not seen — worse than always saying “open”.