from tkinter import * from tkinter import filedialog from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg from PIL import ImageTk, Image

root = Tk() root.withdraw() root = Toplevel()

设置窗口大小和标题

root.title('网络攻击检测') root.geometry('1024x1024')

加载图片

bg_image = ImageTk.PhotoImage(Image.open('preview.jpg'))

创建Label

bg_label = Label(root, image=bg_image)

将Label放置在顶部

bg_label.place(x=0, y=0, relwidth=1, relheight=1)

txt = openfile() txt = pd.read_csv(txt) lb1 = Label(root, text='开始检测', font=('华文行楷', 20, 'italic')) lb1.place(relx=0.1, rely=0.1, relwidth=0.8, relheight=0.1)

text = Text(root) text.place(relx=0.1, rely=0.8, relwidth=0.8, relheight=0.2)

btn1 = Button(root, text='导入csv数据集', font=('华文行楷', 20, 'italic')) btn1.place(relx=0.7, rely=0.2, relwidth=0.2, relheight=0.1)

btn2 = Button(root, text='预处理', font=('华文行楷', 20, 'italic'), command=lambda: prepro(txt)) btn2.place(relx=0.7, rely=0.3, relwidth=0.2, relheight=0.1) x = prepro(txt)

t_size = DoubleVar() t_size.set(0.1) t_size2 = DoubleVar() t_size2.set(0.1) t_sizeoptions = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9] option_menu = OptionMenu(root, t_size, *t_sizeoptions) option_menu.place(relx=0.1, rely=0.3, relwidth=0.2, relheight=0.1) btnlp = Button(root, text='获取输入值', font=('华文行楷', 20, 'italic'), command=lambda: t_size2.set(t_size.get())) btnlp.place(relx=0.3, rely=0.3, relwidth=0.2, relheight=0.1) btn3 = Button(root, text='划分训练集', font=('华文行楷', 20, 'italic'), command=lambda: huafen(x, txt, float(t_size.get()))) btn3.place(relx=0.7, rely=0.4, relwidth=0.2, relheight=0.1) x_train, x_test, y_train, y_test = huafen(x, txt, float(t_size2.get()))

btn4 = Button(root, text='随机森林减少特征列', font=('华文行楷', 20, 'italic'), command=lambda: detezhen(xtrain(x, txt, float(t_size.get())), ytrain(x, txt, float(t_size.get())))) btn4.place(relx=0.7, rely=0.5, relwidth=0.2, relheight=0.1)

var = StringVar() var.set('选择你的算法') options = ['K近邻算法', '逻辑回归算法', '朴素贝叶斯', '决策树'] option_menu1 = OptionMenu(root, var, *options) option_menu1.place(relx=0.1, rely=0.5, relwidth=0.2, relheight=0.1) btn5 = Button(root, text='训练', font=('华文行楷', 20, 'italic'), command=lambda: method(var.get(), xtrain(x, txt, float(t_size.get())), ytrain(x, txt, float(t_size.get())), xtest(x, txt, float(t_size.get())))) btn5.place(relx=0.7, rely=0.6, relwidth=0.2, relheight=0.1)

var1 = StringVar() var1.set('选择你的可视化') option = ['条形图', '饼图'] option_menu2 = OptionMenu(root, var1, *option) option_menu2.place(relx=0.1, rely=0.6, relwidth=0.2, relheight=0.1) btn6 = Button(root, text='可视化', font=('华文行楷', 20, 'italic'), command=lambda: keshihua(var1.get(), method(var.get(), xtrain(x, txt, float(t_size.get())), xtest(x, txt, float(t_size.get())))) btn6.place(relx=0.7, rely=0.7, relwidth=0.2, relheight=0.1)

root.mainloop()

网络攻击检测工具 - 基于Python的机器学习模型训练和可视化

原文地址: https://www.cveoy.top/t/topic/omVu 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录