Computing the Mean

Calculating the Mean from Scratch using Python
In this post, I will explain a Python program that I wrote which calculates the mean without using the analytics libraries (NumPy, SciPy, etc.). The mean is a standard statistical expression used to calculate the average of a set of real numbers. There are two functions in Python used to calculate the mean from scratch. The first function is sum(), which calculates the sum of elements declared in a program. The program I wrote applies the function to add up a list of numbers and divides them by the len()function, which counts the number of elements declared in a list. When you divide sum()by len(), you get the equation for the mean, which you can declare in a program. The following screenshots show the code and a basic histogram of the values displayed in the program:

The screenshot shows the program where I declared a list of dummy values. Once I did this, I then built the equation for the mean, stored in the values_mean variable. Then, I printed the result to standard output. Finally, I generated a basic histogram using the matplotlib library and used hist() to output the histogram as we see here:

The graph is far from perfect, but it does give a simple visualization of values. In my next post, I will improve the program using the Ames data set, a standard set used in regression modeling. I will also improve upon the graphics to create a more descriptive distribution of values.

原文链接:Computing the Mean

© 版权声明
THE END
喜欢就支持一下吧
点赞14 分享
Nothing can't be figured out. The past just can't be reached again.
没有什么过不去,只是再也回不去
评论 抢沙发

请登录后发表评论

    暂无评论内容