Hi!
I’ve started working on the final projects of Data Analysis with Python. Currently, I’ve finished the Mean-Variance-Standard Deviation Calculator properly. Although, I would like to ask for some feedback on my project.
I’ve applied an efficient way to calculate the statistics? I mean, while I was working on it I had the temptation to write a function for each of the statistics.
Raising a ValueError in a way like I’ve done is ok? I’ve been searching on Google how to raise an error and I’ve seen a ton of approaches. Some create an inherent class from Error. I’d only had 1 error during the tests and was about raising ValueError.
At last, but not least, Is my code written in a good way? It’s clear and easy to follow it?
All comments would be appreciated. I will try to post my other projects asking for feedback if receive interesting answers.
Thanks for your time.
PD: Update. I’ve been working on @sanity recommendations. I’ve added a calculator function to avoid repeating the same piece of code 6 times
It’s very likely numpy’s calculations will be much faster than using python’s build-in functions, modules from standard library or self written functions. However for a matrix with 9 numbers efficiency concerns hardly could be an issue.
Yes, that’s okay. No need to make another error class, when just standard ValueError is supposed to be used.
For a question like that answer usually can be that there are things that can be improved, and there’s nothing wrong in that.
Function is clean and easy to follow. Some variable names should be improved to be more descriptive, there’s also inconsistent formatting - different number of blank lines - between code blocks in function. I like that parameter name list was changed to not shadow the build-in type, although I suspect reason for that partially could be wanting to use list() for type conversion from numpy’s arrays.
Part of what makes function clean is keeping everything structured the same way:
Notice however this part of code repeats few times. Changed are only two variables - calculating function and which calculation it is. Such repeated pattern is a good place to try to change the relevant code into a loop, function, or both. It will significantly shorten whole function and put these calculations in a single place, allowing for easier and quicker change, if needed in future.
How I change the operator and the dict key? I’m thinking about using fstring but I’m not sure. It’s about calling different built functions of numpy? Sure there’s an easy way but I’m stuck with it.