91.1k views
4 votes
Below is the EfficientAveragerator class we saw during lecture, with one new property for you to implement: variance. In EfficientAveragerator, we compute average and standard deviation in an incremental fashion, so that we don't have to recompute everything when a new value arrives in our data set. We want to compute variance using the same incremental approach. Fortunately, EfficientAveragerator already has everything we need to write such an incremental definition of variance. Fill in the definition of the variance property in the cell below. It should take no more than 1-2 lines of code, and does not require NumPy or any other fancy library. (Hint: it will look a lot like the definition of std.)

1 Answer

5 votes

Answer:

Following are the code to this question:

def variance(self):

average = self.avg

return (self.sum_x_sq / self.n - average* average)

Step-by-step explanation:

In the given question, some information missing, that is a program so, the correct code to this question can be described as follows:

  • In the above-given code, a method "variance" declared, that accepts an argument in its parameters, inside the method an another "average" variable is declared, that use to hold avg value.
  • The method will divide "sum_x_sq" with "n- average *average" calculate and return its value.
Below is the EfficientAveragerator class we saw during lecture, with one new property-example-1
User AeroBuffalo
by
6.5k points