Machine_learning.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. import tkinter
  2. import webbrowser
  3. from tkinter.filedialog import askopenfilename, asksaveasfilename
  4. import tkinter.messagebox
  5. import os
  6. import chardet
  7. from tkinter.scrolledtext import ScrolledText
  8. import Learn_Numpy
  9. def Main():
  10. global top,ML,Form_List,PATH,bg,bbg,fg
  11. PATH = os.getcwd()
  12. Form_List = []
  13. ML = Learn_Numpy.Machine_Learner()
  14. top = tkinter.Tk()
  15. bg = '#FFFAFA' # 主颜色
  16. bbg = '#FFFAFA' # 按钮颜色
  17. fg = '#000000' # 文字颜色
  18. top["bg"] = bg
  19. FONT = ('黑体', 11) # 设置字体
  20. top.title('CoTan机器学习')
  21. top.resizable(width=False, height=False)
  22. top.geometry('+10+10') # 设置所在位置
  23. width_B = 13 # 标准宽度
  24. height_B = 2
  25. a_y = 0
  26. a_x = 0
  27. tkinter.Button(top, bg=bbg, fg=fg, text='导入CSV', command=Add_CSV, font=FONT, width=width_B,
  28. height=height_B).grid(column=a_x, row=a_y,
  29. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  30. tkinter.Button(top, bg=bbg, fg=fg, text='导入Py', command=Add_Python, font=FONT, width=width_B,
  31. height=height_B).grid(column=a_x + 1, row=a_y,
  32. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  33. tkinter.Button(top, bg=bbg, fg=fg, text='导出CSV', command=to_CSV, font=FONT, width=width_B,
  34. height=height_B).grid(column=a_x + 2, row=a_y,
  35. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  36. global name_Input
  37. a_y += 1
  38. tkinter.Label(top, text='表格名称:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,
  39. row=a_y) # 设置说明
  40. name_Input = tkinter.Entry(top, width=width_B)
  41. name_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  42. a_y += 1
  43. tkinter.Button(top, bg=bbg, fg=fg, text='删除表格', font=FONT, width=width_B,
  44. height=height_B).grid(column=a_x, row=a_y,
  45. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  46. tkinter.Button(top, bg=bbg, fg=fg, text='查看表格', command=Show, font=FONT, width=width_B,
  47. height=height_B).grid(column=a_x + 1, row=a_y,
  48. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  49. tkinter.Button(top, bg=bbg, fg=fg, text='查看单一表格', command=Show_One, font=FONT, width=width_B,
  50. height=height_B).grid(column=a_x + 2, row=a_y,
  51. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  52. global Form_BOX, Index_BOX, Column_BOX, to_HTML_Type, Seq_Input, Code_Input,str_must
  53. a_y += 1
  54. to_HTML_Type = tkinter.IntVar() # 正,负,0
  55. lable = ['选项卡型', '可移动型', '自适应型'] # 复选框
  56. for i in range(3):
  57. tkinter.Radiobutton(top, bg=bg, fg=fg, activebackground=bg, activeforeground=fg, selectcolor=bg, text=lable[i],
  58. variable=to_HTML_Type,
  59. value=i).grid(column=a_x + i, row=a_y, sticky=tkinter.W)
  60. str_must = tkinter.IntVar()
  61. a_y += 1
  62. tkinter.Label(top, text='编码方式:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,
  63. row=a_y) # 设置说明
  64. Code_Input = tkinter.Entry(top, width=width_B)
  65. Code_Input.grid(column=a_x + 1, row=a_y, sticky=tkinter.E + tkinter.W)
  66. buttom = tkinter.Checkbutton(top, bg=bg, fg=fg, activebackground=bg, activeforeground=fg, selectcolor=bg,
  67. text='字符串类型',
  68. variable=str_must)
  69. buttom.grid(column=a_x + 2, row=a_y, sticky=tkinter.W)
  70. a_y += 1
  71. tkinter.Label(top, text='CSV分隔符:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,
  72. row=a_y) # 设置说明
  73. Seq_Input = tkinter.Entry(top, width=width_B)
  74. Seq_Input.grid(column=a_x + 1,columnspan=2, row=a_y, sticky=tkinter.E + tkinter.W)
  75. a_y += 1
  76. Form_BOX = tkinter.Listbox(top, width=width_B * 3, height=height_B * 10) # 显示符号
  77. Form_BOX.grid(column=a_x, row=a_y, columnspan=3, rowspan=10, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  78. a_x += 3
  79. tkinter.Label(top, text='', bg=bg, fg=fg, font=FONT, width=1).grid(column=a_x, row=a_y) # 设置说明
  80. a_x += 1
  81. a_y = 0
  82. tkinter.Label(top, text='【机器学习】', bg=bg, fg=fg, font=FONT, width=width_B * 3, height=height_B).grid(column=a_x,
  83. columnspan=3,
  84. row=a_y,
  85. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N) # 设置说明
  86. global ML_BOX, ML_OUT,X_OUT,Y_OUT
  87. a_y += 1
  88. X_OUT = tkinter.StringVar()
  89. Put = tkinter.Entry(top, width=width_B * 2, textvariable=X_OUT)
  90. Put.grid(column=a_x, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  91. Put['state'] = 'readonly'
  92. tkinter.Button(top, bg=bbg, fg=fg, text='选用特征集', command=set_Feature, font=FONT, width=width_B,
  93. height=height_B).grid(column=a_x + 2, row=a_y, sticky=tkinter.E + tkinter.W)
  94. Y_OUT = tkinter.StringVar()
  95. a_y += 1
  96. Put = tkinter.Entry(top, width=width_B * 2, textvariable=Y_OUT)
  97. Put.grid(column=a_x, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  98. Put['state'] = 'readonly'
  99. tkinter.Button(top, bg=bbg, fg=fg, text='选用标签集', command=set_Label, font=FONT, width=width_B,
  100. height=height_B).grid(column=a_x + 2, row=a_y, sticky=tkinter.E + tkinter.W)
  101. ML_OUT = tkinter.StringVar()
  102. a_y += 1
  103. Put = tkinter.Entry(top, width=width_B * 2, textvariable=ML_OUT)
  104. Put.grid(column=a_x, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  105. Put['state'] = 'readonly'
  106. tkinter.Button(top, bg=bbg, fg=fg, text='选用学习器', command=set_Learner, font=FONT, width=width_B,
  107. height=height_B).grid(column=a_x + 2, row=a_y, sticky=tkinter.E + tkinter.W)
  108. global Split_Input
  109. a_y += 1
  110. tkinter.Label(top, text='测试数据分割:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,
  111. row=a_y)
  112. Split_Input = tkinter.Entry(top, width=width_B * 2)
  113. Split_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  114. a_y += 1
  115. ML_BOX = tkinter.Listbox(top, width=width_B * 3, height=height_B * 5)
  116. ML_BOX.grid(column=a_x, row=a_y, columnspan=3, rowspan=5, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  117. a_y += 5
  118. tkinter.Button(top, bg=bbg, fg=fg, text='导入学习器', font=FONT, width=width_B, height=height_B).grid(
  119. column=a_x, row=a_y,
  120. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  121. tkinter.Button(top, bg=bbg, fg=fg, text='查看数据', command=Show_Args, font=FONT, width=width_B, height=height_B).grid(
  122. column=a_x + 1, row=a_y,
  123. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  124. tkinter.Button(top, bg=bbg, fg=fg, text='删除学习器', command=Del_Leaner, font=FONT, width=width_B,
  125. height=height_B).grid(column=a_x + 2, row=a_y,
  126. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  127. a_y += 1
  128. tkinter.Button(top, bg=bbg, fg=fg, text='训练机器', command=Fit_Learner, font=FONT, width=width_B,
  129. height=height_B).grid(column=a_x, row=a_y,
  130. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  131. tkinter.Button(top, bg=bbg, fg=fg, text='测试机器', command=Score_Learner, font=FONT, width=width_B,
  132. height=height_B).grid(column=a_x + 1, row=a_y,
  133. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  134. tkinter.Button(top, bg=bbg, fg=fg, text='数据预测', command=Predict_Learner, font=FONT, width=width_B,
  135. height=height_B).grid(column=a_x + 2, row=a_y,
  136. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  137. a_y += 1
  138. tkinter.Button(top, bg=bbg, fg=fg, text='单一变量特征选择', command=Add_SelectKBest, font=FONT, width=width_B, height=height_B).grid(column=a_x, row=a_y,columnspan=2,
  139. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  140. tkinter.Button(top, bg=bbg, fg=fg, text='映射标准化', command=Add_Mapzoom, font=FONT, width=width_B,
  141. height=height_B).grid(column=a_x+2, row=a_y,
  142. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  143. a_y += 1
  144. tkinter.Button(top, bg=bbg, fg=fg, text='方差特征选择',command=Add_Variance, font=FONT, width=width_B, height=height_B).grid(
  145. column=a_x, row=a_y,
  146. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  147. tkinter.Button(top, bg=bbg, fg=fg, text='使用学习器筛选', command=Add_SelectFrom_Model, font=FONT, width=width_B,
  148. height=height_B).grid(column=a_x + 1, row=a_y,sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  149. tkinter.Button(top, bg=bbg, fg=fg, text='模糊量化标准化', command=Add_Fuzzy_quantization, font=FONT, width=width_B, height=height_B).grid(
  150. column=a_x + 2, row=a_y,
  151. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  152. a_y += 1
  153. tkinter.Button(top, bg=bbg, fg=fg, text='Z-score',command=Add_Z_Score, font=FONT, width=width_B, height=height_B).grid(
  154. column=a_x, row=a_y,
  155. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  156. tkinter.Button(top, bg=bbg, fg=fg, text='离差标准化', command=Add_MinMaxScaler, font=FONT, width=width_B, height=height_B).grid(
  157. column=a_x + 1, row=a_y,
  158. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  159. tkinter.Button(top, bg=bbg, fg=fg, text='Log变换', command=Add_LogScaler, font=FONT, width=width_B,
  160. height=height_B).grid(column=a_x + 2, row=a_y,
  161. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  162. a_y += 1
  163. tkinter.Button(top, bg=bbg, fg=fg, text='atan变换',command=Add_atanScaler, font=FONT, width=width_B, height=height_B).grid(
  164. column=a_x, row=a_y,
  165. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  166. tkinter.Button(top, bg=bbg, fg=fg, text='小数定标准化', command=Add_decimalScaler, font=FONT, width=width_B, height=height_B).grid(
  167. column=a_x + 1, row=a_y,
  168. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  169. tkinter.Button(top, bg=bbg, fg=fg, text='Sigmod变换', command=Add_sigmodScaler, font=FONT, width=width_B,
  170. height=height_B).grid(column=a_x + 2, row=a_y,
  171. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  172. a_y += 1
  173. tkinter.Button(top, bg=bbg, fg=fg, text='正则化',command=Add_Regularization, font=FONT, width=width_B, height=height_B).grid(
  174. column=a_x, row=a_y,
  175. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  176. tkinter.Button(top, bg=bbg, fg=fg, text='二值离散', command=Add_Binarizer, font=FONT, width=width_B, height=height_B).grid(
  177. column=a_x + 1, row=a_y,
  178. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  179. tkinter.Button(top, bg=bbg, fg=fg, text='多值离散', command=Add_Discretization, font=FONT, width=width_B,
  180. height=height_B).grid(column=a_x + 2, row=a_y,
  181. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  182. a_y += 1
  183. tkinter.Button(top, bg=bbg, fg=fg, text='独热编码',command=Add_OneHotEncoder, font=FONT, width=width_B, height=height_B).grid(
  184. column=a_x, row=a_y,
  185. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  186. tkinter.Button(top, bg=bbg, fg=fg, text='数字编码', command=Add_Label, font=FONT, width=width_B, height=height_B).grid(
  187. column=a_x + 1, row=a_y,
  188. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  189. tkinter.Button(top, bg=bbg, fg=fg, text='缺失填充', command=Add_Missed, font=FONT, width=width_B,
  190. height=height_B).grid(column=a_x + 2, row=a_y,
  191. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  192. a_y += 1
  193. tkinter.Button(top, bg=bbg, fg=fg, text='PCA降维',command=Add_PCA, font=FONT, width=width_B, height=height_B).grid(
  194. column=a_x, row=a_y,
  195. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  196. tkinter.Button(top, bg=bbg, fg=fg, text='RPCA降维', command=Add_RPCA, font=FONT, width=width_B, height=height_B).grid(
  197. column=a_x + 1, row=a_y,
  198. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  199. tkinter.Button(top, bg=bbg, fg=fg, text='KPCA升维', command=Add_KPCA, font=FONT, width=width_B,
  200. height=height_B).grid(column=a_x + 2, row=a_y,
  201. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  202. a_y += 1
  203. tkinter.Button(top, bg=bbg, fg=fg, text='LDA', command=Add_LDA, font=FONT, width=width_B, height=height_B).grid(
  204. column=a_x, row=a_y,columnspan=3,
  205. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  206. a_y += 1
  207. tkinter.Button(top, bg=bbg, fg=fg, text='线性回归', command=Add_Line, font=FONT, width=width_B, height=height_B).grid(
  208. column=a_x, row=a_y,
  209. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  210. tkinter.Button(top, bg=bbg, fg=fg, text='岭回归', command=Add_Ridge, font=FONT, width=width_B, height=height_B).grid(
  211. column=a_x + 1, row=a_y,
  212. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  213. tkinter.Button(top, bg=bbg, fg=fg, text='Lasso', command=Add_Lasso, font=FONT, width=width_B, height=height_B).grid(
  214. column=a_x + 2, row=a_y,
  215. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  216. a_y += 1
  217. tkinter.Button(top, bg=bbg, fg=fg, text='逻辑回归', command=Add_LogisticRegression, font=FONT, width=width_B,
  218. height=height_B).grid(column=a_x, row=a_y,
  219. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  220. tkinter.Button(top, bg=bbg, fg=fg, text='决策树回归',command=Add_Tree, font=FONT, width=width_B, height=height_B).grid(
  221. column=a_x + 1, row=a_y,
  222. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  223. tkinter.Button(top, bg=bbg, fg=fg, text='决策树分类',command=Add_Tree_Class, font=FONT, width=width_B, height=height_B).grid(
  224. column=a_x + 2, row=a_y,
  225. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  226. a_y += 1
  227. tkinter.Button(top, bg=bbg, fg=fg, text='朴素贝叶斯', font=FONT, width=width_B, height=height_B).grid(
  228. column=a_x, row=a_y,
  229. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  230. tkinter.Button(top, bg=bbg, fg=fg, text='K邻近预测', command=Add_Knn, font=FONT, width=width_B, height=height_B).grid(
  231. column=a_x + 1, row=a_y,
  232. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  233. tkinter.Button(top, bg=bbg, fg=fg, text='K邻近分类', command=Add_Knn_Class, font=FONT, width=width_B,
  234. height=height_B).grid(column=a_x + 2, row=a_y,
  235. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  236. a_x += 3
  237. tkinter.Label(top, text='', bg=bg, fg=fg, font=FONT, width=1).grid(column=a_x, row=a_y) # 设置说明
  238. a_x += 1
  239. a_y = 0
  240. tkinter.Label(top, text='【学习器配置】', bg=bg, fg=fg, font=FONT, width=width_B * 3, height=height_B).grid(column=a_x,
  241. columnspan=3,
  242. row=a_y,
  243. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N) # 设置说明
  244. global Args_Learner
  245. a_y += 1
  246. Args_Learner = tkinter.Text(top, width=width_B * 3, height=height_B * 11)
  247. Args_Learner.grid(column=a_x, row=a_y, columnspan=3, rowspan=11,
  248. sticky=tkinter.E + tkinter.W + tkinter.N + tkinter.S)
  249. top.mainloop()
  250. def Del_Leaner():
  251. Learn = get_Learner(True)
  252. set_Learne = get_Learner(False) # 获取学习器Learner
  253. if set_Learne != Learn:
  254. ML.Del_Leaner(Learn)
  255. Update_Leaner()
  256. def Show_Args():
  257. learner = get_Learner(True)
  258. if tkinter.messagebox.askokcancel('提示', f'是否将数据生成表格。\n(可绘制成散点图对比数据)'):
  259. Dic = asksaveasfilename(title='选择保存的CSV', filetypes=[("CSV", ".csv")])
  260. else:
  261. Dic = ''
  262. Data = ML.Show_Args(learner, Dic)
  263. title = f'CoTan数据处理 查看数据:{learner}'
  264. Creat_TextSheet(f'对象:{learner}\n\n{Data[0]}\n\n\n{Data[1]}', title)
  265. Update_BOX()
  266. def get_Args_Learner():
  267. global Args_Learner
  268. return Args_Learner.get('0.0', tkinter.END)
  269. def Score_Learner():
  270. learner = get_Learner()
  271. socore = ML.Score(get_Name(False,True),get_Name(False,False), learner)
  272. tkinter.messagebox.showinfo('测试完成', f'针对测试数据评分结果为:{socore}')
  273. def Predict_Learner():
  274. learner = get_Learner()
  275. Data = ML.Predict(get_Name(False,True),learner)
  276. title = f'CoTan数据处理 学习器:{learner}'
  277. Creat_TextSheet(Data, title)
  278. Update_BOX()
  279. def Fit_Learner():
  280. learner = get_Learner()
  281. try:
  282. split = float(Split_Input.get())
  283. if split < 0 or 1 < split: raise Exception
  284. except:
  285. split = 0.3
  286. socore = ML.Fit(get_Name(False,True),get_Name(False,False), learner, Text=get_Args_Learner(), split=split)
  287. tkinter.messagebox.showinfo('训练完成', f'针对训练数据({(1 - split) * 100}%)评分结果为:{socore[0]}\n'
  288. f'针对测试数据评分({split * 100}%)结果为:{socore[1]}')
  289. def set_Feature():
  290. global X_OUT
  291. X_OUT.set(get_Name())
  292. def set_Label():
  293. global Y_OUT
  294. Y_OUT.set(get_Name())
  295. def set_Learner():
  296. global ML_OUT
  297. ML_OUT.set(get_Learner(True))
  298. def get_Learner(Type=False):
  299. global Learn_Dic, ML_BOX, ML_OUT
  300. if Type:
  301. try:
  302. return list(Learn_Dic.keys())[ML_BOX.curselection()[0]]
  303. except:
  304. # raise
  305. try:
  306. return list(Learn_Dic.keys)[0]
  307. except:
  308. return None
  309. else:
  310. try:
  311. return ML_OUT.get()
  312. except:
  313. return None
  314. def Add_LDA():
  315. Add_leaner('LDA')
  316. def Add_KPCA():
  317. Add_leaner('KPCA')
  318. def Add_RPCA():
  319. Add_leaner('RPCA')
  320. def Add_PCA():
  321. Add_leaner('PCA')
  322. def Add_Missed():
  323. Add_leaner('Missed')
  324. def Add_Label():
  325. Add_leaner('Label')
  326. def Add_OneHotEncoder():
  327. Add_leaner('OneHotEncoder')
  328. def Add_Discretization():
  329. Add_leaner('Discretization')
  330. def Add_Binarizer():
  331. Add_leaner('Binarizer')
  332. def Add_Regularization():
  333. Add_leaner('Regularization')
  334. def Add_Fuzzy_quantization():
  335. Add_leaner('Fuzzy_quantization')
  336. def Add_Mapzoom():
  337. Add_leaner('Mapzoom')
  338. def Add_sigmodScaler():
  339. Add_leaner('sigmodScaler')
  340. def Add_decimalScaler():
  341. Add_leaner('decimalScaler')
  342. def Add_atanScaler():
  343. Add_leaner('atanScaler')
  344. def Add_LogScaler():
  345. Add_leaner('LogScaler')
  346. def Add_MinMaxScaler():
  347. Add_leaner('MinMaxScaler')
  348. def Add_Z_Score():
  349. Add_leaner('Z-Score')
  350. def Add_Tree_Class():
  351. Add_leaner('Tree_class')
  352. def Add_Tree():
  353. Add_leaner('Tree')
  354. def Add_SelectKBest():
  355. Add_leaner('SelectKBest')
  356. def Add_Knn_Class():
  357. Add_leaner('Knn_class')
  358. def Add_LogisticRegression():
  359. Add_leaner('LogisticRegression')
  360. def Add_Lasso():
  361. Add_leaner('Lasso')
  362. def Add_Variance():
  363. Add_leaner('Variance')
  364. def Add_Knn():
  365. Add_leaner('Knn')
  366. def Add_Ridge():
  367. Add_leaner('Ridge')
  368. def Add_Line():
  369. Add_leaner('Line')
  370. def Add_SelectFrom_Model(): # 添加Lenear的核心
  371. ML.Add_SelectFrom_Model(get_Learner(), Text=get_Args_Learner())
  372. Update_Leaner()
  373. def Add_leaner(Type): # 添加Lenear的核心
  374. ML.Add_Learner(Type, Text=get_Args_Learner())
  375. Update_Leaner()
  376. def Update_Leaner():
  377. global Learn_Dic, ML_BOX
  378. Learn_Dic = ML.Return_Learner()
  379. ML_BOX.delete(0, tkinter.END)
  380. ML_BOX.insert(tkinter.END, *Learn_Dic.keys())
  381. def Show_One():
  382. global PATH, to_HTML_Type
  383. Dic = f'{PATH}/$Show_Sheet.html'
  384. try:
  385. name = get_Name()
  386. if name == None: raise Exception
  387. ML.to_Html_One(name, Dic)
  388. webbrowser.open(Dic)
  389. except:
  390. # pass
  391. raise
  392. def Show():
  393. global PATH, to_HTML_Type
  394. Dic = f'{PATH}/$Show_Sheet.html'
  395. try:
  396. name = get_Name()
  397. if name == None: raise Exception
  398. ML.to_Html(name, Dic, to_HTML_Type.get())
  399. webbrowser.open(Dic)
  400. except:
  401. pass
  402. def to_CSV():
  403. global top, Seq_Input, Code_Input, str_must, Index_must
  404. Dic = asksaveasfilename(title='选择保存的CSV', filetypes=[("CSV", ".csv")])
  405. Seq = Seq_Input.get()
  406. name = get_Name()
  407. ML.to_CSV(Dic, name, Seq)
  408. Update_BOX()
  409. def Add_CSV():
  410. global top, Seq_Input, Code_Input, str_must, name_Input
  411. Dic = askopenfilename(title='选择载入的CSV', filetypes=[("CSV", ".csv")])
  412. if Dic == '': return False
  413. Seq = Seq_Input.get()
  414. Codeing = Code_Input.get()
  415. str_ = bool(str_must.get())
  416. name = name_Input.get().replace(' ', '')
  417. if name == '':
  418. name = os.path.splitext(os.path.split(Dic)[1])[0]
  419. print(name)
  420. if Codeing == '':
  421. with open(Dic, 'rb') as f:
  422. Codeing = chardet.detect(f.read())['encoding']
  423. if Seq == '': Seq = ','
  424. ML.read_csv(Dic, name, Codeing, str_, Seq,)
  425. Update_BOX()
  426. def Add_Python():
  427. global top, Seq_Input, Code_Input, str_must, Index_must
  428. Dic = askopenfilename(title='选择载入的py', filetypes=[("Python", ".py"), ("Txt", ".txt")])
  429. name = name_Input.get().replace(' ', '')
  430. if name == '':
  431. name = os.path.splitext(os.path.split(Dic)[1])[0]
  432. with open(Dic, 'r') as f:
  433. ML.Add_Python(f.read(), name)
  434. Update_BOX()
  435. def get_Name(Type=True, x=True): # 获得名字统一接口
  436. global Form_List, Form_BOX, X_OUT
  437. if Type:
  438. try:
  439. return Form_List[Form_BOX.curselection()[0]]
  440. except:
  441. try:
  442. return Form_List[0]
  443. except:
  444. return None
  445. else:
  446. try:
  447. if x:
  448. return X_OUT.get()
  449. else:
  450. return Y_OUT.get()
  451. except:
  452. return None
  453. def Update_BOX():
  454. global top, Form_BOX, Form_List
  455. Form_List = list(ML.get_Form().keys())
  456. Form_BOX.delete(0, tkinter.END)
  457. Form_BOX.insert(tkinter.END, *Form_List)
  458. def Creat_TextSheet(data, name):
  459. global bg
  460. new_top = tkinter.Toplevel(bg=bg)
  461. new_top.title(name)
  462. new_top.geometry('+10+10') # 设置所在位置
  463. text = ScrolledText(new_top, font=('黑体', 13), height=50)
  464. text.pack(fill=tkinter.BOTH)
  465. text.insert('0.0', data)
  466. text.config(state=tkinter.DISABLED)
  467. new_top.resizable(width=False, height=False)
  468. if __name__ == '__main__':
  469. Main()