Created
September 17, 2020 10:05
-
-
Save AvielMak/0294b31083914ab6a42ef2a973078354 to your computer and use it in GitHub Desktop.
Plot Distribution of two classes given feature
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Def plot distribution | |
| def plot_distribution(data_select,data,h,limit=()): | |
| """ | |
| Plot_Distribution to see how 2 classes are seperated on different features | |
| data_select = which feature we want to see | |
| data = the DataFrame | |
| h = column of the two classes | |
| limit = non mendatory, tuple to limit the x_axis | |
| """ | |
| figsize =( 15, 8) | |
| sns.set_style("whitegrid") | |
| keys = data[h].unique() | |
| a = keys[0] | |
| b = keys[1] | |
| s = sns.FacetGrid(data, hue = h,aspect = 2.5, palette ={a : 'lime', b :'black'}) | |
| s.map(sns.kdeplot, data_select, shade = True, alpha = 0.6) | |
| if not limit: | |
| s.set(xlim=(data[data_select].min(), data[data_select].max())) | |
| else: | |
| s.set(xlim=(limit[0], limit[1])) | |
| s.add_legend() | |
| s.set_axis_labels(data_select, 'proportion') | |
| s.fig.suptitle(data_select) | |
| plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment