LIMITED TIME OFFER: 50% OFF OF PREMIUM WITH OUR ANNUAL PLAN (THAT'S $294 IN SAVINGS).
GET OFFER

Histogram of standardized `Overall House Quality`

Screen link: Learn data science with Python and R projects

After completing the exercise of standardizing Overall House Quality for the purposes of comparing values, I couldn’t resist building a visual for the z-scores. Thought I’d share here so that other visual creatures like myself could enjoy!

Code to produce plot:

import numpy as np

mean_index1 = houses['index_1'].mean()
mean_index2 = houses['index_2'].mean()
stdev_index1 = houses['index_1'].std(ddof=0)
stdev_index2 = houses['index_2'].std(ddof=0)

houses['z_1'] = houses['index_1'].apply(lambda x: ((x-mean_index1)/stdev_index1))
houses['z_2'] = houses['index_2'].apply(lambda x: ((x-mean_index2)/stdev_index2))

houses['house_quality'] = houses.pop('z_1').fillna(houses.pop('z_2'))
step = (houses['house_quality'].max() - houses['house_quality'].min())/10
houses['house_quality'].plot.hist(figsize=(12,8))
plt.xticks(np.arange(round(houses['house_quality'].min(),2), 
                 houses['house_quality'].max(),
                 step))
plt.axvline(0, lw=2, color='red', label='mean')
plt.axvline(houses['house_quality'].median(), lw=2, color='orange', label='median')
plt.axvline((-1.157 + -0.235)/2, lw=2, color='green', label='mode')
plt.xlabel('z-score')
plt.title('z-scores for House Quality', fontsize=20)
plt.legend()
plt.show()