# Positive & Negative Correlation: dataset2 = dataset[['SeniorCitizen', 'Partner', 'Dependents', 'tenure', 'PhoneService', 'PaperlessBilling', 'MonthlyCharges', 'TotalCharges']] correlations = dataset2.corrwith(dataset.Churn) correlations = correlations[correlations!=1] positive_correlations = correlations[correlations >0].sort_values(ascending = False) negative_correlations =correlations[correlations<0].sort_values(ascending = False) print('Most Positive Correlations: \n', positive_correlations) print('\nMost Negative Correlations: \n', negative_correlations) # Correlation Plot among Independent Variables: #Set and compute the Correlation Matrix: sn.set(style="white") corr = dataset2.corr() #Generate a mask for the upper triangle: mask = np.zeros_like(corr, dtype=np.bool) mask[np.triu_indices_from(mask)] = True #Set up the matplotlib figure and a diverging colormap: f, ax = plt.subplots(figsize=(18, 15)) cmap = sn.diverging_palette(220, 10, as_cmap=True) #Draw the heatmap with the mask and correct aspect ratio: sn.heatmap(corr, mask=mask, cmap=cmap, vmax=.3, center=0, square=True, linewidths=.5, cbar_kws={"shrink": .5})
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter