pour ces données (timeStamp,elapsed,label,responseCode,responseMessage,threadName,dataType,success,failureMessage,bytes,sentBytes,grpThreads,allThreads,URL,Latency,IdleTime,Connect 1712659388813,894,HTTP Request,200,OK,SkillsFactoryTest 1-3,text,true,,17415,406,5,5,https://www.jenkins.io/doc/book/installing/,189,0,89 1712659388813,189,HTTP Request-0,301,Moved Permanently,SkillsFactoryTest 1-3,,true,,470,135,5,5,http://www.jenkins.io/doc/book/installing,189,0,89 ) générer par jmeter dans le test de performance , je dois implémenter une solution avec LSTm pour la détection de dégradation de performance , en passant par les étapes principeaux de IA ainsi que d'utilliser des algorithmes pour ajuster les hyperparametres , et create an app streamlit with this solution
To upload files, please first save the app
import streamlit as st
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import LSTM, Dense, Dropout
from sklearn.metrics import mean_squared_error
# Load data
@st.cache_data
def load_data():
data = {
'timeStamp': [1712659388813, 1712659388813],
'elapsed': [894, 189],
'label': ['HTTP Request', 'HTTP Request-0'],
'responseCode': [200, 301],
'responseMessage': ['OK', 'Moved Permanently'],
'threadName': ['SkillsFactoryTest 1-3'] * 2,
'dataType': ['text'] * 2,
'success': [True, True],
'failureMessage': [None, None],
'bytes': [17415, 470],
'sentBytes': [406, 135],
'grpThreads': [5] * 2,
'allThreads': [5] * 2,
'URL': ['https://www.jenkins.io/doc/book/installing/', 'http://www.jenkins.io/doc/book/installing'],
'Latency': [189, 189],
'IdleTime': [0, 0],
'Connect': [89, 89]
}
return pd.DataFrame(data)
# LSTM model
def create_lstm_model(input_shape):
model = Sequential()
model.add(LSTM(50, activation='relu', input_shape=input_shape))
model.add(Dropout(0.2))
model.add(Dense(1))
model.compile(optimizer='adam', loss='mse')
return model
# Function to train model
def train_model(data):
# Preprocess data
data = data[['elapsed', 'Latency']].values
X, y = data[:-1], data[1:, 0]
X = np.reshape(X, (X.shape[0], 1, X.shape[1]))
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
model = create_lstm_model((X_train.shape[1], X_train.shape[2]))
model.fit(X_train, y_train, epochs=100, batch_size=32, verbose=0)
return model, X_test, y_test
# Main Streamlit app
def main():
st.title('Performance Degradation Detection with LSTM')
data = load_data()
st.write('### Raw Data', data)
model, X_test, y_test = train_model(data)
preds = model.predict(X_test)
st.write('### Model Predictions', preds)
st.write('### Expected Values', y_test)
st.write('### Mean Squared Error', mean_squared_error(y_test, preds))
if __name__ == '__main__':
main()
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?