Machine_learning.py 42 KB

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