<jupyter_start><jupyter_text>Lendo dados salvos<jupyter_code>dados = pd.read_csv('dados.csv', delimiter=';')
dados['timestamp'] = [datetime.fromtimestamp(timestamp) for timestamp in dados['timestamp']]
dados = dados.set_index(dados['timestamp'])
dados = dados.asfreq(freq='15S', method='bfill')
dados.isnull()
dados.fillna(0, inplace=True)
#dados.isnull()
#dados
dados['req_failed'] = dados['req_failed'].div(100)
#dados
def minutes_to_step(min: int) -> int:
        return int((min * 60) / 15)

regressor = RandomForestRegressor(
                max_depth=20,
                n_estimators=3,
                random_state=123,
            )
dados = dados.drop(columns='timestamp')<jupyter_output><empty_output><jupyter_text>Gráfico dos dados de requisições falhadas, uso de CPU(%) e uso de memória(%) dos dados coletados<jupyter_code>fig, ax = plt.subplots(figsize=(24, 12))
dados['req_failed'].plot(ax=ax, label='req_failed')
dados['cpu_percent'].plot(ax=ax, label='cpu_percent')
dados['memory_percent'].plot(ax=ax, label='memory_percent')

ax.legend(prop={'size': 25})
#dados.plot()
split_time = minutes_to_step(30)
train = dados[:-split_time]
test = dados[-split_time:]
print(len(train), len(test))
#print(train.head())
predictions = {}
for label in ['req_failed', 'cpu_percent', 'memory_percent', 'request_per_sec']:
    forecaster = ForecasterAutoreg(
            regressor=regressor,
            lags=minutes_to_step(30)
        )
    forecaster.fit(y=train[label])
    prediction = forecaster.predict(steps=split_time)
    predictions[label] = prediction<jupyter_output><empty_output><jupyter_text>Gráfico comparativo da predição VS real das requisições por segundo<jupyter_code>fig, ax = plt.subplots(figsize=(28, 12))
predictions['request_per_sec'].plot(ax=ax, label='pred_request_per_sec')
test['request_per_sec'].plot(ax=ax, label='read_request_per_sec')
ax.legend(prop={'size': 25})<jupyter_output><empty_output><jupyter_text>Gráfico da previsão das requisições falhadas, uso de memória(%) e uso de CPU(%)<jupyter_code>fig, ax = plt.subplots(figsize=(24, 12))
predictions['req_failed'].plot(ax=ax, label='pred_req_failed')
predictions['cpu_percent'].plot(ax=ax, label='pred_cpu_percent')
predictions['memory_percent'].plot(ax=ax, label='pred_memory_percent')
ax.legend(prop={'size': 25})<jupyter_output><empty_output><jupyter_text>Gráfico dos dados reais no mesmo período da previsão<jupyter_code>fig, ax = plt.subplots(figsize=(24, 12))
test['req_failed'].plot(ax=ax, label='real_req_failed')
test['cpu_percent'].plot(ax=ax, label='real_cpu_percent')
test['memory_percent'].plot(ax=ax, label='real_memory_percent')
ax.legend(prop={'size': 25})
predictions['req_failed']
res = test
res['pred_req_failed'] = predictions['req_failed']
res['pred_cpu_percent'] = predictions['cpu_percent']
res['pred_memory_percent'] = predictions['memory_percent']
res['diff_req_failed'] = abs(res['pred_req_failed'] - res['req_failed'])
res['diff_cpu_percent'] = abs(res['pred_cpu_percent'] - res['cpu_percent'])
res['diff_memory_percent'] = abs(res['pred_memory_percent'] - res['memory_percent'])

res.head()
desc = res.describe()
desc[['diff_req_failed', 'diff_cpu_percent', 'diff_memory_percent']]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1635122556624263, 'fraction_numerical': 0.013651877133105802, 'mean_word_length': 7.666666666666667, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '28188', 'license': 'MIT', 'n_tokens_mistral': 1204, 'n_tokens_neox': 1167, 'n_words': 176, 'path': 'jupyter/notebookV2.ipynb', 'repo_name': 'BureauTech/BTAlert-IA', 'size': '3223'}