LoslegenKostenlos loslegen

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.

Diese Übung ist Teil des Kurses

Practicing Statistics Interview Questions in Python

Kurs anzeigen

Anleitung zur Übung

  • 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.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# 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(____)
Code bearbeiten und ausführen