Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
COMP30027 Machine Learning
Project 1: Music genre classification with naı¨ve Bayes
Submission: Source code (in Python) and written responses
Groups: You may choose to form a group of 1 or 2.
Groups of 2 will respond to more questions, and commensurately produce more
implementation.
Marks: The project will be marked out of 16 points (individual project) or 24 points
(group project). In either case, this project will contribute 20% of your total
mark.
Overview
A visualisation (mel spectrogram) of a
music clip from the GZTAN dataset [3].
State-of-the-art AI research is focused on developing com-
puter systems that can recognize and understand text, im-
ages, and audio in the ways that humans do. A classic
problem in audio AI is the problem of music genre clas-
sification, which is useful for applications like music rec-
ommendation systems. Given a piece of music, how do
we interpret what “type” of music it is (e.g., pop, classical,
hip-hop, or jazz)? This task is challenging for computers
because the artists, styles, and features of music within a
genre can be quite varied, and songs from different genres
may share some features.
In this project, you will implement a supervised naı¨ve
Bayes learner to classify the genre of a music clip from high-level acoustic features. You will train,
test, and evaluate your classifier on a provided dataset, and then you will have a choice of either
extending this basic model in various ways, or using it to answer some conceptual questions about
naı¨ve Bayes.
Data
The data for this assignment is drawn from the GTZAN music genre dataset [1], a dataset for music
genre classification. It consists of 1000 30-second mp3 audio clips from 10 different classes (100
samples per class). The classes are blues, classical, country, disco, hip hop, jazz, metal, pop, reggae,
and rock. For this assignment, we’ll use a processed version of the dataset from Kaggle [2], which
provides 57 high-level acoustic features [3] extracted from the music clips. You do not need the
original audio files for this assignment, though if you are interested, you can download them through
Kaggle.
Separate training and test datasets are provided. Please use the provided train/test splits for this
assignment, unless a question asks you to create your own splits. Each row in the dataset is a music
clip with the class label given in the label column.
Naive Bayes classifier [4 marks]
There are some suggestions for implementing your learner in the “Naı¨ve Bayes” and “Discrete &
Continuous Data” lectures, but ultimately, the specifics of your implementation are up to you. Your
implementation must be able to perform the following functions:
• preprocess() the data by reading it from a file and converting it into a useful format for
training and testing
• train() by calculating prior probabilities and likelihoods from the training data and using
these to build a naive Bayes model
• predict() classes for new items in a test dataset
• evaluate() the prediction performance by comparing your model’s class outputs to ground
truth labels
Your implementation should be able to handle numeric attributes and it should assume that nu-
meric attributes are Gaussian-distributed. Your model will not be expected to handle nominal at-
tributes.
Your implementation should actually compute the priors, likelihoods, and posterior probabilities
for the naı¨ve Bayes model. You may use built-in functions to read data and compute Gaussian prob-
abilities. However, you must implement the naı¨ve Bayes algorithm yourself and not simply call an
existing implementation such as GaussianNB from scikit-learn.
Task 1. Pop vs. classical music classification [8 marks]
Use the pop vs classical train.csv dataset to train your naı¨ve Bayes model and then eval-
uate it on the pop vs classical test.csv dataset. Answer questions 1-2 below in a short
write-up (no more than 250 words total).
1. Compute and report the accuracy, precision, and recall of your model (treat “classical” as the
“positive” class). [3 marks]
2. For each of the features X below, plot the probability density functions P (X|Class = pop)
and P (X|Class = classical). If you had to classify pop vs. classical music using just one of
these three features, which feature would you use and why? Refer to your plots to support your
answer. [5 marks]
• spectral centroid mean
• harmony mean
• tempo
Task 2. 10-way music genre classification [4 marks (individual) or 12 marks (group of
2)]
Use the gztan train.csv dataset to train your naı¨ve Bayes model and then evaluate it on the
gztan test.csv dataset. If you are working in a group of 1, answer 1 of the questions below
for 4 marks. If you are working in a group of 2, answer 3 of the questions below for 12 marks. Each
question response should be no more than 250 words and include figures and/or tables as appropriate.
When reporting the performance of a model, you should include a breakdown of the performance over
categories in addition to reporting the overall accuracy.
3. Compare the performance of the full model to a 0R baseline and a one-attribute baseline. The
one-attribute baseline should be the best possible naı¨ve Bayes model which uses only a prior
and a single attribute. In your write-up, explain how you implemented the 0R and one-attribute
baselines. [4 marks]