本文共 1853 字,大约阅读时间需要 6 分钟。
python二分法查找程序
While dealing with a large data, how many samples do we need to look at before we can have justified confidence in our answer? This depends on the variance of the dataset.
在处理大量数据时,我们需要先查看多少样本,才能对我们的答案有充分的把握? 这取决于数据集的方差。
Variance tells us about the divergence and the inconsistency of the sample. The standard deviation of a collection of values is the square root of the variance. While it contains the same information as the variance. But Standard deviation is quite more referred. Why? Look at the below statement:
方差告诉我们样本的差异和不一致。 值集合的标准偏差是方差的平方根。 虽然它包含与方差相同的信息。 但是标准偏差要多得多。 为什么? 看下面的语句:
The mean income of the population is 846000 with a standard deviation of 4000.
The mean income of the population is 846000 with a variance of 16000000.人口的平均收入是846000, 标准差是4000。
人口的平均收入是846000,方差16000000。Now see which statement is more favorable and therefore we use standard deviation.
现在看看哪种说法更有利,因此我们使用标准差。
So in this python article, we are going to build a function for finding the SD.
因此,在这篇Python文章中,我们将构建一个用于查找SD的函数。
So the following function can be used while working on a program with big data which is very useful and help you a lot.
因此,在处理具有大数据的程序时可以使用以下功能,这非常有用,对您有很大帮助。
So here is the function code:
所以这是功能代码:
def stdv(X): mean = sum(X)/len(X) tot = 0.0 for x in X: tot = tot + (x - mean)**2 return (tot/len(X))**0.5# main code# a simple data-set sample = [1, 2, 3, 4, 5] print("Standard Deviation of the sample is: ", stdv(sample))sample = [1, 2, 3, -4, -5] print("Standard Deviation of the sample is: ", stdv(sample))sample = [10, -20, 30, -40, 50] print("Standard Deviation of the sample is: ", stdv(sample))
Output:
输出:
Standard Deviation of the sample is: 1.4142135623730951 Standard Deviation of the sample is: 3.2619012860600183 Standard Deviation of the sample is: 32.61901286060018
翻译自:
python二分法查找程序
转载地址:http://tcvzd.baihongyu.com/