Source: Better Data Visualization Using Beeswarm Chart
import pandas as pd
import seaborn as sns
import kaggle
Dataset comes from Kaggle: Titanic - Suited for binary logistic regression
kaggle.api.authenticate()
kaggle.api.dataset_download_files('heptapod/titanic', path='.', unzip=True)
df = pd.read_csv('train_and_test2.csv', sep=',')
df.rename(columns={'2urvived': 'survived'}, inplace=True)
df['Sex'] = df['Sex'].replace({0: 'Male', 1: 'Female'}).astype('category')
df['Pclass'] = df['Pclass'].replace({1: '1st', 2: '2nd', 3: '3th'}).astype('category')
# df['Age'] = pd.cut(df['Age'].round(), 5).astype(str)
ax = sns.catplot(x="Sex", y="Age", hue='survived', col='Pclass', kind="swarm", data=df)
/home/pablo/miniconda3/envs/datamining/lib/python3.8/site-packages/seaborn/categorical.py:1296: UserWarning: 6.1% of the points cannot be placed; you may want to decrease the size of the markers or use stripplot. warnings.warn(msg, UserWarning) /home/pablo/miniconda3/envs/datamining/lib/python3.8/site-packages/seaborn/categorical.py:1296: UserWarning: 20.8% of the points cannot be placed; you may want to decrease the size of the markers or use stripplot. warnings.warn(msg, UserWarning) /home/pablo/miniconda3/envs/datamining/lib/python3.8/site-packages/seaborn/categorical.py:1296: UserWarning: 33.9% of the points cannot be placed; you may want to decrease the size of the markers or use stripplot. warnings.warn(msg, UserWarning)