I’m unable to submit the answer on Measures of Variability, task 9, although the code & the histogram seem to be correct.
Welcome to our Dataquest Community.
There must be something. You are missing in the code, maybe applying ‘Bessel corrections’ for calculating the standard deviation of a sample, etc.
Below is my code, which submitted successfully without any error.
from math import sqrt
import matplotlib.pyplot as plt
def standard_deviation(array):
reference_point = sum(array) / len(array)
distances = []
for value in array:
squared_distance = (value - reference_point)**2
distances.append(squared_distance)
variance = sum(distances) / len(distances)
return sqrt(variance)
def bessel_corr(array):
mean = sum(array)/len(array)
var = [abs(value-mean) ** 2 for value in array]
variance = sum(var)/(len(var)-1)
return sqrt(variance)
sample_sd = []
for i in range(5000):
sample = houses['SalePrice'].sample(10, random_state=i)
sample_sd.append(bessel_corr(sample))
plt.hist(sample_sd)
plt.axvline(standard_deviation(houses['SalePrice']))
Please, take a look at your code once again.
Thank You