Overlaid histograms for continuous features

PHOTO EMBED

Tue Mar 15 2022 11:05:54 GMT+0000 (UTC)

Saved by @abhin__dev #undefined

# Plot overlaid histograms for continuous features
for i in ['Age', 'Fare']:
    died = list(titanic[titanic['Survived'] == 0][i].dropna())
    survived = list(titanic[titanic['Survived'] == 1][i].dropna())
    xmin = min(min(died), min(survived))
    xmax = max(max(died), max(survived))
    width = (xmax - xmin) / 40
    sns.distplot(died, color='r', kde=False, bins=np.arange(xmin, xmax, width))
    sns.distplot(survived, color='g', kde=False, bins=np.arange(xmin, xmax, width))
    plt.legend(['Did not survive', 'Survived'])
    plt.title('Overlaid histogram for {}'.format(i))
    plt.show()
content_copyCOPY

http://localhost:8888/notebooks/Desktop/Python/Ex_Files_Applied_ML/Ex_Files_Applied_ML/Exercise Files/03_Explore_Data/03_03/Begin/03_03.ipynb