Machine_learning.py 32 KB

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