Skip to main content

COMS 930 tutorials

Computational Methods in Social Sciences · University of Kansas

Hands-on labs and notebooks: measuring and visualizing networks in R, and analyzing images and text with machine learning in Python.

Every tutorial can be read here with its code and output. Download the R Markdown labs to run them in RStudio, or open the Python notebooks in Google Colab to run your own copy in the browser, with nothing to install. Use the search box in the sidebar to find a function or topic across all tutorials.

Network analysis in R

Descriptive network measures
Degree, in- and out-degree, closeness, betweenness and eigenvector centrality in an international diplomacy network, and how the measures correlate.
R · igraph · centrality

Network visualization
Visualizing networks for readers who don’t know the data, using prisoner friendship, needle-sharing and other networks.
R · igraph · visualization

Both labs use the Comparative Networks Dataset (McMillan, Phadke, Goist, & Denny, 2017), which is shared with enrolled students on Canvas.

Images and text in Python

Visual feature extraction
How a computer turns an image into keypoints, feature vectors and clustered “visual words,” the building blocks of bag-of-visual-words analysis.
Python · OpenCV · scikit-learn

Facial emotion analysis with DeepFace
Detecting faces and their dominant emotions in YouTube video thumbnails, then turning the emotion scores into variables for analysis.
Python · DeepFace · pandas

Fine-tuning BERT for classification
Fine-tuning DistilBERT with Hugging Face transformers to predict a book’s genre from its Goodreads reviews, from train/test split to evaluation.
Python · Hugging Face · supervised learning

Credits

The BERT tutorial is adapted from the AI for Humanists tutorial “Training and Fine-Tuning BERT for Classification” by Maria Antoniak, Melanie Walsh, and David Mimno.