Classification Using Scikit-Learn:

  • Classification Analysis helps to predict categorical labels (e.g., spam or not spam).
  • Our goal in Exercise 6.4 is to build a classifier that we will train on a subset of the WHR numerical data (x) and the region data (y), so that we can predict regions from data for countries that we have not trained our model on.
    • Our numerical data (x) will include: Happiness, LogGDP, Support, Life, Freedom, Generosity, Corruption, Positive, and Negative sentiment
    • Our region data (y) will include the regions such as: North America, Western Europe, East Asia, North America, etc.

The StandardScaler Object:

  • The StandardScaler object is used to standardize features by removing the mean and scaling to unit variance. In other words, this will have the data look more like a normal distribution with a mean of 0 and a standard deviation of 1.
    • More about standardization and the StandardScaler class can be found here.

The train_test_split Function:

  • The train_test_split function is used to split the data into a training set and a test set. The training set is used to train the model, while the test set is used to evaluate its performance.

The svm & decision tree classifiers:

  • The Support Vector Machines (SVM) classifier cuts through the data space to separate different categories from one another.

Diagram of a Support Vector Machine classifier showing a hyperplane separating two data categories in feature space

  • The Decision Tree classifier is used to formulate a series of yes/no questions on the data to distinguish the categories from one another.

Evaluating the Accuracy of the Classifier:

  • The accuracy_score function is used to evaluate the accuracy of the classifier. It compares the predicted labels with the true labels and returns the accuracy as a percentage.
  • Sklearn helps to evaluate the accuracy as it provides a uniform interface to build different sorts of classifiers and compare their performance.