<jupyter_start><jupyter_text>加载第1周数据<jupyter_code># timestamp_strat = 1535731200
# timestamp_end = 1536335700 #1535731200 + 5 * 60#
# timestamp_interval = 5 * 60
# file_path = '../2019AIOps_data/'
# kSet_train = Transformer().transformKPIData2KPISet(file_path, timestamp_strat, timestamp_end, timestamp_interval)
#kSet_train.save('../result/metadata/KPISetTrain')
kSet_train = KPISet({}, {})
kSet_train.load('../result/metadata/KPISetTrain')<jupyter_output><empty_output><jupyter_text>加载第2周数据<jupyter_code># timestamp_strat = 1536336000
# timestamp_end = 1536940500 #1536336000 + 5 * 60# 
# timestamp_interval = 5 * 60
# file_path = '../2019AIOps_data/'
# kSet_valid = Transformer().transformKPIData2KPISet(file_path, timestamp_strat, timestamp_end, timestamp_interval)
# kSet_valid.save('../result/metadata/KPISetTrainValid')
kSet_valid = KPISet({}, {})
kSet_valid.load('../result/metadata/KPISetTrainValid')<jupyter_output>100%|██████████| 2016/2016 [41:39<00:00,  1.09s/it]<jupyter_text>使用第一周数据预测第二周数据，此处采用前一周7天同时间窗的KPI的均值作为预测值<jupyter_code># 使用第一周数据预测第二周数据
I = 300
T = I * 288 * 7
train_timestamp_start = 1535731200
train_timestamp_end = 1536335700
for timestamp in tqdm(kSet_valid._KPIPoints):
    tw = math.floor((timestamp - 16 * 3600) % (3600 * 24) / I)
    # print(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(timestamp)), tw)
    for leaf in kSet_valid._KPIPoints[timestamp]._leaf:
        ts_true = kSet_train.get_ts_leaf(leaf=leaf, 
                                         t1=train_timestamp_start + tw * I,
                                         t2=train_timestamp_end, 
                                         delta=T)['true']
        predict = np.mean(ts_true)
        kSet_valid._KPIPoints[timestamp]._leaf[leaf][1] = predict

# 保存数据
kSet_valid.save('../result/metadata/KPISetValidPredict')<jupyter_output>100%|██████████| 2016/2016 [02:26<00:00, 15.06it/s]<jupyter_text>计算MAE<jupyter_code>mae = 0
count = 0
maeList = []
real = []
pred = []
kSet_valid = KPISet({},{})
kSet_valid.load('../result/metadata/KPISetValidPredict2')
for ts in kSet_valid._KPIPoints:
    for leaf in kSet_valid._KPIPoints[ts]._leaf:
        value = kSet_valid._KPIPoints[ts]._leaf[leaf]
        mae += abs(value[0] - value[1])
        maeList.append(mae)
        real.append(value[0])
        pred.append(value[1])
        count += 1
print(len(maeList))
print('MAE = %f' % (mae / count))
evaluate(real, pred, 'MAE')
visualize(real, pred)<jupyter_output>MAE 123.788527034
{'fraction_non_alphanumeric': 0.15107330903199676, 'fraction_numerical': 0.07776427703523693, 'mean_word_length': 4.082304526748971, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '307488', 'license': 'Apache-2.0', 'n_tokens_mistral': 1122, 'n_tokens_neox': 987, 'n_words': 129, 'path': 'hotspot/code/predict.ipynb', 'repo_name': 'FudanYuan/faultLocalization', 'size': '2469'}