Python Statistics.variance() Method
ตัวอย่าง
คำนวณความแปรปรวนจากตัวอย่างข้อมูล:
# Import statistics Library
import statistics
# Calculate
the variance from a sample of data
print(statistics.variance([1, 3, 5, 7, 9, 11]))
print(statistics.variance([2,
2.5, 1.25, 3.1, 1.75, 2.8]))
print(statistics.variance([-11, 5.5, -3.4,
7.1]))
print(statistics.variance([1, 30, 50, 100]))
ความหมายและการใช้งาน
วิธี การstatistics.variance()
คำนวณความแปรปรวนจากตัวอย่างข้อมูล (จากประชากร)
ความแปรปรวนขนาดใหญ่บ่งชี้ว่าข้อมูลถูกกระจาย - ความแปรปรวนเล็กน้อยบ่งชี้ว่าข้อมูลถูกจัดกลุ่มอย่างใกล้ชิดรอบ ๆ ค่าเฉลี่ย
เคล็ดลับ:ในการคำนวณความแปรปรวนของประชากรทั้งหมด ให้ดูที่statistics.pvariance()
วิธีการ
ไวยากรณ์
statistics.variance(data, xbar)
ค่าพารามิเตอร์
Parameter | Description |
---|---|
data | Required. The data values to be used (can be any sequence, list or iterator) |
xbar | Optional. The mean of the given data. If omitted (or set to None), the mean is automatically calculated |
หมายเหตุ:ถ้าข้อมูลมีค่าน้อยกว่าสองค่า จะส่งกลับ StatisticsError
รายละเอียดทางเทคนิค
คืนมูลค่า: | ค่า ที่float แสดงถึงความแปรปรวนตัวอย่างของข้อมูลที่กำหนด |
---|---|
เวอร์ชันหลาม: | 3.4 |