Data Visualization in Python- relationship between 3 variables

389 Views Asked by At

I am currently working on a project where I am using machine learning to create a model that predicts which passengers survived the Titanic shipwreck.

I want to find the relationship between the gender of the person and their survival rate. I have one-hot encoded the gender column for the same.

So now I have 3 columns- Female( values 0 or 1), Male( values 0 or 1) and Survived( values 0 or 1). Can you suggest me a suitable graph to visualize and compare their relationship.

I tried scatter plot, but it wasn't helpful.

1

There are 1 best solutions below

0
On

Firstly, convert the data as lists,

  1. survived
  2. male
  3. female
w = 0.4
survived = [.....]
male = [.....]
female = [......]

bar1 = np.arange(len(x))
bar2 = [i+w for i in bar1]

plt.bar(bar1,male,w,label="Male")
plt.bar(bar2,female,w,label="Female")

plt.xlabel("Name a label, Survived")
plt.ylabel("Name a label, Gender")
plt.title("Gender Vs Survived")
plt.legend()
plt.show()```