Discrete Variable Combinations
Python
Compare the mean price for the combinations of levels in the neighbourhood_group and room_type columns using Pandas Pivot and Seaborn Heatmap.
1| def feature_interactions(df,feature1, feature2,continuous_col): 2| group = df.groupby([feature1,feature2],as_index=False)[continuous_col].mean().reset_index(drop=True) 3| pivot = group.pivot(index=feature1, columns=feature2, values=continuous_col) 4| pivot.fillna(0, inplace=True) 5| plt.figure(figsize=(10,6)) 6| sns.heatmap(pivot,cmap='Reds') 7| plt.show() 8| 9| feature_interactions(data,'room_type','neighbourhood_group','price')
133
121
117
109