Genre classification with Logistic Regression
Logistic Regression is a Machine Learning classification algorithm that is often used to predict the probability of a categorical dependent variable; in our case we want to predict the genre of a given input song sample.
First of all, we need the logistic regression model and functions that we can import from the sklearn module.
Then, in order to avoid overfitting we used k-fold cross validation to train our model.
By testing we found out that the leave one out approach was too expensive and the gain in performance was very small, so it was not considered worthwhile.
lr = LogisticRegression()
cv = KFold(n_splits=n_folds)
scores = model_selection.cross_val_score(lr, x, y, cv=cv)
y_pred = model_selection.cross_val_predict(lr, x, y, cv=cv)
# accuracy = scores.mean()
Now that we have the model predictions, calculating precision, recall and other useful pieces of information or plotting a confusion matrix to see the quality of the predictions are easy tasks.
print(classification_report(y, y_pred))
conf_matr = confusion_matrix(y, y_pred)
# plot conf_matr
Performance with FFT
Using FFT data we don't get good results and it takes about 47 minutes to fit the model. Obtained results are the following:
Precision | Recall | F1-score | |
---|---|---|---|
Blues | 0.36 | 0.39 | 0.38 |
Classical | 0.68 | 0.60 | 0.64 |
Country | 0.18 | 0.19 | 0.18 |
Disco | 0.18 | 0.18 | 0.19 |
Jazz | 0.47 | 0.46 | 0.46 |
Metal | 0.25 | 0.23 | 0.24 |
Pop | 0.21 | 0.16 | 0.18 |
Reggae | 0.15 | 0.11 | 0.13 |
Rock | 0.13 | 0.20 | 0.16 |
Average / total | 0.29 | 0.28 | 0.28 |
Performance with MFCC
Using MFCC data It takes about 3 seconds to run so execution is a lot faster and obtained results are much better.
Precision | Recall | F1-score | |
---|---|---|---|
Blues | 0.31 | 0.37 | 0.34 |
Classical | 0.72 | 0.83 | 0.77 |
Country | 0.38 | 0.38 | 0.38 |
Disco | 0.38 | 0.38 | 0.38 |
Jazz | 0.32 | 0.23 | 0.27 |
Metal | 0.60 | 0.88 | 0.71 |
Pop | 0.61 | 0.86 | 0.71 |
Reggae | 0.46 | 0.22 | 0.30 |
Rock | 0.14 | 0.08 | 0.10 |
Average / total | 0.44 | 0.47 | 0.44 |