官术网_书友最值得收藏!

Mean

This is one of the most intuitive and most frequently used concepts in statistics. Given a set of numbers, the mean of that set is the sum of all the elements divided by the number of elements in the set.

The formula that represents the mean is as follows:

Although this is a very simple concept, we will write a Python code sample in which we will create a sample set, represent it as a line plot, and mark the mean of the whole set as a line, which should be at the weighted center of the samples. It will serve as an introduction to Python syntax, and also as a way of experimenting with Jupyter notebooks:

    import matplotlib.pyplot as plt #Import the plot library 

def mean(sampleset): #Definition header for the mean function
total=0
for element in sampleset:
total=total+element
return total/len(sampleset)

myset=[2.,10.,3.,6.,4.,6.,10.] #We create the data set
mymean=mean(myset) #Call the mean funcion
plt.plot(myset) #Plot the dataset
plt.plot([mymean] * 7) #Plot a line of 7 points located on the mean

This program will output a time series of the dataset elements, and will then draw a line at the mean height.

As the following graph shows, the mean is a succinct (one value) way of describing the tendency of a sample set:

In this first example, we worked with a very homogeneous sample set, so the mean is very informative regarding its values. But let's try the same sample with a very dispersed sample set (you are encouraged to play with the values too):

主站蜘蛛池模板: 石狮市| 娱乐| 广南县| 九寨沟县| 龙州县| 承德市| 阿拉善右旗| 蒲城县| 河东区| 阜平县| 丹寨县| 鹿泉市| 南投市| 黑水县| 台湾省| 莱阳市| 宁国市| 抚远县| 独山县| 清流县| 比如县| 阜城县| 横山县| 德州市| 长阳| 桓仁| 清水县| 塔河县| 长治县| 长宁区| 义马市| 长顺县| 虎林市| 商丘市| 大悟县| 邓州市| 东城区| 宜章县| 宜春市| 延寿县| 白水县|