0

我是统计新手。我手头有一个问题,我需要编写 Western Electric 质量控制规则的所有 4 条规则。在同行的帮助下,我已经能够编写第一个和第二个代码,谁能帮我写下第 4 条规则 - “连续九个点落在中心线的同一侧”

在此处输入图像描述

我通过获取低于和高于阈值的数据来绘制规则 1,然后在单个单元格中运行 matplotlib 图。

我无法获取第 4 条规则的数据。

4

1 回答 1

0

即使没有人回答,它也给了我足够的动力去寻找解决方案。虽然我知道我的代码不是最优的,但如果我需要进一步更改,请建议我。

temp_up=[]
temp_down=[]
for i in range(len(data)):
    if arr_data[i] > y_mean:
        temp_up.append(i)
    else:
        temp_down.append(i)

#now we have index values for both data above and below mean, 
#we will now get the sequence of the index to know if there's any run of or greater than length 9
from itertools import groupby
from operator import itemgetter
d_up=[]
d_down=[]
for k, g in groupby(enumerate(temp_up), lambda ix : ix[0] - ix[1]):
    t_up=(list(map(itemgetter(1), g)))
    if len(t_up)>=9:#check if the length of the sequence is greater than or equal to 9
        #get index to mark red for the data
        for i in range(8, len(t_up), 1):
            d_up.append(t_up[i])#index number of data points voilating number 4 rule (above mean)

for k, g in groupby(enumerate(temp_down), lambda ix : ix[0] - ix[1]):
    t_down=(list(map(itemgetter(1), g)))
    if len(t_down)>=9:#check if the length of the sequence is greater than or equal to 9
        #print(t_down)
        #get index to mark red for the data
        for i in range(8, len(t_down), 1):
            d_down.append(t_down[i])#index number of data points voilating number 4 rule (above mean)

data_above_r4 = pd.DataFrame(data.iloc[d_up])
于 2019-06-18T12:27:40.413 回答