by
104 5

2D Data Visualization

correlation, heatmap, plt, sns, pd, eda
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/4382974/2D-Data-Visualization?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
# 1: # Correlation matrix (Pearson correlation) def plotCorr(df): plt.figure(figsize=(14,12)) plt.title('Pearson Correlation of Features', y=1.05, size=15) sns.heatmap(df.astype(float).corr(),linewidths=0.1,vmax=1.0, square=True, linecolor='white', annot=True) plt.show() ### # 2: # Focused correlation matrix # Apply some condition on the correlation of the cols over the target col # before plotting it corr = df.corr() mask = (corr["targetCol"] > 0.4) + (corr["targetCol"] < -0.4) selectedCols = corr.loc[mask].index.values plotCorr(df[selectedCols]) ### # 3: # Joint plot (image in comments) sns.jointplot(x='col1', y='col2', data=df, kind='reg', space=0, size=5, ratio=4) ### # Grouped bar plot # Perform discrete histogram on column x and group by coulmn on hue sns.countplot(x="histCol", hue="groupCol", data=df) ### # Faceted boxplot # As many boxplots of "y" as values has "x" sns.boxplot(x="discreteCol", y="continuousCol", data=df) ### # Distplot with 2nd dim as hue (image in comments) # We use FacetGrid to encode the hue beacuse distplot doesn't have it # (last time I checked anyway) g = sns.FacetGrid(wines, hue='hueCol') g.map(sns.distplot, 'histCol', kde=False, bins=15)
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus