-
Notifications
You must be signed in to change notification settings - Fork 0
Add in implementation of standard deviation on data #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
bielsnohr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.