Exploratory Data Analysis
Let’s find out the count of each music label.
Python3
music_data[ 'label' ].value_counts() |
Output:
blues 100 classical 100 country 100 disco 100 hiphop 100 jazz 100 metal 100 pop 100 reggae 100 rock 100
We can also analysis the sound waves of the audio using the Librosa library.
Let’s visualize few of them with the below code.
Python3
path = 'genres_original/blues/blues.00000.wav' plt.figure(figsize = ( 14 , 5 )) x, sr = librosa.load(path) librosa.display.waveplot(x, sr = sr) id .Audio(path) print ( "Blue" ) |
Output :
Blue
Python3
path = 'genres_original/metal/metal.00000.wav' plt.figure(figsize = ( 14 , 5 )) x, sr = librosa.load(path) librosa.display.waveplot(x, sr = sr,color = 'orange' ) id .Audio(path) print ( "Metal" ) |
Output :
Metal
Python3
path = 'genres_original/pop/pop.00000.wav' plt.figure(figsize = ( 14 , 5 )) x, sr = librosa.load(path) librosa.display.waveplot(x, sr = sr,color = 'purple' ) id .Audio(path) print ( "Pop" ) |
Output :
Pop
Python3
path = 'genres_original/hiphop/hiphop.00000.wav' plt.figure(figsize = ( 14 , 5 )) x, sr = librosa.load(path) librosa.display.waveplot(x, sr = sr,color = 'grey' ) id .Audio(path) print ( "HipHop" ) |
Output :
HipHop
Python3
import numpy as np import seaborn as sns # Computing the Correlation Matrix spike_cols = [col for col in data.columns if 'mean' in col] # Set up the matplotlib figure f, ax = plt.subplots(figsize = ( 16 , 11 )); # Draw the heatmap with the mask and correct aspect ratio sns.heatmap(data[spike_cols].corr(), cmap = 'YlGn' ) plt.title( 'Heatmap for MEAN variables' , fontsize = 20 ) plt.xticks(fontsize = 10 ) plt.yticks(fontsize = 10 ); |
Output :
Music Genre Classifier using Machine Learning
Music is the art of arranging sound and noise together to create harmony, melody, rhythm, and expressive content. It is organized so that humans and sometimes other living organisms can express their current emotions with it.
We all have our own playlist, which we listen to while traveling, studying, dancing, etc.
In short, every emotion has a different genre. So here today, we will study how can we implement the task of genre classification using Machine Learning in Python.
Before starting the code, download the data from this link.
Let’s start with the code.
Contact Us