I have a dataset with 6 independent variables, I have trained this dataset on a Support Vector Machine. Is there is a way in python or R to visualize the feature space with the hyperplane? Or for example, can I plot many 2D plots such that every plot has two features vs each other separated by the decision boundary in the graph?
2 Answers
For something like visualizing four dimensions, you could do something along the lines of constructing a 3D plot and then adding a color gradient to represent the fourth dimension. For five dimensions you could add scatter plot point size, for six perhaps even scatter point shape as well. After around four dimensions however, the 'standard' visualization of a scatterplot starts to look fairly clunky.
One way to visualize six dimensional data is to use a technique you mentioned above. Namely, create a series of 2D plots. One way to accomplish this in by using the scatter_matrix
in pandas. You can read about that on its documentation here.
A minimal example is provided below:
import pandas as pd
import numpy as np
# import the scatter_matrix function from pandas
from pandas.plotting import scatter_matrix
# create a df that contains a series of random numbers with 6 features
df = pd.DataFrame(np.random.randn(60, 6), columns=['x_1', 'x_2', 'x_3', 'x_4',
'x_5','x_6'])
#create a scatter matrix and plot a histogram across the diagonal
scatter_matrix(df, alpha=.4, figsize=(8, 8), diagonal='hist');
The result:
It is possible to visualize 4D features or more by playing with the following parameters in a 3D space:
- Color (ex: the more the dot is bright, the more it is high)
- Size (ex: the more the dot is big, the more it is high)
- Shapes
- Animations
But it works mainly if you have features with less importance than others.
If you have features of similar importance, you can represent different 3D views interactively next to each other like in this example or maybe virtual reality could give some interesting views of hyperspace.