Teaching portfolio · COM5508

Media Data Analytics

  • Postgraduate
  • CityUHK
  • Spring 2019
  • Python
  • Machine learning

Seven hands-on Python notebooks that take communication students from their first read_csv to building, validating, and interpreting predictive models of media data.

In Spring 2019 I was the Teaching Assistant for COM5508 Media Data Analytics, a postgraduate course in the Department of Media and Communication, City University of Hong Kong. I designed and taught the weekly tutorials that turn each lecture's concepts into working code.

The tutorials follow one real dataset, the IMDB 5000 movies, through exploration, regression, classification, and clustering, then move to text, with topic models of journal abstracts and sentiment in film reviews. A closing demo puts the whole pipeline together.

Teaching Assistant Zhicong Chen · Spring 2019
01 / The course

Computational methods for communication students.

COM5508 trains students of communication and new media to analyze and visualize numeric, text, and visual data from social media with computational social science methods. The emphasis is on building, validating, and applying predictive models of user behaviour, alongside the policy and ethics questions that come with them: privacy, data integrity, and open access.

The syllabus calls for "hands-on tutorials". Those are the part of the course this page documents.

3credit units · one semester
P5–P6postgraduate level, taught in English
100%continuous assessment, no exam
7tutorial notebooks, open on GitHub

Keyword syllabusTopics the course is built around

  • Computational social science
  • Web analytics and data mining
  • Supervised learning: prediction and classification
  • Unsupervised learning: clustering
  • Recommender systems
  • Data visualization and dashboards

Course intended learning outcomes 5 CILOs

  1. 1 Understand

    the principles and procedure of analyzing and visualizing social media data.

    Assessed in tasks 1 · 3
  2. 2 Explain

    core data-analytics techniques and the strengths and weaknesses of different computational approaches.

    Assessed in tasks 2 · 3
  3. 3 Interpret

    numerical, textual, and visual data to find patterns in user-generated content and behaviour.

    Assessed in tasks 1 · 2
  4. 4 Value

    ethical and socially responsible practice in data analysis and visualization.

    Assessed in tasks 1 · 3
  5. 5 Critique

    plans for studying social media content, both when designing them and when carrying them out.

    Assessed in tasks 2 · 3
02 / Tutorials

One dataset, one pipeline, one new method each week.

Each tutorial opens a Jupyter notebook beside the lecture of the same number. The first four reuse the same table of 5,043 films, so students spend their attention on the method rather than on learning a new dataset. The last two move from numbers to text.

  1. Explore
  2. Regress
  3. Classify
  4. Cluster
  5. Topics
  6. Sentiment
  7. End-to-end demo
Lecture 4 · ExplorationNumPy, Pandas, Matplotlib

NumPy, pandas, and Matplotlib

What does audience attention look like, and which features move with a film's IMDb score?

  1. Load the IMDB 5000 table (28 variables, 100 years, 66 countries) into a DataFrame.
  2. Separate numeric from categorical features; log-transform the skewed counts of likes, votes, and dollars.
  3. Plot each feature's distribution, then its relationship with imdb_score.
  4. Compare mean scores across languages, countries, years, and content ratings; dummy-code the categories.

TakeawayLook before you model: most audience metrics are heavily right-skewed until logged.

  • pandas
  • numpy
  • matplotlib
Open notebook ↗
Lecture 5 · RegressionSupervised learning

From least squares to decision boundaries

How much of a film's rating can its popularity signals explain, and how should the features be prepared?

  1. Fit a linear regression on raw features, then on log-transformed and standardized ones, and compare R².
  2. Read a full OLS summary in statsmodels next to the scikit-learn estimates.
  3. Watch stochastic gradient descent diverge on unscaled data, then recover after standardization.
  4. Move to classification with logistic regression and linear discriminant analysis (US vs. Chinese films).

TakeawayFeature preparation is part of the model: logging and scaling raised R² from 0.33 to 0.44.

  • scikit-learn
  • statsmodels
Open notebook ↗
Lecture 6 · ClassificationSupervised learning

Decision trees, neural networks, and honest evaluation

Can we sort films into five score bands, and how do we know a classifier really works?

  1. Bin imdb_score into five classes and set the majority-class baseline (66.6%).
  2. Dummy-code countries, languages, people, and multi-label genres for scikit-learn's CART trees.
  3. Train a decision tree, export it with Graphviz, and contrast training accuracy with 10-fold cross-validation.
  4. Compare a multilayer perceptron, logistic regression, and a random forest on the same folds.

TakeawayA tree that scores 100% on its own training data scores 69% under cross-validation.

  • scikit-learn
  • graphviz
Open notebook ↗
Lecture 7 · ClusteringUnsupervised learning

Finding audience segments with K-means and DBSCAN

Without labels, do films fall into natural groups by Facebook likes and user votes?

  1. Log-transform the attention metrics and pick two interpretable dimensions to cluster on.
  2. Partition the films with K-means and plot the clusters.
  3. Run density-based DBSCAN, which finds its own number of clusters and flags noise points.
  4. Compare the two solutions with the Davies–Bouldin index.

TakeawayDifferent algorithms encode different ideas of what a cluster is. Validate with a metric and with your eyes.

  • scikit-learn
  • matplotlib
Open notebook ↗
Lecture 9 · Text as dataTopic modeling

Latent Dirichlet allocation on research abstracts

What themes run through abstracts from the Journal of Computer-Mediated Communication?

  1. Turn 68 abstracts into a document-term matrix (1,969 terms, English stop words removed).
  2. Fit a 10-topic LDA model.
  3. Read the model three ways: top words per topic, likely topics per word, and the topic mix of each document.

TakeawayA topic model is a set of probability tables. Interpretation happens in reading them.

  • scikit-learn
  • CountVectorizer
Open notebook ↗
Lecture 10 · Text as dataSentiment analysis

Classifying film reviews with Naive Bayes

Can a bag of words tell a positive review from a negative one, and which words decide?

  1. Load 2,000 labelled reviews from NLTK's movie_reviews corpus and build word-presence features.
  2. Hold out 20% (400 reviews) and train a Naive Bayes classifier on the other 1,600.
  3. Inspect the most informative words, such as outstanding and ludicrous.
  4. Score new sentences written in class.

Takeaway73.5% held-out accuracy from word presence alone, and a model whose reasoning you can read.

Capstone demoModel for the group project

Predicting IMDb scores, end to end

Does adding more features always make a better model?

  1. Frame the problem: choose the dependent variable and the predictors, then bin the score.
  2. Impute, transform, and standardize numeric features; split into training and test sets.
  3. Tune a random forest with grid-search cross-validation.
  4. Add genre dummies, then director and actor dummies, and test whether performance actually improves.

TakeawayA complete, reproducible workflow students can adapt for their own group projects.

  • scikit-learn
  • GridSearchCV
Open notebook ↗
Before the first tutorialSetup

Running the notebooks

Everything runs locally in Jupyter on a standard scientific Python stack.

  1. Install Anaconda (Python 3) and start Jupyter Notebook.
  2. Download movie_metadata.csv from the IMDB 5000 Movie Dataset on Kaggle and place it beside the notebooks.
  3. For L6, install Graphviz (conda install python-graphviz); for L10, fetch the NLTK corpus with nltk.download('movie_reviews').
  4. Each notebook links to the scikit-learn API page and user guide for every method it uses.
  • Python 3
  • Jupyter
  • Anaconda
Repository ↗
03 / Teaching approach

Make the pitfalls happen in class, on purpose.

The notebooks are written so the common mistakes in applied machine learning show up live, where they can be discussed, instead of later in a student's project.

Design principles

Four habits that run through every notebook.

  • A running dataset The IMDB 5000 table returns in L4 to L7 and the demo, so each week adds a method to familiar data, and the results can be compared across weeks.
  • Baseline first Before any model, students write down what guessing the most common class would score. Every model after that is judged against it.
  • Validate, don't just fit Training accuracy and cross-validated accuracy sit side by side, so overfitting is something students see in the numbers.
  • Learn to read the docs Each method links to its scikit-learn API page and user guide. This builds the self-directed learning that the individual exercises assess.

Which classifier beats the baseline?

Mean 10-fold cross-validated accuracy predicting five IMDb score bands (L6). The dashed line is the majority-class baseline.

  • Random forest 0.731
  • Decision tree 0.692
  • Neural network 0.666
  • Logistic regression 0.633
Baseline: always predict the most common band, 0.666 Scale: 0 to 1

Why scaling matters

The same SGD regressor on the same logged features (L5), before and after standardization.

−2.3 × 10¹⁷R², unscaled: the optimizer diverges
0.43R², standardized: matches OLS (0.44)
04 / Assessment & readings

Tutorial work counts toward the grade.

The course is assessed entirely through coursework. Tutorial tasks are graded on the ability to reproduce the procedures and methods of social media analysis and visualization from worked examples, and the notebooks above are those examples.

30%

Class participation & tutorial tasks

Replicate the procedure and methods of social media data analysis and visualization from given examples.

CILO 1 · 3 · 4Tutorials
40%

Individual exercises

Develop and test customized algorithms to analyse and visualize social media data, with self-directed learning beyond class.

CILO 2 · 3 · 5
30%

Group project & presentation

Explore, analyse, and visualize social media data in teams, then explain the process and results with technical accuracy.

CILO 1 · 2 · 4 · 5

Reading list Compulsory and additional

Course description, learning outcomes, assessment, and readings are taken from the CityUHK course catalogue record for COM5508 (effective Semester A 2025/26). The tutorials are from the Spring 2019 offering.

Reuse

The notebooks are open for teaching.

Instructors are welcome to adapt these tutorials for their own courses. I'm always happy to talk about teaching computational methods to communication students.