1

I have an intuitive problem. Let's take

import pandas as pd
import numpy as np
df1 =5*pd.DataFrame(np.random.randn(N, 3), columns=['A', 'B','C'])
df2 =10+10*pd.DataFrame(np.random.randn(N, 3), columns=['A', 'B','C'])

Data=np.concatenate((df1, df2), axis=0)
Data[:,2]=1
Data[0:,2]=0
y=Data[:,2]
df=pd.DataFrame(np.c_[Data[:,0],Data[:,1]])
df1=df
df1['^2']=Data[:,1]**2
df1['^3']=Data[:,1]**3
df1['^4']=Data[:,1]**4

My task is to plot scatter plot the following :

enter image description here

But I highly doubt that it's feasible because of data dimension. My thesis is that you cannot plot data above on scatter plot or any type of plot (even 3d) Am I correct ?

John
  • 1,849
  • 2
  • 13
  • 23
  • [You can have a 4D plot,](https://stackoverflow.com/a/40452621/8881141) i.e., 3D + colour code. 5D in a scatter plot, if you include marker size. – Mr. T Nov 05 '20 at 21:25

1 Answers1

1

You can plot up to 4D (this is equivalent to creating a "heatmap" in 3D). See the link here for more information.

One way to plot "high dimensional" data is to use dimensionality reduction techniques such as Principal Component Analysis (PCA) to reduce the dimensionality of your data while retaining as much information as possible about how the data is distributed.

If this is of interest, one thing you could do is project your 5D data into 4D data using PCA (this can be done with sklearn) and then plotting in 4D using the code linked above:

import numpy as np
from sklearn.decomposition import PCA
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt

# Project data down to 4D
X = df.values  # This could be done after you raise your data to different powers
pca = PCA(n_components=4)  # n_components is the number of dimensions to project to
X_four_d = pca.fit_transform(X)

# Now plot in 4D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

x = X_four_d[:,0]
y = X_four_d[:,1]
z = X_four_d[:,2]
c = X_four_d[:,3]

img = ax.scatter(x, y, z, c=c, cmap=plt.hot())
fig.colorbar(img)
plt.show()
Ryan Sander
  • 419
  • 3
  • 6