Viewing the E.Coli imbalance dataset in 3D with Python
Tags: Machine Learning, Python, Matplotlib, Artificial Intelligence, Data Science

Viewing the E.Coli imbalance dataset in 3D with Python Tracyrenee Follow Dec 16 · 4 min read

The E.Coli imbalance dataset is a very good dataset to experiment on because two of its classes only have two occurences in and one class has only five occurrences. Some individuals suggest removing those classes from the dataset to obtain a better accuracy, but I personally would like to find an algorithm that will pick up all of the classes.

One way to better understand how the labels in the dataset inter-relate with the independent variables associated with them is to view their visual representations. In a recent post I presented the target variables in a two dimensional plot and the link for that post can be found here:- A look at the E.Coli dataset using Principal Component Analysis (PCA) | by Tracyrenee | AI In Plain English | Dec, 2020 | Medium

In this post I intend to present the targets in a three dimensional, or 3D, graph to illustrate the way this variable fits into the memory locations in the computer’s memory.

The e.coli dataset describes the problem of classifying E.coli proteins using their amino acid sequences in their cell localization sites. That is, predicting how a protein will bind to a cell based on the chemical composition of the protein before it is folded.

The e.coli dataset is credited to Kenta Nakai and was developed into its current form by Paul Horton and Kenta Nakai in their 1996 paper titled “A Probabilistic Classification System For Predicting The Cellular Localization Sites Of Proteins.” In it, they achieved a classification accuracy of 81%.

The dataset is comprised of 335 examples of E.coli proteins and each example is described using seven input variables calculated from the proteins’ amino acid sequence.

In order to plot a 3D grappd of the targets, I created a program in Google Colab, which is an online Jupyter Notebook that can be accessed from any computer that has the internet connected to it.

I loaded some of the Python libraries, which are pre-installed in Google Colab, and then loaded and read the e.coli dataset.

The column titles are not present in this dataset, so I had to define the column titles, otherwise one of the rows in the dataset would show up as a title:-

I then checked for any null values and in this dataset there were none that needed to be imputed.

I then counted how many occurrences were present in each example of the target, which revealed a very large class imbalance:-

I defined the X variable, which is the dataset’s independent values, and scaled it using the StandardScaler() function in sklearn’s library.

I then calculated X’s mean value and standard deviation.

I defined the variable feat_cols, which is made up of the scaled columns in the X dataset.

I then created a dataset, normalised, which will be used in the program:-

I then entered the block of code to create the 3D representation of the e.coli dataset. In order to accomplish this I had to use sklearn’s LabelEncoder() to convert the target to numeric values, which is what the model wants to see:-

Once the code was entered, which is a modification of the code that is presented in the sklearn website, I ran the program and was presented with a 3D view of how the target variable examples appear in the computer memory:-

The code for this program can be found in its entirety in my personal GitHub account, the link being found here:- Misc-Predictions/E_Coli_PCA.ipynb at main · TracyRenee61/Misc-Predictions (github.com)