我们可以用新的math步骤来实现一个查询,计算图中每个机场的跑道数的标准差。我们将看到sqrt和power运算符的使用。笔者把查询分成了三条语句,而不是在一条语句中完成。在笔者看来,最后的三个查询语句已经相当的复杂了。注意在同一个查询中,前一个数学运算的结果做为了后一个数学运算的输入参数。
We could use the new math step to implement a query that calculates the standard deviation for the
number of runways each airport in the graph has. This allows us to see use of the sqrt and power
(^) operators. I broke the solution into three queries rather than try to force it all into one. Even
now the final query of the three is complicated enough I think! Notice how multiple math steps are
used in the same query with the results from one being used as input to the next.
首先,我们让算图中机场跑道的均值。不意外的话,这个数字接近1.5,因为绝大多数机场只有一个或两条跑道。
First of all let’s calculate the mean (or average) number of runways in the graph. Not surprisingly
this number is close to 1.5 as as the majority of the airports only have one or two runways.
我们也需要知道图中有多少个机场,这是我们计算标准差中的一个变量。
We also need to know how many airports there are in the graph so that we can calculate the
variance as part of the standard deviation calculation.
现在我们准备使用平方根和幂运算来计算标准差。提示:标准差是数据集中变量的平方根,每个机场的跑道数减去跑道的平均数,计算这个数字的平方再把各个值加起来,然后除以机场总数。我们写一个查询语句,把这些事情都做了。
Now we are ready to make use of the square root and power operators and calculate the standard
deviation. As a reminder, the standard deviation is found by taking the square root of the variance
in a data set. The variance itself is calculated by for each airport subtracting the mean from the
number of runways it has and squaring it and then taking the sum of those values and finally
dividing that sum by the number of airports. Let’s write a query that can do all of that for us.
我们也可以用另一个查询来检查图中跑道的分布,看一看我们的标准差结果是否可信。
We could use another query to check on the distribution of runways in the graph to see if we
believe our standard deviation result.
从分布中可以看出,在航线图中,绝大多数的机场有一条或者两条跑道,我们的结果相当的合理。明显极少的机场有6,7,8条跑道,它们是样本中的偏离值。这些值会落到我们计算的均值和标准差之外。
Looking at the distribution, where a large majority of the airports have either one or two runways,
our result looks pretty reasonable. Clearly the few airports with six, seven or eight runways are the
outliers in this sample and would fall well outside of the standard deviation from the mean that we
calculated.
我们再用同样基本的步骤再计算一次,这次是找到图中出边的标准差。
Just for fun, let’s use the same basic set of steps once again but this time to find the standard
deviation for the number of outgoing routes in the graph.
和前边一样,我们需要找到数据集的均值。这次我们要找的是图的出边的平均值。当然机场的总数是一样的。
As before we need to find the mean value for the data set. This time we need to find the average
number of outgoing routes in the graph. The airport count remains the same of course.
现在我们准备重新计算机场每个出边数据集的标准差。
Now we are ready to again calculate the standard deviation for the data set representing all
outgoing routes per airport.
这个数字与查找跑道的标准差相比,这次我们得到了一个更大的数字。 这反应了大部的机场和少部分的机场路径分布的差异。
This time we got a much bigger number back as the result compared to when we looked at
runways. This reflects the differing distribution of routes between major and more minor airports.
浙公网安备 33010602011771号