Welcome back to our journey into the heart of unsupervised learning! We just explored the intricacies of Principal Component Analysis (PCA), and today, let's advance one step further into another dimensionality reduction technique, Independent Component Analysis, or ICA for short.
ICA is a technique you can use to untangle conflicting variables in a dataset or extract meaningful signals from noisy data, such as separating individual voices from a racket at a party. So, the goal of this lesson is to help you master the theoretical aspects of ICA, implement it using Python's scikit-learn
library, and interpret the results obtained. As always, we believe in learning by doing, so we'll illustrate these concepts using the Iris dataset.
Imagine you're at a crowded party with a band playing, people chatting, and glasses clanging. Amid all this chaos, you're trying to listen to your friend's conversation. This is where ICA comes into play; much like your brain and ears, it helps pick out individual sound sources from a mishmash of noises. This is the essence of Independent Component Analysis.
ICA is a computational method for separating a multivariate signal into additive subcomponents, supposing the mutual statistical independence of non-Gaussian signals. As you're familiar with Principal Component Analysis (PCA), it's noteworthy that ICA is quite similar. However, while PCA identifies components that maximize variance and are statistically uncorrelated, ICA further requires the components to be statistically independent. This additional requirement makes ICA more potent than PCA in many applications because it can recover non-Gaussian independent components.
In the real world, ICA separates superimposed signals, such as the "cocktail party problem" we've just discussed. However, this technique is also widely used in digital images, document databases, economic indicators, stock prices, etc.
While the math behind the algorithm is not always necessary to implement a working code, in most cases it's important to know main concepts lying behind the machine learning algorithm we are trying to use.
To understand the math behind ICA, let's first comprehend its assumptions and objectives. ICA assumes that the observed data is a linear mixture of independent non-Gaussian sources. The goal of ICA is then to estimate the mixing matrix and the independent sources.
Let denote our observed data matrix, be the source matrix (independent components), and be the mixing matrix. In the cocktail party example - the sounds picked up by two microphones comprise our observed data, the individual voices are the sources, and the degree to which each voice contributes to the sound at each microphone is the mixing matrix. Mathematically, the model can thus be defined as .
The goal of ICA is to estimate an unmixing matrix that, when multiplied by the observed data , yields the independent sources: . This estimated should ideally contain maximally non-Gaussian independent components.
To achieve this, ICA employs the concept of statistical independence. Intuitively, two variables are independent if the occurrence of one event doesn't affect the probability of another event. Mathematically, two variables are considered independent if their joint probability density can be expressed as a product of their marginal probabilities.
Another critical concept employed by ICA is non-Gaussianity. ICA exploits the fact that real-world data distribution is usually non-Gaussian (not symmetrical, exhibiting skewness/kurtosis, etc.). ICA aims to find a rotation of the observed data such that the distribution of projections onto the basis vectors is non-Gaussian, as these are the 'interesting' parts of the data that hold pertinent information.
There exist several algorithms to solve the ICA problem, but in general, they follow a three-step approach:
-
Centring: This involves subtracting the mean from to make its columns have zero mean.
-
Whitening: This involves transforming to a new variable , such that , where is the eigenvector matrix and is the eigenvalue matrix of .
-
Rotation: This involves applying an orthogonal rotation to the whitened in order to find a rotation matrix (the inverse of ) whose columns give the independent components, i.e. . This maximizes the non-Gaussianity of rows in .
Varied ICA algorithms may use distinct strategies and measures to maximize non-Gaussianity.
Now you understand the mathematical basis of ICA. It leverages the concepts of statistical independence and non-Gaussianity to estimate the latent sources that give rise to observed multivariate data.
Transferring from theory to practice, let's look at implementing ICA on our familiar Iris dataset using the FastICA
algorithm provided by the scikit-learn
Python library.
First, we must import the necessary libraries for our task:
Python1import numpy as np 2from sklearn.decomposition import FastICA 3from sklearn import datasets 4import matplotlib.pyplot as plt
Next, we load the Iris dataset, standardize our data to have a zero mean and unit variance, and apply ICA. Standardization allows FastICA
to converge faster, as it brings all features to equal standing.
Python1# load iris dataset 2iris = datasets.load_iris() 3X = iris.data 4 5# Standardizing the features 6X = (X - X.mean(axis=0)) / X.std(axis=0) 7 8# Computing ICA 9ica = FastICA(n_components=3, whiten="unit-variance") 10X_transformed = ica.fit_transform(X)
The FastICA
function has several important parameters:
n_components
determines the number of independent components we want to retrieve.whiten
applies a pre-processing step to make the input data uncorrelated and standardize their variances to unit variance.algorithm
specifies the algorithm to use for the computation, which could be either 'parallel' or 'deflation'.fun
specifies the functional form of the G function used in the approximation to neg-entropy.max_iter
dictates the maximum number of iterations during the fit.
The ICA-transformed data, X_transformed
, holds our independent components. Essentially, these components are the original variables that, when mixed in certain proportions, yield our observed data.
Visualizing these components can help us understand their effects on the observed data. In the context of our Iris dataset, we can visualize these variables as follows:
Python1plt.figure(figsize=(8, 8)) 2for color, i, target_name in zip(["navy", "turquoise", "black"], [0, 1, 2], iris.target_names): 3 plt.scatter(X_transformed[iris.target == i, 0], X_transformed[iris.target == i, 1], color=color, s=100, lw=2, label=target_name) 4 5plt.legend(loc="best", shadow=False, scatterpoints=1) 6plt.title('ICA of IRIS dataset') 7plt.show()
Each point in the scatterplot represents an Iris flower, and the colors correspond to different Iris species. You can see that ICA has segregated these intertwined 'conversations' at our Iris 'cocktail party.'
Although our 'cocktail party problem' offered a glimpse into ICA's workings, this technique finds application in various other spheres. ICA is widely used in biomedical signal and image processing, telecommunications, and bioinformatics.
For instance, in digital image processing, ICA can be used to unpack mixed signals into source images. Consider an instance where you have a set of images that have been overlaid on top of each other to create a new composite image (somewhat like Instagram filters!). ICA can separate out the original images, much as it parsed through our jumbled 'conversations' at the cocktail party.
Today, we delved deep into the theory and practical aspects of Independent Components Analysis (ICA) - from understanding how ICA untangles multivariate signals to implementing ICA on the Iris dataset using scikit-learn
in Python and finally interpreting those elusive independent components.
Take a moment to reflect on our journey so far: from the humble beginnings of understanding unsupervised learning to now being able to implement and interpret complex algorithms such as ICA. This progress is not trivial!
It feels like quite an accomplishment, right? But we're not done just yet! Up next are some challenging practice exercises that will help you solidify your understanding of ICA and uncover its real power. By solving real-world problems, you'll master the concept and gain a hands-on understanding of how ICA is used in practice. So let's dive in and turn you into an expert in Independent Component Analysis!