Model Training

Initially, split the model using train_test_split module. 

Python3




from sklearn.model_selection import train_test_split
  
X_train, X_test, y_train, y_test = train_test_split(X, y, 
                                                    test_size=0.3
                                                    random_state=111)
X_train.shape, X_test.shape, y_train.shape, y_test.shape


We will be testing our datasets on below models : 

  • K-Neighbors Classifier :  KNeighborsClassifier looks for topmost n_neighbors using different distance methods like Euclidean distance.
  • Decision Tree Classifier : In Decision tree each node is trained by splitting the data is continuously according to a certain parameter.
  • Random Forest : Random Forest Classifier fits a number of decision tree classifiers on many sub-samples of the dataset and then use the average to improve the results.
  • Logistics Regression : Logistic Regression is a regression model that predicts the probability of a given data belongs to the particular category or not.
  • Cat Boost : CatBoost implements decision trees and restricts the features split per level to one, which help in decreasing prediction time. It also handles categorical features effectively.
  • Gradient Boost : In Gradient Boost an decision trees are implemented in a sequential manner which enhance the performance.

Python3




from sklearn.metrics import accuracy_score
from sklearn.neighbors import KNeighborsClassifier
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.linear_model import LogisticRegression
import catboost as cb
from xgboost import XGBClassifier
  
rf = RandomForestClassifier(n_estimators=1000, max_depth=10, random_state=0)
cbc = cb.CatBoostClassifier(verbose=0, eval_metric='Accuracy', loss_function='MultiClass')
xgb = XGBClassifier(n_estimators=1000, learning_rate=0.05)
  
for clf in (rf, cbc, xgb):
    clf.fit(X_train, y_train)
    preds = clf.predict(X_test)
    print(clf.__class__.__name__,accuracy_score(y_test, preds))


Output :

RandomForestClassifier 0.78
CatBoostClassifier 0.8333333333333334
XGBClassifier 0.7933333333333333

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.

Similar Reads

Import Libraries and Dataset

Firstly we need to import Libraries :...

Exploratory Data Analysis

...

Data Preprocessing

...

Model Training

Let’s find out the count of each music label....

Neural Network

...

Evaluation

...

Conclusion

...