四分位距IQR interquartile range

 

import matplotlib.pyplot as plt

import numpy as np

x = np.array([-100, 12, 45, 30, 70, 36, 50, 40, 26, 38])

print(sorted(x))

a = np.quantile(x, 0.75)  # 上四分之一数

b = np.quantile(x, 0.25)  # 下四分之一数

print("平均数:", np.mean(x))  # 打印均值

print("中位数:", np.median(x))  # 打印中位数

print("上四分之一数:", a)  # 打印上四分之一数

print("下四分之一数:", b)  # 打印下四分之一数

up = a + 1.5 * (a - b)  # 异常值判断标准

down = b - 1.5 * (a - b)  # 异常值判断标准

x = np.sort(x)  # 对原始数据排序

shangjie = x[x < up][-1]  # 除了异常值外的最大值

xiajie = x[x > down][0]  # 除了异常值外的最小值

print("上界:", shangjie)  # 打印上界

print("up:", up)

print("down:", down)

print("下界:", xiajie)  # 打印下界

plt.grid(True)  # 显示网格

y = plt.boxplot(x, meanline=True, showmeans=True,

                flierprops={"marker": "o", "markerfacecolor": "red", "markersize": 15})  # 绘制箱形图,设置异常点大小、样式等

plt.show()  # 显示图

import matplotlib.pyplot as plt
import numpy as np
x = np.array([-100, 12, 45, 30, 70, 36, 50, 40, 26, 38])
print(sorted(x))
a = np.quantile(x, 0.75)  # 上四分之一数
b = np.quantile(x, 0.25)  # 下四分之一数
print("平均数:", np.mean(x))  # 打印均值
print("中位数:", np.median(x))  # 打印中位数
print("上四分之一数:", a)  # 打印上四分之一数
print("下四分之一数:", b)  # 打印下四分之一数
up = a + 1.5 * (a - b)  # 异常值判断标准
down = b - 1.5 * (a - b)  # 异常值判断标准
x = np.sort(x)  # 对原始数据排序
shangjie = x[x < up][-1]  # 除了异常值外的最大值
xiajie = x[x > down][0]  # 除了异常值外的最小值
print("上界:", shangjie)  # 打印上界
print("up:", up)
print("down:", down)
print("下界:", xiajie)  # 打印下界
plt.grid(True)  # 显示网格
y = plt.boxplot(x, meanline=True, showmeans=True,
                flierprops={"marker": "o", "markerfacecolor": "red", "markersize": 15})  # 绘制箱形图,设置异常点大小、样式等
plt.show()  # 显示图

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值