Add in implementation of standard deviation on data#3
Add in implementation of standard deviation on data#3thomaskileyukaea wants to merge 3 commits intomainfrom
Conversation
bielsnohr
left a comment
There was a problem hiding this comment.
Overall, looking good. A few suggested changes to consider. Also, there are some tests that I would expect to see for this new feature:
- We should use some 2D data rather than just the 1D used here
- We should have some data with invalid values and check that the functions deal with these edge cases
- A test where the rows of a 2D matrix have been swapped around to check that the standard deviation is invariant (row swaps shouldn't affect its value).
|
|
||
| def s_dev(data): | ||
| """Computes and returns standard deviation for data.""" | ||
| number = np.mean(data, axis=0) |
There was a problem hiding this comment.
I don't immediately know what the purpose of the number variable is from its name. Based on its assignment, it is the mean along one axis, so perhaps it should be called data_mean or event just mean?
There was a problem hiding this comment.
Resolved by using np.std
| number = np.mean(data, axis=0) | ||
| devs = [] | ||
| for entry in data: | ||
| devs.append((entry - number) * (entry - number)) | ||
|
|
||
| s_dev2 = sum(devs) / len(data) |
There was a problem hiding this comment.
This is an implementation of standard deviation from the ground up. We could probably replace with a call to np.std.
| devs.append((entry - number) * (entry - number)) | ||
|
|
||
| s_dev2 = sum(devs) / len(data) | ||
| return {'standard deviation': s_dev2} |
There was a problem hiding this comment.
Returning a dict doesn't match what is returned for all of the other functions in this module. We should probably switch to just returning the calculated value.
There was a problem hiding this comment.
And it mixes in responsibilites that should be with the view
As per SR.1.1.1 add ability to calculate standard deviation for each day and then present this in the graphs show to the user.