Uniform Manifold Approximation and Projection
Last updated
Last updated
The required packages for this section are pandas, seaborn, scikit-learn and umap-learn. These can be installed with the following command in the command window (Windows) / terminal (Mac).
For this section the following dataset will be used:
Load the dataset into a Pandas DataFrame named df as described in the basic plotting section:
Usually before running UMAP, PCA is performed on the high-dimensional data to reduce the dimensions (e.g. 30, 50) and then UMAP is applied on the derived Principal Components.
The first step is to normalise the data such that the features (lipids) have zero mean and unit variance, this can easily be done with the StandardScaler from sklearn. By indexing the dataframe with df.iloc[:,1:] we'll select all the data in the dataframe, except for the first column, which contains the labels:
Next, we use the PCA sklearn from sklearn, we'll select the 50 first principal components and we'll apply the PCA algorithm to the normalised data:
Then using UMAP from umap-learn we'll apply the UMAP algrorithm on the 50 Principal Components.
The UMAP function from umap-learn returns the results as a numpy ndarray, let's put these results in a Pandas DataFrame:
We can now visualise the projection of the samples to the new feature space with a scatterplot: