using the confusion matrix to measure accuracy in multiclass problems with multiclass problemswe should also not limit our interest to how well we manage to correctly classify the genres in additionwe should also look at which genres we actually confuse with each other this can be done with the so-called confusion matrixfrom sklearn metrics import confusion_matrix cm confusion_matrix(y_testy_predprint(cm[[ ]it prints the distribution of labels that the classifier predicted for the test set for every genre since we have six genreswe have six by six matrix the first row in the matrix says that for classical songs (sum of the first row)it predicted to belong to the genre classicalone to be jazz songtwo to belong to the country genreand two to be metal the diagonal shows the correct classifications in the first rowwe see that out of songs ( ) have been correctly classified as classical and were misclassifications this is actually not that bad the second row is more soberingonly out of jazz songs have been correctly classified--that is only percent of coursewe follow the train/test split setup from the previous so that we actually have to record the confusion matrices per cross-validation fold we also have to average and normalize later on so that we have range between (total failureto (everything classified correctlya graphical visualization is often much easier to read than numpy arrays matplotlib' matshow(is our friendfrom matplotlib import pylab def plot_confusion_matrix(cmgenre_listnametitle)pylab clf(pylab matshow(cmfignum=falsecmap='blues'vmin= vmax= ax pylab axes(ax set_xticks(range(len(genre_list))ax set_xticklabels(genre_listax xaxis set_ticks_position("bottom"