Hii I have projectbased on tkinter from tkinter import messagebox from tkinter import *…
- User
Hii I have projectbased on tkinter from tkinter import messagebox from tkinter import * from tkinter import simpledialog import tkinter from tkinter import filedialog import matplotlib.pyplot as plt from tkinter.filedialog import askopenfilename import numpy as np import os import pandas as pd from sklearn.preprocessing import LabelEncoder import seaborn as sns from sklearn.metrics import precision_score from sklearn.metrics import recall_score from sklearn.metrics import f1_score from sklearn.metrics import confusion_matrix from sklearn.metrics import accuracy_score from sklearn.model_selection import train_test_split from keras.models import Sequential, load_model import pickle from keras.layers import Dense, Dropout, Activation, Flatten, LSTM import os from keras.models import Model from sklearn.preprocessing import StandardScaler from keras.callbacks import ModelCheckpoint from keras.utils.np_utils import to_categorical from tcn import compiled_tcn #loading TCN model from sklearn.ensemble import RandomForestClassifier import shap from sklearn.metrics import roc_curve from sklearn.metrics import roc_auc_score from sklearn import metrics
main = tkinter.Tk() main.title("Explainable AI for Intrusion Detection Systems: LIME and SHAP Applicability on Multi-Layer Perceptron") main.geometry("1300x1200")
global filename, lstm_model, tcn_model, X, Y global accuracy, precision, recall, fscore, perturb, features global X_train, X_test, y_train, y_test global labels global label_encoder, scaler, shap_values
def upload(): global filename, labels, dataset filename = filedialog.askopenfilename(initialdir="Dataset") text.delete('1.0', END) text.insert(END,filename+" loaded\n") dataset = pd.read_csv(filename) text.insert(END,str(dataset)+"\n\n") text.update_idletasks() labels = np.unique(dataset["Label"]) label = dataset.groupby('Label').size() label.plot(kind="bar") plt.xlabel("Data Type") plt.ylabel("Count") plt.title("Normal & Attack Graph") plt.show()
def preprocess(): text.delete('1.0', END) global dataset, X, Y, label_encoder, scaler global X_train, X_test, y_train, y_test, perturb, features label_encoder = [] columns = dataset.columns types = dataset.dtypes.values for j in range(len(types)): name = types[j] if name == 'object': #finding column with object type le = LabelEncoder() dataset[columns[j]] = pd.Series(le.fit_transform(dataset[columns[j]].astype(str)))#encode all str columns to numeric label_encoder.append([columns[j], le]) dataset.fillna(0, inplace = True) dataset = dataset[np.isfinite(dataset).all(1)] perturb = dataset['FlowDuration'].ravel() Y = dataset['Label'].ravel() dataset.drop(['Label', 'FlowDuration'], axis = 1,inplace=True) features = dataset.columns X = dataset.values scaler = StandardScaler() X = scaler.fit_transform(X) Y = to_categorical(Y) text.insert(END,"Processed & Normalized Dataset Features = "+str(X))
def trainTestSplit(): text.delete('1.0', END) global X, Y, X_train, X_test, y_train, y_test, perturb, features X = np.reshape(X, (X.shape[0], X.shape[1], 1)) X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.2) for i in range(0, 10): X_test[i,0] = perturb[i] text.insert(END,"Total records found in dataset : "+str(X.shape[0])+"\n\n") text.insert(END,"Dataset split for train and test\n\n") text.insert(END,"80% dataset records used to train Algorithms : "+str(X_train.shape[0])+"\n") text.insert(END,"20% dataset records used to test Algorithms : "+str(X_test.shape[0])+"\n")
- Assistant
- User
there is nothing going to happen after i upload the dataet in the cod epleas emake the changes in the code and make sure you displauy all the graphs which is use to sdisplay using tkinter
- Assistant
- User
TypeError: object of type 'NoneType' has no len() Traceback: File "C:\Users\mani3\miniconda3\envs\explainableIDS37\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 552, in _run_script exec(code, module.dict) File "C:\Users\mani3\Downloads\ExplainableIDS\ExplainableIDS\streamlit_app.py", line 192, in run_lstm() File "C:\Users\mani3\Downloads\ExplainableIDS\ExplainableIDS\streamlit_app.py", line 113, in run_lstm calculate_metrics("LSTM", y_test1, predict) File "C:\Users\mani3\Downloads\ExplainableIDS\ExplainableIDS\streamlit_app.py", line 85, in calculate_metrics sns.heatmap(conf_matrix, annot=True, fmt='d', ax=ax, cmap='Blues', xticklabels=labels, yticklabels=labels) File "C:\Users\mani3\miniconda3\envs\explainableIDS37\lib\site-packages\seaborn\matrix.py", line 537, in heatmap yticklabels, mask) File "C:\Users\mani3\miniconda3\envs\explainableIDS37\lib\site-packages\seaborn\matrix.py", line 137, in if not len(xticklabels):
- Assistant
- User
Total records found in dataset: 4515
80% used for training: 3612
20% used for testing: 903
IndexError: list index out of range Traceback: File "C:\Users\mani3\miniconda3\envs\explainableIDS37\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 552, in _run_script exec(code, module.dict) File "C:\Users\mani3\Downloads\ExplainableIDS\ExplainableIDS\streamlit_app.py", line 207, in graph() File "C:\Users\mani3\Downloads\ExplainableIDS\ExplainableIDS\streamlit_app.py", line 149, in graph 'Value': [precision[0], recall[0], fscore[0], accuracy[0], precision[1], recall[1], fscore[1], accuracy[1]]
this is the eror i am getting fter prrerrocessing also u can show the data distribution like what was shouwing on the tkingter
- Assistant
- User
- Assistant