## Scratch中如何操作

### 标准差的定义

(25 + 60 + 40 + 45 + 55) / 5 = 45

Flower #1: ((25) - (45))^2 = (-20)^2 = 400
Flower #2: ((40) - (45))^2 = (-5)^2 = 25
Flower #3: ((45) - (45))^2 = (0)^2 = 0
Flower #4: ((55) - (45))^2 = (10)^2 = 100
Flower #5: ((60) - (45))^2 = (15)^2 = 225

(400 + 25 + 0 + 100 + 225) / 5 = 150

1、总体标准差，针对总体数据的偏差。例如，如果世界上只有5朵花，那么12.247就是花高度的总体标准差。

2、样本标准差。样本标准差是只有一部分数据的标准差。例如：我们拿五朵花。世界上显然有五朵以上的花，所以五朵花只是全部数据的一部分。针对从总体抽样，利用样本来计算总体偏差。就必须将算出的标准偏差的值适度放大。

(400 + 25 + 0 + 100 + 225) / (5 - 1) = 187.5

### 变量

• 数据集列表

• Average
• Sum
• Variance
• Standard Deviation
• Number
• Sum2
• Number2

### 代码

when gf clicked
set [Sum v] to (0)//初始化变量。
set [Number v] to (1)
repeat (length of [Data v])
change [Sum v] by (item (Number) of [Data v])
change [Number v] by (1)//变量(Number) 是代码取数据集列表的指针。
end
set [Average v] to ((Sum) / (length of [Data v]))

when gf clicked
set [Sum v] to (0)//Resetting the variables.
set [Number v] to (1)
repeat (length of [Data v])
change [Sum v] by (item (Number) of [Data v])
change [Number v] by (1)
end
set [Average v] to ((Sum) / (length of [Data v]))
set [Sum2 v] to (0)
set [Number2 v] to (1)
repeat (length of [Data v])
change [Sum2 v] by (((item (Number2) of [Data v]) - (Average)) * ((item (Number2) of [Data v]) - (Average)))
change [Number2 v] by (1)
end
set [Variance v] to ((Sum2) / ((length of [Data v]) - (1)))

when gf clicked
set [Sum v] to (0)//Resetting the variables.
set [Number v] to (1)
repeat (length of [Data v])
change [Sum v] by (item (Number) of [Data v])
change [Number v] by (1)
end
set [Average v] to ((Sum) / (length of [Data v]))
set [Sum2 v] to (0)
set [Number2 v] to (1)
repeat (length of [Data v])
change [Sum2 v] by (((item (Number2) of [Data v]) - (Average)) * ((item (Number2) of [Data v]) - (Average)))
change [Number2 v] by (1)
end
set [Variance v] to ((Sum2) / ((length of [Data v]) - (1)))
set [Standard Deviation v] to ([sqrt v] of (Variance))

when gf clicked
set [Sum v] to (0)//Resetting the variables.
set [Number v] to (1)
repeat (length of [Data v])
change [Sum v] by (item (Number) of [Data v])
change [Number v] by (1)
end
set [Average v] to ((Sum) / (length of [Data v]))
set [Sum2 v] to (0)
set [Number2 v] to (1)
repeat (length of [Data v])
change [Sum2 v] by (((item (Number2) of [Data v]) - (Average)) * ((item (Number2) of [Data v]) - (Average)))
change [Number2 v] by (1)
end
set [Variance v] to ((Sum2) / ((length of [Data v]) - (1)))
set [Standard Deviation v] to ([sqrt v] of (Variance))

### 完整代码

when gf clicked
set [Sum v] to (0)//Resetting the variables.
set [Number v] to (1)
repeat (length of [Data v])
change [Sum v] by (item (Number) of [Data v])
change [Number v] by (1)
end
set [Average v] to ((Sum) / (length of [Data v]))
set [Sum2 v] to (0)
set [Number2 v] to (1)
repeat (length of [Data v])
change [Sum2 v] by (((item (Number2) of [Data v]) - (Average)) * ((item (Number2) of [Data v]) - (Average)))
change [Number2 v] by (1)
end
set [Variance v] to ((Sum2) / ((length of [Data v]) - (1)))
set [Standard Deviation v] to ([sqrt v] of (Variance))

when gf clicked
set [Sum v] to (0)//Resetting the variables.
set [Number v] to (1)
repeat (length of [Data v])
change [Sum v] by (item (Number) of [Data v])
change [Number v] by (1)
end
set [Average v] to ((Sum) / (length of [Data v]))
set [Sum v] to (0)//Resetting the variables.
set [Number v] to (1)
repeat (length of [Data v])
change [Sum v] by (((item (Number) of [Data v]) - (Average)) * ((item (Number) of [Data v]) - (Average)))
change [Number v] by (1)
end
set [Variance v] to ((Sum) / (length of [Data v]))
set [Standard Deviation v] to ([sqrt v] of (Variance))

## 相关链接

Cookies help us deliver our services. By using our services, you agree to our use of cookies.