0

I'm trying to plot the original data before handling the imbalance in a way to show the class distribution and class imbalance (class is Failure =0/1) 2. I might need to do some transformation on the data in both cases to be able to visualize it.

Here's what the column looks like:

| failure |
|---------|
| 1       |
| 0       |
| 0       |
| 1       |
| 0       |

Here's what I have tried so far:

import numpy as np
from scipy.stats.kde import gaussian_kde

def distribution_scatter(x, symmetric=True, cmap=None, size=None):
    pdf = gaussian_kde(x)    
    w = np.random.rand(len(x))    

    if symmetric:        
        w = w*2-1    
        pseudo_y = pdf(x) * w    

    if cmap:        
        plt.scatter(x, pseudo_y, c=x, cmap=cmap, s=size)    

    else:        
        plt.scatter(x, pseudo_y, s=size)    

    return pseudo_y

Results:

enter image description here

The problem with the results:

I want the plot the distribution of 0's and 1's. For which I believe I need to transform it in someway.

Desired output:

enter image description here

1 Answer 1

1

If you want a KDE plot, you can check kdeplot from seaborn:

x = np.random.binomial(1, 0.2, 100)
sns.kdeplot(x)

Output:

picture


Update: Or a swarmplot if you want a scatter:

x = np.random.binomial(1, 0.2, 25)
sns.swarmplot(x=x)

Output:

picture2


Update 2: In fact, your function seems to also produce a reasonable visualization:

distribution_scatter(np.random.binomial(1, 0.2, 100))

Output:

picture3

Sign up to request clarification or add additional context in comments.

7 Comments

Thanks for mentioning! But I want a scatter plot which will show the distribution of 0's and 1's.
@QasimKhan Maybe swarmplot (see Update)?
@QasimKhan And actually the function that you currently have seems to be OK as well (see Update 2). Can you explain in a bit more detail what specifically you're trying to achieve?
Hey @perl, please check the question again, I added a desired output section.
@QasimKhan What are the X and Y values in your chart? Do you want them generated somehow?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.