ComeçarComece de graça

Standard deviation by hand

In the video, we talked about measures of variability, and discussed standard deviation as the measure that is used most commonly. It's pretty important that you have a grasp on this concept, as interviewers will likely hit on it early on in the process through a coding assignment or something more conceptual.

Here, you'll simulate this experience by computing standard deviation by hand, meaning that you won't use any existing functions like std() to get your results.

Este exercício faz parte do curso

Practicing Statistics Interview Questions in Python

Ver curso

Instruções do exercício

  • Without using the mean() function, compute the mean of our nums list defined for you.
  • Use the computed variance value along with the math.sqrt() function to get the standard deviation; print your result.
  • Check your work by printing the actual standard deviation with the np.std() function mentioned earlier.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# Create a sample list
import math
nums = [1, 2, 3, 4, 5]

# Compute the mean of the list
mean = ____

# Compute the variance and print the std of the list
variance = sum(pow(x - mean, 2) for x in nums) / len(nums)
std = ____
print(____)

# Compute and print the actual result from numpy
real_std = np.array(____).std()
print(____)
Editar e executar o código