Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import pandas as pd
- import matplotlib.pyplot as plt
- import seaborn as sns
- from scipy import stats
- df_no_nulls_diesel = df_diesel[["Years Automobile", "Price BGN", "Kilometers", "Horsepower"]].dropna().copy()
- df_no_nulls_diesel.corr()
- g = sns.lmplot(x = "Years Automobile", y = "Price BGN", data = df_no_nulls_diesel, height=12, aspect=1)
- g.fig.suptitle('Diesel engines: Years Automobile vs Price BGN')
- plt.show()
- g = sns.heatmap(np.round(df_no_nulls_diesel.corr(), 2), annot = True).set(title='Diesel engines: Correlation Analysis')
- g
- plt.show()
- df_no_nulls_diesel.mpg.corr(df_no_nulls_diesel.years)
- ########################################################
- # jointplot returns a jointgrid, which we need to assign to a variable in order to add an annotation
- # This line is almost like the original, but it seems that fill is needed explicitly now.
- # And most importantly, ".annotate" is not just deprecated. It's gone.
- jg = sns.jointplot(x='BMXLEG', y='BMXARML', data=da, kind='kde', fill=True)
- # To get the correlation, we need to consider only the records with NA values for either measurement.
- da_no_nulls = da[['BMXLEG', 'BMXARML']].dropna()
- pearsonr, p = stats.pearsonr(da_no_nulls.BMXLEG, da_no_nulls.BMXARML)
- pearson_str = f'pearsonr = {pearsonr:.2f}; p = {p}'
- # Placing the annotation somewhere readable requires that we find the max of the axes
- jg.ax_joint.text(
- jg.ax_joint._axes.xaxis.get_data_interval()[1],
- jg.ax_joint._axes.yaxis.get_data_interval()[1],
- pearson_str,
- horizontalalignment='right')
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement