I have a dataset of two classes with several features, how can I visualise such data using Matlab to decide if it is linear separable or not?
You basically need a t-SNE plot, the t-SNE will convert the high dimensional feature vector (several features in your case) to a 2d point and then you can use matplotlib to plot, while plotting you need to send in the class of the corresponding feature to get different colour for different classes of data points. once you do this, you will be able to judge if they are linearly separable.
the code goes as follows
import matplotlib.pyplot as plt from sklearn.manifold import TSNE tsne = TSNE(n_components=2, random_state=0) transformed_data = tsne.fit_transform(features) k = np.array(transformed_data) plt.scatter(k[:, 0], k[:, 1], c=class_labels, zorder=10, s=0.4)
and the above code should produce an image as shown below
Since you're looking for MATLAB code you can get the t-SNE with the function tsne(x) click on it for documentation. Also matplotlib scatter plot is pretty easy to do on Matlab, the documentation is extensive!
vote me if i was able to help ;)
When class labels are known, you can use Linear Discriminant Analysis (LDA) for visualization to see whether classes are linearly separable. LDA is similar to PCA but supervised. It tries to project the data in a way that maximizes the distance between classes (here is a how-to post for Matlab, R, Python. Here is a mult-class LDA for Matlab).
Also, we can get a sense of linearity without any visualization. To this end, we can train/test a linear SVM on [sample of] data and if the test accuracy (assuming class numbers are balanced) is 90%, 95%, 99%, it is an increasingly good indication that classes are almost linearly separable.
Please note that we cannot use non-linear dimensionality reduction methods such as IsoMap or t-SNE, since they are able to show a linearly separated visualization even for classes that are not linearly separable in the original space, hence the name non-linear. Here is the famous Swiss roll example: