1
$\begingroup$

Let's say I have 3 classes and 1 score for each data point

  • score z
  • class 1
  • class 2
  • class 3

E.g. the input looks like:

0.529 5 7 4
0.310 3 4 2
0.774 10 7 6
0.774 10 8 5
0.172 3 0 2

In code:

>>> import pandas as pd
>>> df = pd.DataFrame([[0.529, 5.0, 7.0, 4.0], [0.31, 3.0, 4.0, 2.0], [0.774, 10.0, 7.0, 6.0], [0.774, 10.0, 8.0, 5.0], [0.172, 3.0, 0.0, 2.0]])
>>> df
       0     1    2    3
0  0.529   5.0  7.0  4.0
1  0.310   3.0  4.0  2.0
2  0.774  10.0  7.0  6.0
3  0.774  10.0  8.0  5.0
4  0.172   3.0  0.0  2.0

Each row represents a data point and column 0 is the score and column 1,2,3 are some sort of coefficients for the classes.

The score is some sort of computed entity independent of the coefficients and the goal is to visualize the interaction between the coefficients and the score.

How to visualize the interaction between the 3 classes (column 1,2,3) and the score (column 0)?

$\endgroup$
2
$\begingroup$

You could use a 3d-scatter plot, where each class would correspond to one axis and the color-intensity of the point would indicate the score value(e.g. for a grayscale colormap, the whiter the closer to 1 the value of the score).

Using the above format:

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import pandas as pd


df = pd.DataFrame([[0.529, 5.0, 7.0, 4.0], [0, 3.0, 4.0, 2.0], [0.774, 10.0, 7.0, 6.0], [0.774, 10.0, 8.0, 5.0], [1, 3.0, 0.0, 2.0]])
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(df[1].values, df[2].values, df[3].values, c=df[0].values, cmap='gray', s=50, vmin=0.,vmax=1)

ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')

plt.show()

Example 3d You can change the scatter plot attributes for marker-size, colormap etc. according to the documentation to match your tastes.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.