Machine_learning.py 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856
  1. import tkinter
  2. import webbrowser
  3. from tkinter.filedialog import askopenfilename, asksaveasfilename,askdirectory
  4. import tkinter.messagebox
  5. import os
  6. import chardet
  7. from tkinter.scrolledtext import ScrolledText
  8. import Learn_Numpy
  9. import webbrowser
  10. def Main():
  11. global top,ML,Form_List,PATH,bg,bbg,fg,Merge_list
  12. PATH = os.getcwd()
  13. Form_List = []
  14. Merge_list = []
  15. ML = Learn_Numpy.Machine_Learner()
  16. top = tkinter.Tk()
  17. bg = '#FFFAFA' # 主颜色
  18. bbg = '#FFFAFA' # 按钮颜色
  19. fg = '#000000' # 文字颜色
  20. top["bg"] = bg
  21. FONT = ('黑体', 11) # 设置字体
  22. top.title('CoTan机器学习')
  23. top.resizable(width=False, height=False)
  24. top.geometry('+10+10') # 设置所在位置
  25. width_B = 13 # 标准宽度
  26. height_B = 2
  27. a_y = 0
  28. a_x = 0
  29. tkinter.Button(top, bg=bbg, fg=fg, text='导入CSV', command=Add_CSV, font=FONT, width=width_B,
  30. height=height_B).grid(column=a_x, row=a_y,
  31. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  32. tkinter.Button(top, bg=bbg, fg=fg, text='导入Py', command=Add_Python, font=FONT, width=width_B,
  33. height=height_B).grid(column=a_x + 1, row=a_y,
  34. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  35. tkinter.Button(top, bg=bbg, fg=fg, text='导出CSV', command=to_CSV, font=FONT, width=width_B,
  36. height=height_B).grid(column=a_x + 2, row=a_y,
  37. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  38. global name_Input
  39. a_y += 1
  40. tkinter.Label(top, text='表格名称:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,
  41. row=a_y) # 设置说明
  42. name_Input = tkinter.Entry(top, width=width_B)
  43. name_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  44. a_y += 1
  45. tkinter.Button(top, bg=bbg, fg=fg, text='删除表格', font=FONT, width=width_B,
  46. height=height_B).grid(column=a_x, row=a_y,
  47. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  48. tkinter.Button(top, bg=bbg, fg=fg, text='查看表格', command=Show, font=FONT, width=width_B,
  49. height=height_B).grid(column=a_x + 1, row=a_y,
  50. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  51. tkinter.Button(top, bg=bbg, fg=fg, text='查看单一表格', command=Show_One, font=FONT, width=width_B,
  52. height=height_B).grid(column=a_x + 2, row=a_y,
  53. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  54. global Form_BOX, Index_BOX, Column_BOX, to_HTML_Type, Seq_Input, Code_Input,str_must
  55. a_y += 1
  56. to_HTML_Type = tkinter.IntVar() # 正,负,0
  57. lable = ['选项卡型', '可移动型', '自适应型'] # 复选框
  58. for i in range(3):
  59. tkinter.Radiobutton(top, bg=bg, fg=fg, activebackground=bg, activeforeground=fg, selectcolor=bg, text=lable[i],
  60. variable=to_HTML_Type,
  61. value=i).grid(column=a_x + i, row=a_y, sticky=tkinter.W)
  62. str_must = tkinter.IntVar()
  63. a_y += 1
  64. tkinter.Label(top, text='编码方式:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,
  65. row=a_y) # 设置说明
  66. Code_Input = tkinter.Entry(top, width=width_B)
  67. Code_Input.grid(column=a_x + 1, row=a_y, sticky=tkinter.E + tkinter.W)
  68. buttom = tkinter.Checkbutton(top, bg=bg, fg=fg, activebackground=bg, activeforeground=fg, selectcolor=bg,
  69. text='字符串类型',
  70. variable=str_must)
  71. buttom.grid(column=a_x + 2, row=a_y, sticky=tkinter.W)
  72. a_y += 1
  73. tkinter.Label(top, text='CSV分隔符:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,
  74. row=a_y) # 设置说明
  75. Seq_Input = tkinter.Entry(top, width=width_B)
  76. Seq_Input.grid(column=a_x + 1,columnspan=2, row=a_y, sticky=tkinter.E + tkinter.W)
  77. a_y += 1
  78. Form_BOX = tkinter.Listbox(top, width=width_B * 3, height=height_B * 10) # 显示符号
  79. Form_BOX.grid(column=a_x, row=a_y, columnspan=3, rowspan=10, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  80. #422
  81. a_y += 10
  82. tkinter.Button(top, bg=bbg, fg=fg, text='添加数据', command=Merge_Add, font=FONT, width=width_B,
  83. height=height_B).grid(column=a_x, row=a_y,
  84. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  85. tkinter.Button(top, bg=bbg, fg=fg, text='删除数据', command=Merge_Del, font=FONT, width=width_B,
  86. height=height_B).grid(column=a_x + 1, row=a_y,
  87. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  88. tkinter.Button(top, bg=bbg, fg=fg, text='组合数据', command=Merge, font=FONT, width=width_B,
  89. height=height_B).grid(column=a_x + 2, row=a_y,
  90. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  91. global Processing_type, Shape_Input, Merge_BOX
  92. a_y += 1
  93. Merge_BOX = tkinter.Listbox(top, width=width_B * 3, height=height_B * 3) # 显示符号
  94. Merge_BOX.grid(column=a_x, row=a_y, columnspan=3, rowspan=3, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  95. a_y += 3
  96. Processing_type = tkinter.IntVar()#正,负,0
  97. lable = ['横向处理','纵向处理','深度处理']#复选框
  98. for i in range(3):
  99. tkinter.Radiobutton(top,bg = bg,fg = fg,activebackground=bg,activeforeground=fg,selectcolor=bg,text=lable[i],
  100. variable=Processing_type, value=i).grid(column=a_x+i, row=a_y, sticky=tkinter.W)
  101. a_y += 1
  102. tkinter.Button(top, bg=bbg, fg=fg, text='数据切片', command=Two_Split, font=FONT, width=width_B,
  103. height=height_B).grid(column=a_x, row=a_y,
  104. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  105. tkinter.Button(top, bg=bbg, fg=fg, text='数据分割', command=Split, font=FONT, width=width_B,
  106. height=height_B).grid(column=a_x + 1, row=a_y,columnspan=2,
  107. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  108. a_y += 1
  109. tkinter.Label(top, text='重塑形状:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  110. Shape_Input = tkinter.Entry(top, width=width_B)
  111. Shape_Input.grid(column=a_x + 1, row=a_y, sticky=tkinter.E + tkinter.W)
  112. tkinter.Button(top, bg=bbg, fg=fg, text='矩阵重塑', command=Reshape, font=FONT, width=width_B,
  113. height=height_B).grid(column=a_x + 2, row=a_y,
  114. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  115. a_y += 1
  116. tkinter.Button(top, bg=bbg, fg=fg, text='矩阵伸展', command=Reval, font=FONT, width=width_B,
  117. height=height_B).grid(column=a_x, row=a_y,
  118. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  119. tkinter.Button(top, bg=bbg, fg=fg, text='矩阵降维', command=Del_Ndim, font=FONT, width=width_B,
  120. height=height_B).grid(column=a_x + 1, row=a_y,
  121. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  122. tkinter.Button(top, bg=bbg, fg=fg, text='矩阵转置', command=T, font=FONT, width=width_B,
  123. height=height_B).grid(column=a_x + 2, row=a_y,
  124. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  125. a_x += 3
  126. tkinter.Label(top, text='', bg=bg, fg=fg, font=FONT, width=1).grid(column=a_x, row=a_y) # 设置说明
  127. a_x += 1
  128. a_y = 0
  129. tkinter.Label(top, text='【机器学习】', bg=bg, fg=fg, font=FONT, width=width_B * 3, height=height_B).grid(column=a_x,
  130. columnspan=3,
  131. row=a_y,
  132. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N) # 设置说明
  133. global ML_BOX, ML_OUT,X_OUT,Y_OUT
  134. a_y += 1
  135. X_OUT = tkinter.StringVar()
  136. Put = tkinter.Entry(top, width=width_B * 2, textvariable=X_OUT)
  137. Put.grid(column=a_x, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  138. Put['state'] = 'readonly'
  139. tkinter.Button(top, bg=bbg, fg=fg, text='选用X集', command=set_Feature, font=FONT, width=width_B,
  140. height=height_B).grid(column=a_x + 2, row=a_y, sticky=tkinter.E + tkinter.W)
  141. Y_OUT = tkinter.StringVar()
  142. a_y += 1
  143. Put = tkinter.Entry(top, width=width_B * 2, textvariable=Y_OUT)
  144. Put.grid(column=a_x, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  145. Put['state'] = 'readonly'
  146. tkinter.Button(top, bg=bbg, fg=fg, text='选用Y集', command=set_Label, font=FONT, width=width_B,
  147. height=height_B).grid(column=a_x + 2, row=a_y, sticky=tkinter.E + tkinter.W)
  148. ML_OUT = tkinter.StringVar()
  149. a_y += 1
  150. Put = tkinter.Entry(top, width=width_B * 2, textvariable=ML_OUT)
  151. Put.grid(column=a_x, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  152. Put['state'] = 'readonly'
  153. tkinter.Button(top, bg=bbg, fg=fg, text='选用学习器', command=set_Learner, font=FONT, width=width_B,
  154. height=height_B).grid(column=a_x + 2, row=a_y, sticky=tkinter.E + tkinter.W)
  155. global Split_Input
  156. a_y += 1
  157. tkinter.Label(top, text='测试数据分割:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,
  158. row=a_y)
  159. Split_Input = tkinter.Entry(top, width=width_B * 2)
  160. Split_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  161. a_y += 1
  162. ML_BOX = tkinter.Listbox(top, width=width_B * 3, height=height_B * 5)
  163. ML_BOX.grid(column=a_x, row=a_y, columnspan=3, rowspan=5, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  164. a_y += 5
  165. tkinter.Button(top, bg=bbg, fg=fg, text='导入学习器', font=FONT, width=width_B, height=height_B).grid(
  166. column=a_x, row=a_y,
  167. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  168. tkinter.Button(top, bg=bbg, fg=fg, text='查看数据', command=Show_Args, font=FONT, width=width_B, height=height_B).grid(
  169. column=a_x + 1, row=a_y,
  170. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  171. tkinter.Button(top, bg=bbg, fg=fg, text='删除学习器', command=Del_Leaner, font=FONT, width=width_B,
  172. height=height_B).grid(column=a_x + 2, row=a_y,
  173. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  174. a_y += 1
  175. tkinter.Button(top, bg=bbg, fg=fg, text='训练机器', command=Fit_Learner, font=FONT, width=width_B,
  176. height=height_B).grid(column=a_x, row=a_y,
  177. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  178. tkinter.Button(top, bg=bbg, fg=fg, text='测试机器', command=Score_Learner, font=FONT, width=width_B,
  179. height=height_B).grid(column=a_x + 1, row=a_y,
  180. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  181. tkinter.Button(top, bg=bbg, fg=fg, text='数据预测', command=Predict_Learner, font=FONT, width=width_B,
  182. height=height_B).grid(column=a_x + 2, row=a_y,
  183. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  184. a_y += 1
  185. 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,
  186. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  187. tkinter.Button(top, bg=bbg, fg=fg, text='映射标准化', command=Add_Mapzoom, font=FONT, width=width_B,
  188. height=height_B).grid(column=a_x+2, row=a_y,
  189. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  190. a_y += 1
  191. tkinter.Button(top, bg=bbg, fg=fg, text='方差特征选择',command=Add_Variance, font=FONT, width=width_B, height=height_B).grid(
  192. column=a_x, row=a_y,
  193. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  194. tkinter.Button(top, bg=bbg, fg=fg, text='使用学习器筛选', command=Add_SelectFrom_Model, font=FONT, width=width_B,
  195. height=height_B).grid(column=a_x + 1, row=a_y,sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  196. tkinter.Button(top, bg=bbg, fg=fg, text='模糊量化标准化', command=Add_Fuzzy_quantization, font=FONT, width=width_B, height=height_B).grid(
  197. column=a_x + 2, row=a_y,
  198. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  199. a_y += 1
  200. tkinter.Button(top, bg=bbg, fg=fg, text='Z-score',command=Add_Z_Score, font=FONT, width=width_B, height=height_B).grid(
  201. column=a_x, row=a_y,
  202. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  203. tkinter.Button(top, bg=bbg, fg=fg, text='离差标准化', command=Add_MinMaxScaler, font=FONT, width=width_B, height=height_B).grid(
  204. column=a_x + 1, row=a_y,
  205. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  206. tkinter.Button(top, bg=bbg, fg=fg, text='Log变换', command=Add_LogScaler, font=FONT, width=width_B,
  207. height=height_B).grid(column=a_x + 2, row=a_y,
  208. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  209. a_y += 1
  210. tkinter.Button(top, bg=bbg, fg=fg, text='atan变换',command=Add_atanScaler, font=FONT, width=width_B, height=height_B).grid(
  211. column=a_x, row=a_y,
  212. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  213. tkinter.Button(top, bg=bbg, fg=fg, text='小数定标准化', command=Add_decimalScaler, font=FONT, width=width_B, height=height_B).grid(
  214. column=a_x + 1, row=a_y,
  215. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  216. tkinter.Button(top, bg=bbg, fg=fg, text='Sigmod变换', command=Add_sigmodScaler, font=FONT, width=width_B,
  217. height=height_B).grid(column=a_x + 2, row=a_y,
  218. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  219. a_y += 1
  220. tkinter.Button(top, bg=bbg, fg=fg, text='正则化',command=Add_Regularization, font=FONT, width=width_B, height=height_B).grid(
  221. column=a_x, 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_Binarizer, font=FONT, width=width_B, height=height_B).grid(
  224. column=a_x + 1, row=a_y,
  225. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  226. tkinter.Button(top, bg=bbg, fg=fg, text='多值离散', command=Add_Discretization, font=FONT, width=width_B,
  227. height=height_B).grid(column=a_x + 2, row=a_y,
  228. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  229. a_y += 1
  230. tkinter.Button(top, bg=bbg, fg=fg, text='独热编码',command=Add_OneHotEncoder, font=FONT, width=width_B, height=height_B).grid(
  231. column=a_x, row=a_y,
  232. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  233. tkinter.Button(top, bg=bbg, fg=fg, text='数字编码', command=Add_Label, font=FONT, width=width_B, height=height_B).grid(
  234. column=a_x + 1, row=a_y,
  235. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  236. tkinter.Button(top, bg=bbg, fg=fg, text='缺失填充', command=Add_Missed, font=FONT, width=width_B,
  237. height=height_B).grid(column=a_x + 2, row=a_y,
  238. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  239. a_y += 1
  240. tkinter.Button(top, bg=bbg, fg=fg, text='PCA降维',command=Add_PCA, font=FONT, width=width_B, height=height_B).grid(
  241. column=a_x, row=a_y,
  242. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  243. tkinter.Button(top, bg=bbg, fg=fg, text='RPCA降维', command=Add_RPCA, font=FONT, width=width_B, height=height_B).grid(
  244. column=a_x + 1, row=a_y,
  245. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  246. tkinter.Button(top, bg=bbg, fg=fg, text='KPCA升维', command=Add_KPCA, font=FONT, width=width_B,
  247. height=height_B).grid(column=a_x + 2, row=a_y,
  248. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  249. a_y += 1
  250. tkinter.Button(top, bg=bbg, fg=fg, text='LDA降维', command=Add_LDA, font=FONT, width=width_B, height=height_B).grid(
  251. column=a_x, row=a_y,
  252. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  253. tkinter.Button(top, bg=bbg, fg=fg, text='NMF降维', command=Add_NMF, font=FONT, width=width_B, height=height_B).grid(
  254. column=a_x+1, row=a_y,
  255. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  256. tkinter.Button(top, bg=bbg, fg=fg, text='t-SNE', command=Add_TSNE, font=FONT, width=width_B, height=height_B).grid(
  257. column=a_x+2, row=a_y,
  258. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  259. a_y += 1
  260. tkinter.Button(top, bg=bbg, fg=fg, text='线性回归', command=Add_Line, font=FONT, width=width_B, height=height_B).grid(
  261. column=a_x, row=a_y,
  262. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  263. tkinter.Button(top, bg=bbg, fg=fg, text='岭回归', command=Add_Ridge, font=FONT, width=width_B, height=height_B).grid(
  264. column=a_x + 1, row=a_y,
  265. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  266. tkinter.Button(top, bg=bbg, fg=fg, text='Lasso', command=Add_Lasso, font=FONT, width=width_B, height=height_B).grid(
  267. column=a_x + 2, row=a_y,
  268. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  269. a_y += 1
  270. tkinter.Button(top, bg=bbg, fg=fg, text='逻辑回归', command=Add_LogisticRegression, font=FONT, width=width_B,
  271. height=height_B).grid(column=a_x, row=a_y,
  272. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  273. tkinter.Button(top, bg=bbg, fg=fg, text='K邻近预测', command=Add_Knn, font=FONT, width=width_B, height=height_B).grid(
  274. column=a_x + 1, row=a_y,
  275. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  276. tkinter.Button(top, bg=bbg, fg=fg, text='K邻近分类', command=Add_Knn_Class, font=FONT, width=width_B,
  277. height=height_B).grid(column=a_x + 2, row=a_y,
  278. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  279. a_y += 1
  280. tkinter.Button(top, bg=bbg, fg=fg, text='梯度回归树回归', command=Add_GradientTree, font=FONT, width=width_B,
  281. height=height_B).grid(column=a_x, row=a_y,
  282. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  283. tkinter.Button(top, bg=bbg, fg=fg, text='决策树回归',command=Add_Tree, font=FONT, width=width_B, height=height_B).grid(
  284. column=a_x + 1, row=a_y,
  285. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  286. tkinter.Button(top, bg=bbg, fg=fg, text='决策树分类',command=Add_Tree_Class, font=FONT, width=width_B, height=height_B).grid(
  287. column=a_x + 2, row=a_y,
  288. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  289. a_y += 1
  290. tkinter.Button(top, bg=bbg, fg=fg, text='梯度回归树分类', command=Add_GradientTree_class, font=FONT, width=width_B,
  291. height=height_B).grid(column=a_x, row=a_y,sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  292. tkinter.Button(top, bg=bbg, fg=fg, text='随机森林回归', command=Add_Forest, font=FONT, width=width_B,
  293. height=height_B).grid(column=a_x+1, row=a_y,
  294. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  295. tkinter.Button(top, bg=bbg, fg=fg, text='随机森林分类',command=Add_Forest_class, font=FONT, width=width_B, height=height_B).grid(
  296. column=a_x + 2, row=a_y,sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  297. a_x += 3
  298. tkinter.Label(top, text='', bg=bg, fg=fg, font=FONT, width=1).grid(column=a_x, row=a_y) # 设置说明
  299. a_x += 1
  300. a_y = 0
  301. tkinter.Button(top, bg=bbg, fg=fg, text='多层感知机回归', command=Add_MLP, font=FONT, width=width_B,
  302. height=height_B).grid(column=a_x, row=a_y,sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  303. tkinter.Button(top, bg=bbg, fg=fg, text='多层感知机分类', command=Add_MLP_class, font=FONT, width=width_B,
  304. height=height_B).grid(column=a_x+1, row=a_y,
  305. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  306. tkinter.Button(top, bg=bbg, fg=fg, text='随机森林分类',command=Add_Forest_class, font=FONT, width=width_B, height=height_B).grid(
  307. column=a_x + 2, row=a_y,sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  308. a_y += 1
  309. tkinter.Button(top, bg=bbg, fg=fg, text='支持向量机分类:SVC', command=Add_SVC, font=FONT, width=width_B, height=height_B).grid(
  310. column=a_x, row=a_y,columnspan=2,
  311. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  312. tkinter.Button(top, bg=bbg, fg=fg, text='回归:SVR', command=Add_SVR, font=FONT, width=width_B, height=height_B).grid(
  313. column=a_x + 2, row=a_y,
  314. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  315. a_y += 1
  316. tkinter.Button(top, bg=bbg, fg=fg, text='k-means', command=Add_KMeans, font=FONT, width=width_B,
  317. height=height_B).grid(column=a_x, row=a_y,sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  318. tkinter.Button(top, bg=bbg, fg=fg, text='凝聚聚类', command=Add_Agglomerative, font=FONT, width=width_B,
  319. height=height_B).grid(column=a_x+1, row=a_y,
  320. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  321. tkinter.Button(top, bg=bbg, fg=fg, text='DBSCAN',command=Add_DBSCAN, font=FONT, width=width_B, height=height_B).grid(
  322. column=a_x + 2, row=a_y,sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  323. a_y += 1
  324. tkinter.Button(top, bg=bbg, fg=fg, text='特征分类图', command=Add_ClassBar, font=FONT, width=width_B,
  325. height=height_B).grid(column=a_x, row=a_y,sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  326. tkinter.Button(top, bg=bbg, fg=fg, text='临近特征回归图', command=Add_FeatureScatter, font=FONT, width=width_B,
  327. height=height_B).grid(column=a_x+1, row=a_y,
  328. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  329. tkinter.Button(top, bg=bbg, fg=fg, text='临近特征分类图',command=Add_FeatureScatterClass, font=FONT, width=width_B, height=height_B).grid(
  330. column=a_x + 2, row=a_y,sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  331. a_y += 1
  332. tkinter.Button(top, bg=bbg, fg=fg, text='所有特征回归图', command=Add_FeatureScatter_all, font=FONT, width=width_B,
  333. height=height_B).grid(column=a_x, row=a_y,sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  334. tkinter.Button(top, bg=bbg, fg=fg, text='所有特征分类图', command=Add_FeatureScatterClass_all, font=FONT, width=width_B,
  335. height=height_B).grid(column=a_x+1, row=a_y,
  336. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  337. tkinter.Button(top, bg=bbg, fg=fg, text='临近特征预测图',command=Add_Predictive_HeatMap, font=FONT, width=width_B, height=height_B).grid(
  338. column=a_x + 2, row=a_y,sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  339. a_y += 1
  340. tkinter.Button(top, bg=bbg, fg=fg, text='所有特征预测图', command=Add_Predictive_HeatMap_More, font=FONT, width=width_B,
  341. height=height_B).grid(column=a_x, row=a_y,sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  342. tkinter.Button(top, bg=bbg, fg=fg, text='矩阵热力图', command=Add_Numpy_To_HeatMap, font=FONT, width=width_B,
  343. height=height_B).grid(column=a_x+1, row=a_y,
  344. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  345. tkinter.Button(top, bg=bbg, fg=fg, text='数据y-x散点图',command=Add_FeatureY_X, font=FONT, width=width_B, height=height_B).grid(
  346. column=a_x + 2, row=a_y,sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  347. a_y += 1
  348. tkinter.Button(top, bg=bbg, fg=fg, text='聚类树状图', command=Add_ClusterTree, font=FONT, width=width_B,
  349. height=height_B).grid(column=a_x, row=a_y,sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  350. tkinter.Button(top, bg=bbg, fg=fg, text='获取数据', command=Add_View_data, font=FONT, width=width_B,
  351. height=height_B).grid(column=a_x+1, row=a_y,
  352. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  353. tkinter.Button(top, bg=bbg, fg=fg, text='矩阵散点图',command=Add_MatrixScatter, font=FONT, width=width_B, height=height_B).grid(
  354. column=a_x + 2, row=a_y,sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  355. a_x += 3
  356. tkinter.Label(top, text='', bg=bg, fg=fg, font=FONT, width=1).grid(column=a_x, row=a_y) # 设置说明
  357. a_x += 1
  358. a_y = 0
  359. tkinter.Label(top, text='【学习器配置】', bg=bg, fg=fg, font=FONT, width=width_B * 3, height=height_B).grid(column=a_x,
  360. columnspan=3,
  361. row=a_y,
  362. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N) # 设置说明
  363. global Args_Learner
  364. a_y += 1
  365. Args_Learner = tkinter.Text(top, width=width_B * 3, height=height_B * 11)
  366. Args_Learner.grid(column=a_x, row=a_y, columnspan=3, rowspan=11,
  367. sticky=tkinter.E + tkinter.W + tkinter.N + tkinter.S)
  368. top.mainloop()
  369. #90
  370. def Reshape():
  371. global ML,Processing_type
  372. shape = eval(f'[{Shape_Input.get()}]')[0]
  373. ML.reShape(get_Name(),shape)
  374. Update_BOX()
  375. def T():
  376. global ML,Processing_type,Shape_Input
  377. try:
  378. Func = eval(f'[{Shape_Input.get()}]')
  379. except:
  380. Func = None
  381. ML.T(get_Name(),Func)
  382. Update_BOX()
  383. def Del_Ndim():
  384. global ML
  385. ML.Del_Ndim(get_Name())
  386. Update_BOX()
  387. def Reval():
  388. global ML,Processing_type
  389. Type = Processing_type.get()
  390. ML.Reval(get_Name(),Type)
  391. Update_BOX()
  392. def Two_Split():
  393. global ML,Processing_type,Shape_Input
  394. Type = Processing_type.get()
  395. ML.Two_Split(get_Name(),Shape_Input.get(),Type)
  396. Update_BOX()
  397. def Split():
  398. global ML,Processing_type,Shape_Input
  399. Type = Processing_type.get()
  400. try:
  401. Split = eval(f'[{Shape_Input.get()}]')[0]
  402. except:
  403. Split = 2
  404. ML.Split(get_Name(),Split,Type)
  405. Update_BOX()
  406. def Merge():
  407. global Merge_list,ML,Processing_type
  408. if len(Merge_list) < 1:
  409. return False
  410. Type = Processing_type.get()
  411. ML.Merge(Merge_list,Type)
  412. Update_BOX()
  413. def Update_Merge():
  414. global Merge_list,Merge_BOX
  415. Merge_BOX.delete(0, tkinter.END)
  416. Merge_BOX.insert(tkinter.END, *Merge_list)
  417. def Merge_Del():
  418. global Merge_list,Merge_BOX
  419. del Merge_list[Merge_BOX.curselection()[0]]
  420. Update_Merge()
  421. def Merge_Add():
  422. global Merge_list
  423. name = get_Name()
  424. Merge_list.append(name)
  425. Update_Merge()
  426. def Del_Leaner():
  427. Learn = get_Learner(True)
  428. set_Learne = get_Learner(False) # 获取学习器Learner
  429. if set_Learne != Learn:
  430. ML.Del_Leaner(Learn)
  431. Update_Leaner()
  432. def Show_Args():
  433. learner = get_Learner(True)
  434. Dic = askdirectory(title='选择保存的CSV')
  435. data = ML.Show_Args(learner,Dic)
  436. webbrowser.open(data[0])
  437. # title = f'CoTan数据处理 查看数据:{learner}'
  438. # Creat_TextSheet(f'对象:{learner}\n\n{Data[0]}\n\n\n{Data[1]}', title)
  439. Update_BOX()
  440. def get_Args_Learner():
  441. global Args_Learner
  442. return Args_Learner.get('0.0', tkinter.END)
  443. def Score_Learner():
  444. learner = get_Learner()
  445. socore = ML.Score(get_Name(False,True),get_Name(False,False), learner)
  446. tkinter.messagebox.showinfo('测试完成', f'针对测试数据评分结果为:{socore}')
  447. def Predict_Learner():
  448. learner = get_Learner()
  449. Data = ML.Predict(get_Name(False,True),learner)
  450. title = f'CoTan数据处理 学习器:{learner}'
  451. Creat_TextSheet(Data, title)
  452. Update_BOX()
  453. def Fit_Learner():
  454. learner = get_Learner()
  455. try:
  456. split = float(Split_Input.get())
  457. if split < 0 or 1 < split: raise Exception
  458. except:
  459. split = 0.3
  460. socore = ML.Fit(get_Name(False,True),get_Name(False,False), learner, Text=get_Args_Learner(), split=split)
  461. tkinter.messagebox.showinfo('训练完成', f'针对训练数据({(1 - split) * 100}%)评分结果为:{socore[0]}\n'
  462. f'针对测试数据评分({split * 100}%)结果为:{socore[1]}')
  463. def set_Feature():
  464. global X_OUT
  465. X_OUT.set(get_Name())
  466. def set_Label():
  467. global Y_OUT
  468. Y_OUT.set(get_Name())
  469. def set_Learner():
  470. global ML_OUT
  471. ML_OUT.set(get_Learner(True))
  472. def get_Learner(Type=False):
  473. global Learn_Dic, ML_BOX, ML_OUT
  474. if Type:
  475. try:
  476. return list(Learn_Dic.keys())[ML_BOX.curselection()[0]]
  477. except:
  478. # raise
  479. try:
  480. return list(Learn_Dic.keys)[0]
  481. except:
  482. return get_Learner(False)
  483. else:
  484. try:
  485. return ML_OUT.get()
  486. except:
  487. return None
  488. def Add_MatrixScatter(): # 添加Lenear的核心
  489. Add_leaner('MatrixScatter')
  490. def Add_View_data(): # 添加Lenear的核心
  491. ML.Add_View_data(get_Learner(), Text=get_Args_Learner())
  492. Update_Leaner()
  493. def Add_ClusterTree():
  494. Add_leaner('ClusterTree')
  495. def Add_FeatureY_X():
  496. Add_leaner('FeatureY-X')
  497. def Add_Numpy_To_HeatMap():
  498. Add_leaner('HeatMap')
  499. def Add_Predictive_HeatMap_More(): # 添加Lenear的核心
  500. ML.Add_Predictive_HeatMap_More(get_Learner(), Text=get_Args_Learner())
  501. Update_Leaner()
  502. def Add_Predictive_HeatMap(): # 添加Lenear的核心
  503. ML.Add_Predictive_HeatMap(get_Learner(), Text=get_Args_Learner())
  504. Update_Leaner()
  505. def Add_FeatureScatterClass_all():
  506. Add_leaner('FeatureScatterClass_all')
  507. def Add_FeatureScatter_all():
  508. Add_leaner('FeatureScatter_all')
  509. def Add_FeatureScatterClass():
  510. Add_leaner('FeatureScatterClass')
  511. def Add_FeatureScatter():
  512. Add_leaner('FeatureScatter')
  513. def Add_ClassBar():
  514. Add_leaner('ClassBar')
  515. def Add_DBSCAN():
  516. Add_leaner('DBSCAN')
  517. def Add_Agglomerative():
  518. Add_leaner('Agglomerative')
  519. def Add_KMeans():
  520. Add_leaner('k-means')
  521. def Add_MLP_class():
  522. Add_leaner('MLP_class')
  523. def Add_MLP():
  524. Add_leaner('MLP')
  525. def Add_SVR():
  526. Add_leaner('SVR')
  527. def Add_SVC():
  528. Add_leaner('SVC')
  529. def Add_GradientTree():
  530. Add_leaner('GradientTree')
  531. def Add_GradientTree_class():
  532. Add_leaner('GradientTree_class')
  533. def Add_TSNE():
  534. Add_leaner('t-SNE')
  535. def Add_NMF():
  536. Add_leaner('NMF')
  537. def Add_LDA():
  538. Add_leaner('LDA')
  539. def Add_KPCA():
  540. Add_leaner('KPCA')
  541. def Add_RPCA():
  542. Add_leaner('RPCA')
  543. def Add_PCA():
  544. Add_leaner('PCA')
  545. def Add_Missed():
  546. Add_leaner('Missed')
  547. def Add_Label():
  548. Add_leaner('Label')
  549. def Add_OneHotEncoder():
  550. Add_leaner('OneHotEncoder')
  551. def Add_Discretization():
  552. Add_leaner('Discretization')
  553. def Add_Binarizer():
  554. Add_leaner('Binarizer')
  555. def Add_Regularization():
  556. Add_leaner('Regularization')
  557. def Add_Fuzzy_quantization():
  558. Add_leaner('Fuzzy_quantization')
  559. def Add_Mapzoom():
  560. Add_leaner('Mapzoom')
  561. def Add_sigmodScaler():
  562. Add_leaner('sigmodScaler')
  563. def Add_decimalScaler():
  564. Add_leaner('decimalScaler')
  565. def Add_atanScaler():
  566. Add_leaner('atanScaler')
  567. def Add_LogScaler():
  568. Add_leaner('LogScaler')
  569. def Add_MinMaxScaler():
  570. Add_leaner('MinMaxScaler')
  571. def Add_Z_Score():
  572. Add_leaner('Z-Score')
  573. def Add_Forest():
  574. Add_leaner('Forest')
  575. def Add_Forest_class():
  576. Add_leaner('Forest_class')
  577. def Add_Tree_Class():
  578. Add_leaner('Tree_class')
  579. def Add_Tree():
  580. Add_leaner('Tree')
  581. def Add_SelectKBest():
  582. Add_leaner('SelectKBest')
  583. def Add_Knn_Class():
  584. Add_leaner('Knn_class')
  585. def Add_LogisticRegression():
  586. Add_leaner('LogisticRegression')
  587. def Add_Lasso():
  588. Add_leaner('Lasso')
  589. def Add_Variance():
  590. Add_leaner('Variance')
  591. def Add_Knn():
  592. Add_leaner('Knn')
  593. def Add_Ridge():
  594. Add_leaner('Ridge')
  595. def Add_Line():
  596. Add_leaner('Line')
  597. def Add_SelectFrom_Model(): # 添加Lenear的核心
  598. ML.Add_SelectFrom_Model(get_Learner(), Text=get_Args_Learner())
  599. Update_Leaner()
  600. def Add_leaner(Type): # 添加Lenear的核心
  601. ML.Add_Learner(Type, Text=get_Args_Learner())
  602. Update_Leaner()
  603. def Update_Leaner():
  604. global Learn_Dic, ML_BOX
  605. Learn_Dic = ML.Return_Learner()
  606. ML_BOX.delete(0, tkinter.END)
  607. ML_BOX.insert(tkinter.END, *Learn_Dic.keys())
  608. def Show_One():
  609. global PATH, to_HTML_Type
  610. Dic = f'{PATH}/$Show_Sheet.html'
  611. try:
  612. name = get_Name()
  613. if name == None: raise Exception
  614. ML.to_Html_One(name, Dic)
  615. webbrowser.open(Dic)
  616. except:
  617. # pass
  618. raise
  619. def Show():
  620. global PATH, to_HTML_Type
  621. Dic = f'{PATH}/$Show_Sheet.html'
  622. try:
  623. name = get_Name()
  624. if name == None: raise Exception
  625. ML.to_Html(name, Dic, to_HTML_Type.get())
  626. webbrowser.open(Dic)
  627. except:
  628. pass
  629. def to_CSV():
  630. global top, Seq_Input, Code_Input, str_must, Index_must
  631. Dic = asksaveasfilename(title='选择保存的CSV', filetypes=[("CSV", ".csv")])
  632. Seq = Seq_Input.get()
  633. name = get_Name()
  634. ML.to_CSV(Dic, name, Seq)
  635. Update_BOX()
  636. def Add_CSV():
  637. global top, Seq_Input, Code_Input, str_must, name_Input
  638. Dic = askopenfilename(title='选择载入的CSV', filetypes=[("CSV", ".csv")])
  639. if Dic == '': return False
  640. Seq = Seq_Input.get()
  641. Codeing = Code_Input.get()
  642. str_ = bool(str_must.get())
  643. name = name_Input.get().replace(' ', '')
  644. if name == '':
  645. name = os.path.splitext(os.path.split(Dic)[1])[0]
  646. print(name)
  647. if Codeing == '':
  648. with open(Dic, 'rb') as f:
  649. Codeing = chardet.detect(f.read())['encoding']
  650. if Seq == '': Seq = ','
  651. ML.read_csv(Dic, name, Codeing, str_, Seq,)
  652. Update_BOX()
  653. def Add_Python():
  654. global top, Seq_Input, Code_Input, str_must, Index_must
  655. Dic = askopenfilename(title='选择载入的py', filetypes=[("Python", ".py"), ("Txt", ".txt")])
  656. name = name_Input.get().replace(' ', '')
  657. if name == '':
  658. name = os.path.splitext(os.path.split(Dic)[1])[0]
  659. with open(Dic, 'r') as f:
  660. ML.Add_Python(f.read(), name)
  661. Update_BOX()
  662. def get_Name(Type=True, x=True): # 获得名字统一接口
  663. global Form_List, Form_BOX, X_OUT
  664. if Type:
  665. try:
  666. return Form_List[Form_BOX.curselection()[0]]
  667. except:
  668. try:
  669. return Form_List[0]
  670. except:
  671. return None
  672. else:
  673. try:
  674. if x:
  675. return X_OUT.get()
  676. else:
  677. return Y_OUT.get()
  678. except:
  679. return None
  680. def Update_BOX():
  681. global top, Form_BOX, Form_List
  682. Form_List = list(ML.get_Form().keys())
  683. Form_BOX.delete(0, tkinter.END)
  684. Form_BOX.insert(tkinter.END, *Form_List)
  685. def Creat_TextSheet(data, name):
  686. global bg
  687. new_top = tkinter.Toplevel(bg=bg)
  688. new_top.title(name)
  689. new_top.geometry('+10+10') # 设置所在位置
  690. text = ScrolledText(new_top, font=('黑体', 13), height=50)
  691. text.pack(fill=tkinter.BOTH)
  692. text.insert('0.0', data)
  693. text.config(state=tkinter.DISABLED)
  694. new_top.resizable(width=False, height=False)
  695. if __name__ == '__main__':
  696. Main()