Machine_learning.py 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305
  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. from Machine_learning_analysis import Learn_Numpy
  9. def machine_learning():
  10. global SCREEN, learner_controller, sheet_list, PATH, bg_color, botton_color, word_color
  11. global merge_list, calculation_list, calculation_method, FONT
  12. calculation_list = []
  13. calculation_method = []
  14. PATH = os.getcwd()
  15. sheet_list = []
  16. merge_list = []
  17. learner_controller = Learn_Numpy.MachineLearner()
  18. SCREEN = tkinter.Tk()
  19. bg_color = "#FFFAFA" # 主颜色
  20. botton_color = "#FFFAFA" # 按钮颜色
  21. word_color = "#000000" # 文字颜色
  22. SCREEN["bg"] = bg_color
  23. FONT = ("黑体", 11) # 设置字体
  24. SCREEN.title("CoTan机器学习")
  25. SCREEN.resizable(width=False, height=False)
  26. SCREEN.geometry("+10+10") # 设置所在位置
  27. gui_width = 13 # 标准宽度
  28. gui_height = 2
  29. row = 0
  30. column = 0
  31. tkinter.Button(
  32. SCREEN,
  33. bg=botton_color,
  34. fg=word_color,
  35. text="导入CSV",
  36. command=add_csv,
  37. font=FONT,
  38. width=gui_width,
  39. height=gui_height,
  40. ).grid(
  41. column=column,
  42. row=row,
  43. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  44. )
  45. tkinter.Button(
  46. SCREEN,
  47. bg=botton_color,
  48. fg=word_color,
  49. text="导入Py",
  50. command=add_python,
  51. font=FONT,
  52. width=gui_width,
  53. height=gui_height,
  54. ).grid(
  55. column=column + 1,
  56. row=row,
  57. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  58. )
  59. tkinter.Button(
  60. SCREEN,
  61. bg=botton_color,
  62. fg=word_color,
  63. text="导出CSV",
  64. command=to_csv,
  65. font=FONT,
  66. width=gui_width,
  67. height=gui_height,
  68. ).grid(
  69. column=column + 2,
  70. row=row,
  71. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  72. )
  73. global sheet_name
  74. row += 1
  75. tkinter.Label(
  76. SCREEN,
  77. text="表格名称:",
  78. bg=bg_color,
  79. fg=word_color,
  80. font=FONT,
  81. width=gui_width,
  82. height=gui_height,
  83. ).grid(
  84. column=column, row=row
  85. ) # 设置说明
  86. sheet_name = tkinter.Entry(SCREEN, width=gui_width)
  87. sheet_name.grid(
  88. column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
  89. )
  90. row += 1
  91. tkinter.Button(
  92. SCREEN,
  93. bg=botton_color,
  94. fg=word_color,
  95. text="删除表格",
  96. font=FONT,
  97. width=gui_width,
  98. height=gui_height,
  99. ).grid(
  100. column=column,
  101. row=row,
  102. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  103. )
  104. tkinter.Button(
  105. SCREEN,
  106. bg=botton_color,
  107. fg=word_color,
  108. text="查看表格",
  109. command=to_html,
  110. font=FONT,
  111. width=gui_width,
  112. height=gui_height,
  113. ).grid(
  114. column=column + 1,
  115. row=row,
  116. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  117. )
  118. tkinter.Button(
  119. SCREEN,
  120. bg=botton_color,
  121. fg=word_color,
  122. text="查看单一表格",
  123. command=to_html_one,
  124. font=FONT,
  125. width=gui_width,
  126. height=gui_height,
  127. ).grid(
  128. column=column + 2,
  129. row=row,
  130. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  131. )
  132. global sheet_box, index_box, column_box, to_html_type, sep, encoding, dtype_str
  133. row += 1
  134. to_html_type = tkinter.IntVar() # 正,负,0
  135. lable = ["选项卡型", "可移动型", "自适应型"] # 复选框
  136. for i in range(3):
  137. tkinter.Radiobutton(
  138. SCREEN,
  139. bg=bg_color,
  140. fg=word_color,
  141. activebackground=bg_color,
  142. activeforeground=word_color,
  143. selectcolor=bg_color,
  144. text=lable[i],
  145. variable=to_html_type,
  146. value=i,
  147. ).grid(column=column + i, row=row, sticky=tkinter.W)
  148. dtype_str = tkinter.IntVar()
  149. row += 1
  150. tkinter.Label(
  151. SCREEN,
  152. text="编码方式:",
  153. bg=bg_color,
  154. fg=word_color,
  155. font=FONT,
  156. width=gui_width,
  157. height=gui_height,
  158. ).grid(
  159. column=column, row=row
  160. ) # 设置说明
  161. encoding = tkinter.Entry(SCREEN, width=gui_width)
  162. encoding.grid(column=column + 1, row=row, sticky=tkinter.E + tkinter.W)
  163. buttom = tkinter.Checkbutton(
  164. SCREEN,
  165. bg=bg_color,
  166. fg=word_color,
  167. activebackground=bg_color,
  168. activeforeground=word_color,
  169. selectcolor=bg_color,
  170. text="字符串类型",
  171. variable=dtype_str,
  172. )
  173. buttom.grid(column=column + 2, row=row, sticky=tkinter.W)
  174. row += 1
  175. tkinter.Label(
  176. SCREEN,
  177. text="CSV分隔符:",
  178. bg=bg_color,
  179. fg=word_color,
  180. font=FONT,
  181. width=gui_width,
  182. height=gui_height,
  183. ).grid(
  184. column=column, row=row
  185. ) # 设置说明
  186. sep = tkinter.Entry(SCREEN, width=gui_width)
  187. sep.grid(column=column + 1, columnspan=2, row=row, sticky=tkinter.E + tkinter.W)
  188. row += 1
  189. sheet_box = tkinter.Listbox(
  190. SCREEN, width=gui_width * 3, height=gui_height * 10
  191. ) # 显示符号
  192. sheet_box.grid(
  193. column=column,
  194. row=row,
  195. columnspan=3,
  196. rowspan=10,
  197. sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N,
  198. )
  199. # 422
  200. row += 10
  201. tkinter.Button(
  202. SCREEN,
  203. bg=botton_color,
  204. fg=word_color,
  205. text="添加数据",
  206. command=merge_add,
  207. font=FONT,
  208. width=gui_width,
  209. height=gui_height,
  210. ).grid(
  211. column=column,
  212. row=row,
  213. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  214. )
  215. tkinter.Button(
  216. SCREEN,
  217. bg=botton_color,
  218. fg=word_color,
  219. text="删除数据",
  220. command=merge_del,
  221. font=FONT,
  222. width=gui_width,
  223. height=gui_height,
  224. ).grid(
  225. column=column + 1,
  226. row=row,
  227. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  228. )
  229. tkinter.Button(
  230. SCREEN,
  231. bg=botton_color,
  232. fg=word_color,
  233. text="组合数据",
  234. command=merge,
  235. font=FONT,
  236. width=gui_width,
  237. height=gui_height,
  238. ).grid(
  239. column=column + 2,
  240. row=row,
  241. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  242. )
  243. global processing_type, shape, merge_box
  244. row += 1
  245. merge_box = tkinter.Listbox(
  246. SCREEN, width=gui_width * 3, height=gui_height * 3
  247. ) # 显示符号
  248. merge_box.grid(
  249. column=column,
  250. row=row,
  251. columnspan=3,
  252. rowspan=3,
  253. sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N,
  254. )
  255. row += 3
  256. processing_type = tkinter.IntVar() # 正,负,0
  257. lable = ["横向处理", "纵向处理", "深度处理"] # 复选框
  258. for i in range(3):
  259. tkinter.Radiobutton(
  260. SCREEN,
  261. bg=bg_color,
  262. fg=word_color,
  263. activebackground=bg_color,
  264. activeforeground=word_color,
  265. selectcolor=bg_color,
  266. text=lable[i],
  267. variable=processing_type,
  268. value=i,
  269. ).grid(column=column + i, row=row, sticky=tkinter.W)
  270. row += 1
  271. tkinter.Button(
  272. SCREEN,
  273. bg=botton_color,
  274. fg=word_color,
  275. text="数据切片",
  276. command=two_split,
  277. font=FONT,
  278. width=gui_width,
  279. height=gui_height,
  280. ).grid(
  281. column=column,
  282. row=row,
  283. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  284. )
  285. tkinter.Button(
  286. SCREEN,
  287. bg=botton_color,
  288. fg=word_color,
  289. text="数据分割",
  290. command=split,
  291. font=FONT,
  292. width=gui_width,
  293. height=gui_height,
  294. ).grid(
  295. column=column + 1,
  296. row=row,
  297. columnspan=2,
  298. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  299. )
  300. row += 1
  301. tkinter.Label(
  302. SCREEN,
  303. text="重塑形状:",
  304. bg=bg_color,
  305. fg=word_color,
  306. font=FONT,
  307. width=gui_width,
  308. height=gui_height,
  309. ).grid(column=column, row=row)
  310. shape = tkinter.Entry(SCREEN, width=gui_width)
  311. shape.grid(column=column + 1, row=row, sticky=tkinter.E + tkinter.W)
  312. tkinter.Button(
  313. SCREEN,
  314. bg=botton_color,
  315. fg=word_color,
  316. text="矩阵重塑",
  317. command=reshape,
  318. font=FONT,
  319. width=gui_width,
  320. height=gui_height,
  321. ).grid(
  322. column=column + 2,
  323. row=row,
  324. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  325. )
  326. row += 1
  327. tkinter.Button(
  328. SCREEN,
  329. bg=botton_color,
  330. fg=word_color,
  331. text="矩阵伸展",
  332. command=reval,
  333. font=FONT,
  334. width=gui_width,
  335. height=gui_height,
  336. ).grid(
  337. column=column,
  338. row=row,
  339. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  340. )
  341. tkinter.Button(
  342. SCREEN,
  343. bg=botton_color,
  344. fg=word_color,
  345. text="矩阵降维",
  346. command=del_ndim,
  347. font=FONT,
  348. width=gui_width,
  349. height=gui_height,
  350. ).grid(
  351. column=column + 1,
  352. row=row,
  353. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  354. )
  355. tkinter.Button(
  356. SCREEN,
  357. bg=botton_color,
  358. fg=word_color,
  359. text="矩阵转置",
  360. command=transpose,
  361. font=FONT,
  362. width=gui_width,
  363. height=gui_height,
  364. ).grid(
  365. column=column + 2,
  366. row=row,
  367. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  368. )
  369. column += 3
  370. tkinter.Label(SCREEN, text="", bg=bg_color, fg=word_color, font=FONT, width=1).grid(
  371. column=column, row=row
  372. ) # 设置说明
  373. column += 1
  374. row = 0
  375. tkinter.Label(
  376. SCREEN,
  377. text="【机器学习】",
  378. bg=bg_color,
  379. fg=word_color,
  380. font=FONT,
  381. width=gui_width * 3,
  382. height=gui_height,
  383. ).grid(
  384. column=column,
  385. columnspan=3,
  386. row=row,
  387. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  388. ) # 设置说明
  389. global learner_box, learner_output, x_data, y_data
  390. row += 1
  391. x_data = tkinter.StringVar()
  392. put = tkinter.Entry(SCREEN, width=gui_width * 2, textvariable=x_data)
  393. put.grid(column=column, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  394. put["state"] = "readonly"
  395. tkinter.Button(
  396. SCREEN,
  397. bg=botton_color,
  398. fg=word_color,
  399. text="选用X集",
  400. command=set_x_data,
  401. font=FONT,
  402. width=gui_width,
  403. height=gui_height,
  404. ).grid(column=column + 2, row=row, sticky=tkinter.E + tkinter.W)
  405. y_data = tkinter.StringVar()
  406. row += 1
  407. put = tkinter.Entry(SCREEN, width=gui_width * 2, textvariable=y_data)
  408. put.grid(column=column, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  409. put["state"] = "readonly"
  410. tkinter.Button(
  411. SCREEN,
  412. bg=botton_color,
  413. fg=word_color,
  414. text="选用Y集",
  415. command=set_y_data,
  416. font=FONT,
  417. width=gui_width,
  418. height=gui_height,
  419. ).grid(column=column + 2, row=row, sticky=tkinter.E + tkinter.W)
  420. learner_output = tkinter.StringVar()
  421. row += 1
  422. put = tkinter.Entry(SCREEN, width=gui_width * 2, textvariable=learner_output)
  423. put.grid(column=column, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  424. put["state"] = "readonly"
  425. tkinter.Button(
  426. SCREEN,
  427. bg=botton_color,
  428. fg=word_color,
  429. text="选用学习器",
  430. command=set_learner,
  431. font=FONT,
  432. width=gui_width,
  433. height=gui_height,
  434. ).grid(column=column + 2, row=row, sticky=tkinter.E + tkinter.W)
  435. global data_split
  436. row += 1
  437. tkinter.Label(
  438. SCREEN,
  439. text="测试数据分割:",
  440. bg=bg_color,
  441. fg=word_color,
  442. font=FONT,
  443. width=gui_width,
  444. height=gui_height,
  445. ).grid(column=column, row=row)
  446. data_split = tkinter.Entry(SCREEN, width=gui_width * 2)
  447. data_split.grid(
  448. column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
  449. )
  450. row += 1
  451. learner_box = tkinter.Listbox(SCREEN, width=gui_width * 3, height=gui_height * 5)
  452. learner_box.grid(
  453. column=column,
  454. row=row,
  455. columnspan=3,
  456. rowspan=5,
  457. sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N,
  458. )
  459. row += 5
  460. tkinter.Button(
  461. SCREEN,
  462. bg=botton_color,
  463. fg=word_color,
  464. text="导入学习器",
  465. font=FONT,
  466. width=gui_width,
  467. height=gui_height,
  468. ).grid(
  469. column=column,
  470. row=row,
  471. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  472. )
  473. tkinter.Button(
  474. SCREEN,
  475. bg=botton_color,
  476. fg=word_color,
  477. text="查看数据",
  478. command=visualization_results,
  479. font=FONT,
  480. width=gui_width,
  481. height=gui_height,
  482. ).grid(
  483. column=column + 1,
  484. row=row,
  485. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  486. )
  487. tkinter.Button(
  488. SCREEN,
  489. bg=botton_color,
  490. fg=word_color,
  491. text="删除学习器",
  492. command=del_leaner,
  493. font=FONT,
  494. width=gui_width,
  495. height=gui_height,
  496. ).grid(
  497. column=column + 2,
  498. row=row,
  499. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  500. )
  501. row += 1
  502. tkinter.Button(
  503. SCREEN,
  504. bg=botton_color,
  505. fg=word_color,
  506. text="训练机器",
  507. command=fit_learner,
  508. font=FONT,
  509. width=gui_width,
  510. height=gui_height,
  511. ).grid(
  512. column=column,
  513. row=row,
  514. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  515. )
  516. tkinter.Button(
  517. SCREEN,
  518. bg=botton_color,
  519. fg=word_color,
  520. text="测试机器",
  521. command=score_learner,
  522. font=FONT,
  523. width=gui_width,
  524. height=gui_height,
  525. ).grid(
  526. column=column + 1,
  527. row=row,
  528. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  529. )
  530. tkinter.Button(
  531. SCREEN,
  532. bg=botton_color,
  533. fg=word_color,
  534. text="数据预测",
  535. command=predict_learner,
  536. font=FONT,
  537. width=gui_width,
  538. height=gui_height,
  539. ).grid(
  540. column=column + 2,
  541. row=row,
  542. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  543. )
  544. row += 1
  545. tkinter.Button(
  546. SCREEN,
  547. bg=botton_color,
  548. fg=word_color,
  549. text="单一变量特征选择",
  550. command=add_select_k_best,
  551. font=FONT,
  552. width=gui_width,
  553. height=gui_height,
  554. ).grid(
  555. column=column,
  556. row=row,
  557. columnspan=2,
  558. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  559. )
  560. tkinter.Button(
  561. SCREEN,
  562. bg=botton_color,
  563. fg=word_color,
  564. text="映射标准化",
  565. command=add_mapzoom,
  566. font=FONT,
  567. width=gui_width,
  568. height=gui_height,
  569. ).grid(
  570. column=column + 2,
  571. row=row,
  572. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  573. )
  574. row += 1
  575. tkinter.Button(
  576. SCREEN,
  577. bg=botton_color,
  578. fg=word_color,
  579. text="方差特征选择",
  580. command=add_variance,
  581. font=FONT,
  582. width=gui_width,
  583. height=gui_height,
  584. ).grid(
  585. column=column,
  586. row=row,
  587. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  588. )
  589. tkinter.Button(
  590. SCREEN,
  591. bg=botton_color,
  592. fg=word_color,
  593. text="使用学习器筛选",
  594. command=add_select_from_model,
  595. font=FONT,
  596. width=gui_width,
  597. height=gui_height,
  598. ).grid(
  599. column=column + 1,
  600. row=row,
  601. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  602. )
  603. tkinter.Button(
  604. SCREEN,
  605. bg=botton_color,
  606. fg=word_color,
  607. text="模糊量化标准化",
  608. command=add_fuzzy_quantization,
  609. font=FONT,
  610. width=gui_width,
  611. height=gui_height,
  612. ).grid(
  613. column=column + 2,
  614. row=row,
  615. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  616. )
  617. row += 1
  618. tkinter.Button(
  619. SCREEN,
  620. bg=botton_color,
  621. fg=word_color,
  622. text="Z-score",
  623. command=add_z_score,
  624. font=FONT,
  625. width=gui_width,
  626. height=gui_height,
  627. ).grid(
  628. column=column,
  629. row=row,
  630. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  631. )
  632. tkinter.Button(
  633. SCREEN,
  634. bg=botton_color,
  635. fg=word_color,
  636. text="离差标准化",
  637. command=add_min_max_scaler,
  638. font=FONT,
  639. width=gui_width,
  640. height=gui_height,
  641. ).grid(
  642. column=column + 1,
  643. row=row,
  644. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  645. )
  646. tkinter.Button(
  647. SCREEN,
  648. bg=botton_color,
  649. fg=word_color,
  650. text="Log变换",
  651. command=add_log_scaler,
  652. font=FONT,
  653. width=gui_width,
  654. height=gui_height,
  655. ).grid(
  656. column=column + 2,
  657. row=row,
  658. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  659. )
  660. row += 1
  661. tkinter.Button(
  662. SCREEN,
  663. bg=botton_color,
  664. fg=word_color,
  665. text="atan变换",
  666. command=add_atan_scaler,
  667. font=FONT,
  668. width=gui_width,
  669. height=gui_height,
  670. ).grid(
  671. column=column,
  672. row=row,
  673. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  674. )
  675. tkinter.Button(
  676. SCREEN,
  677. bg=botton_color,
  678. fg=word_color,
  679. text="小数定标准化",
  680. command=add_decimal_scaler,
  681. font=FONT,
  682. width=gui_width,
  683. height=gui_height,
  684. ).grid(
  685. column=column + 1,
  686. row=row,
  687. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  688. )
  689. tkinter.Button(
  690. SCREEN,
  691. bg=botton_color,
  692. fg=word_color,
  693. text="Sigmod变换",
  694. command=add_sigmod_scaler,
  695. font=FONT,
  696. width=gui_width,
  697. height=gui_height,
  698. ).grid(
  699. column=column + 2,
  700. row=row,
  701. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  702. )
  703. row += 1
  704. tkinter.Button(
  705. SCREEN,
  706. bg=botton_color,
  707. fg=word_color,
  708. text="正则化",
  709. command=add_regularization,
  710. font=FONT,
  711. width=gui_width,
  712. height=gui_height,
  713. ).grid(
  714. column=column,
  715. row=row,
  716. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  717. )
  718. tkinter.Button(
  719. SCREEN,
  720. bg=botton_color,
  721. fg=word_color,
  722. text="二值离散",
  723. command=add_binarizer,
  724. font=FONT,
  725. width=gui_width,
  726. height=gui_height,
  727. ).grid(
  728. column=column + 1,
  729. row=row,
  730. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  731. )
  732. tkinter.Button(
  733. SCREEN,
  734. bg=botton_color,
  735. fg=word_color,
  736. text="多值离散",
  737. command=add_discretization,
  738. font=FONT,
  739. width=gui_width,
  740. height=gui_height,
  741. ).grid(
  742. column=column + 2,
  743. row=row,
  744. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  745. )
  746. row += 1
  747. tkinter.Button(
  748. SCREEN,
  749. bg=botton_color,
  750. fg=word_color,
  751. text="独热编码",
  752. command=add_one_hot_encoder,
  753. font=FONT,
  754. width=gui_width,
  755. height=gui_height,
  756. ).grid(
  757. column=column,
  758. row=row,
  759. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  760. )
  761. tkinter.Button(
  762. SCREEN,
  763. bg=botton_color,
  764. fg=word_color,
  765. text="数字编码",
  766. command=add_label,
  767. font=FONT,
  768. width=gui_width,
  769. height=gui_height,
  770. ).grid(
  771. column=column + 1,
  772. row=row,
  773. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  774. )
  775. tkinter.Button(
  776. SCREEN,
  777. bg=botton_color,
  778. fg=word_color,
  779. text="缺失填充",
  780. command=add_missed,
  781. font=FONT,
  782. width=gui_width,
  783. height=gui_height,
  784. ).grid(
  785. column=column + 2,
  786. row=row,
  787. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  788. )
  789. row += 1
  790. tkinter.Button(
  791. SCREEN,
  792. bg=botton_color,
  793. fg=word_color,
  794. text="PCA降维",
  795. command=add_pca,
  796. font=FONT,
  797. width=gui_width,
  798. height=gui_height,
  799. ).grid(
  800. column=column,
  801. row=row,
  802. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  803. )
  804. tkinter.Button(
  805. SCREEN,
  806. bg=botton_color,
  807. fg=word_color,
  808. text="RPCA降维",
  809. command=add_rpca,
  810. font=FONT,
  811. width=gui_width,
  812. height=gui_height,
  813. ).grid(
  814. column=column + 1,
  815. row=row,
  816. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  817. )
  818. tkinter.Button(
  819. SCREEN,
  820. bg=botton_color,
  821. fg=word_color,
  822. text="KPCA升维",
  823. command=add_kpca,
  824. font=FONT,
  825. width=gui_width,
  826. height=gui_height,
  827. ).grid(
  828. column=column + 2,
  829. row=row,
  830. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  831. )
  832. row += 1
  833. tkinter.Button(
  834. SCREEN,
  835. bg=botton_color,
  836. fg=word_color,
  837. text="LDA降维",
  838. command=add_lda,
  839. font=FONT,
  840. width=gui_width,
  841. height=gui_height,
  842. ).grid(
  843. column=column,
  844. row=row,
  845. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  846. )
  847. tkinter.Button(
  848. SCREEN,
  849. bg=botton_color,
  850. fg=word_color,
  851. text="NMF降维",
  852. command=add_nmf,
  853. font=FONT,
  854. width=gui_width,
  855. height=gui_height,
  856. ).grid(
  857. column=column + 1,
  858. row=row,
  859. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  860. )
  861. tkinter.Button(
  862. SCREEN,
  863. bg=botton_color,
  864. fg=word_color,
  865. text="t-SNE",
  866. command=add_tsne,
  867. font=FONT,
  868. width=gui_width,
  869. height=gui_height,
  870. ).grid(
  871. column=column + 2,
  872. row=row,
  873. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  874. )
  875. row += 1
  876. tkinter.Button(
  877. SCREEN,
  878. bg=botton_color,
  879. fg=word_color,
  880. text="线性回归",
  881. command=add_line,
  882. font=FONT,
  883. width=gui_width,
  884. height=gui_height,
  885. ).grid(
  886. column=column,
  887. row=row,
  888. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  889. )
  890. tkinter.Button(
  891. SCREEN,
  892. bg=botton_color,
  893. fg=word_color,
  894. text="岭回归",
  895. command=add_ridge,
  896. font=FONT,
  897. width=gui_width,
  898. height=gui_height,
  899. ).grid(
  900. column=column + 1,
  901. row=row,
  902. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  903. )
  904. tkinter.Button(
  905. SCREEN,
  906. bg=botton_color,
  907. fg=word_color,
  908. text="Lasso",
  909. command=add_lasso,
  910. font=FONT,
  911. width=gui_width,
  912. height=gui_height,
  913. ).grid(
  914. column=column + 2,
  915. row=row,
  916. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  917. )
  918. row += 1
  919. tkinter.Button(
  920. SCREEN,
  921. bg=botton_color,
  922. fg=word_color,
  923. text="逻辑回归",
  924. command=add_logistic_regression,
  925. font=FONT,
  926. width=gui_width,
  927. height=gui_height,
  928. ).grid(
  929. column=column,
  930. row=row,
  931. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  932. )
  933. tkinter.Button(
  934. SCREEN,
  935. bg=botton_color,
  936. fg=word_color,
  937. text="K邻近预测",
  938. command=add_knn,
  939. font=FONT,
  940. width=gui_width,
  941. height=gui_height,
  942. ).grid(
  943. column=column + 1,
  944. row=row,
  945. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  946. )
  947. tkinter.Button(
  948. SCREEN,
  949. bg=botton_color,
  950. fg=word_color,
  951. text="K邻近分类",
  952. command=add_knn_class,
  953. font=FONT,
  954. width=gui_width,
  955. height=gui_height,
  956. ).grid(
  957. column=column + 2,
  958. row=row,
  959. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  960. )
  961. row += 1
  962. tkinter.Button(
  963. SCREEN,
  964. bg=botton_color,
  965. fg=word_color,
  966. text="梯度回归树回归",
  967. command=add_gradient_tree,
  968. font=FONT,
  969. width=gui_width,
  970. height=gui_height,
  971. ).grid(
  972. column=column,
  973. row=row,
  974. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  975. )
  976. tkinter.Button(
  977. SCREEN,
  978. bg=botton_color,
  979. fg=word_color,
  980. text="决策树回归",
  981. command=add_tree,
  982. font=FONT,
  983. width=gui_width,
  984. height=gui_height,
  985. ).grid(
  986. column=column + 1,
  987. row=row,
  988. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  989. )
  990. tkinter.Button(
  991. SCREEN,
  992. bg=botton_color,
  993. fg=word_color,
  994. text="决策树分类",
  995. command=add_tree_class,
  996. font=FONT,
  997. width=gui_width,
  998. height=gui_height,
  999. ).grid(
  1000. column=column + 2,
  1001. row=row,
  1002. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1003. )
  1004. row += 1
  1005. tkinter.Button(
  1006. SCREEN,
  1007. bg=botton_color,
  1008. fg=word_color,
  1009. text="梯度回归树分类",
  1010. command=add_gradient_tree_class,
  1011. font=FONT,
  1012. width=gui_width,
  1013. height=gui_height,
  1014. ).grid(
  1015. column=column,
  1016. row=row,
  1017. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1018. )
  1019. tkinter.Button(
  1020. SCREEN,
  1021. bg=botton_color,
  1022. fg=word_color,
  1023. text="随机森林回归",
  1024. command=add_forest,
  1025. font=FONT,
  1026. width=gui_width,
  1027. height=gui_height,
  1028. ).grid(
  1029. column=column + 1,
  1030. row=row,
  1031. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1032. )
  1033. tkinter.Button(
  1034. SCREEN,
  1035. bg=botton_color,
  1036. fg=word_color,
  1037. text="随机森林分类",
  1038. command=add_forest_class,
  1039. font=FONT,
  1040. width=gui_width,
  1041. height=gui_height,
  1042. ).grid(
  1043. column=column + 2,
  1044. row=row,
  1045. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1046. )
  1047. column += 3
  1048. tkinter.Label(SCREEN, text="", bg=bg_color, fg=word_color, font=FONT, width=1).grid(
  1049. column=column, row=row
  1050. ) # 设置说明
  1051. column += 1
  1052. row = 0
  1053. tkinter.Button(
  1054. SCREEN,
  1055. bg=botton_color,
  1056. fg=word_color,
  1057. text="多层感知机回归",
  1058. command=add_mlp,
  1059. font=FONT,
  1060. width=gui_width,
  1061. height=gui_height,
  1062. ).grid(
  1063. column=column,
  1064. row=row,
  1065. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1066. )
  1067. tkinter.Button(
  1068. SCREEN,
  1069. bg=botton_color,
  1070. fg=word_color,
  1071. text="多层感知机分类",
  1072. command=add_mlp_class,
  1073. font=FONT,
  1074. width=gui_width,
  1075. height=gui_height,
  1076. ).grid(
  1077. column=column + 1,
  1078. row=row,
  1079. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1080. )
  1081. tkinter.Button(
  1082. SCREEN,
  1083. bg=botton_color,
  1084. fg=word_color,
  1085. text="随机森林分类",
  1086. command=add_forest_class,
  1087. font=FONT,
  1088. width=gui_width,
  1089. height=gui_height,
  1090. ).grid(
  1091. column=column + 2,
  1092. row=row,
  1093. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1094. )
  1095. row += 1
  1096. tkinter.Button(
  1097. SCREEN,
  1098. bg=botton_color,
  1099. fg=word_color,
  1100. text="支持向量机分类:SVC",
  1101. command=add_svc,
  1102. font=FONT,
  1103. width=gui_width,
  1104. height=gui_height,
  1105. ).grid(
  1106. column=column,
  1107. row=row,
  1108. columnspan=2,
  1109. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1110. )
  1111. tkinter.Button(
  1112. SCREEN,
  1113. bg=botton_color,
  1114. fg=word_color,
  1115. text="回归:SVR",
  1116. command=add_svr,
  1117. font=FONT,
  1118. width=gui_width,
  1119. height=gui_height,
  1120. ).grid(
  1121. column=column + 2,
  1122. row=row,
  1123. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1124. )
  1125. row += 1
  1126. tkinter.Button(
  1127. SCREEN,
  1128. bg=botton_color,
  1129. fg=word_color,
  1130. text="k-means",
  1131. command=add_k_means,
  1132. font=FONT,
  1133. width=gui_width,
  1134. height=gui_height,
  1135. ).grid(
  1136. column=column,
  1137. row=row,
  1138. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1139. )
  1140. tkinter.Button(
  1141. SCREEN,
  1142. bg=botton_color,
  1143. fg=word_color,
  1144. text="凝聚聚类",
  1145. command=add_agglomerative,
  1146. font=FONT,
  1147. width=gui_width,
  1148. height=gui_height,
  1149. ).grid(
  1150. column=column + 1,
  1151. row=row,
  1152. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1153. )
  1154. tkinter.Button(
  1155. SCREEN,
  1156. bg=botton_color,
  1157. fg=word_color,
  1158. text="DBSCAN",
  1159. command=add_dbscan,
  1160. font=FONT,
  1161. width=gui_width,
  1162. height=gui_height,
  1163. ).grid(
  1164. column=column + 2,
  1165. row=row,
  1166. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1167. )
  1168. row += 1
  1169. tkinter.Button(
  1170. SCREEN,
  1171. bg=botton_color,
  1172. fg=word_color,
  1173. text="特征分类图",
  1174. command=add_class_bar,
  1175. font=FONT,
  1176. width=gui_width,
  1177. height=gui_height,
  1178. ).grid(
  1179. column=column,
  1180. row=row,
  1181. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1182. )
  1183. tkinter.Button(
  1184. SCREEN,
  1185. bg=botton_color,
  1186. fg=word_color,
  1187. text="临近特征回归图",
  1188. command=add_feature_scatter,
  1189. font=FONT,
  1190. width=gui_width,
  1191. height=gui_height,
  1192. ).grid(
  1193. column=column + 1,
  1194. row=row,
  1195. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1196. )
  1197. tkinter.Button(
  1198. SCREEN,
  1199. bg=botton_color,
  1200. fg=word_color,
  1201. text="临近特征分类图",
  1202. command=add_feature_scatter_class,
  1203. font=FONT,
  1204. width=gui_width,
  1205. height=gui_height,
  1206. ).grid(
  1207. column=column + 2,
  1208. row=row,
  1209. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1210. )
  1211. row += 1
  1212. tkinter.Button(
  1213. SCREEN,
  1214. bg=botton_color,
  1215. fg=word_color,
  1216. text="所有特征回归图",
  1217. command=add_feature_scatter_all,
  1218. font=FONT,
  1219. width=gui_width,
  1220. height=gui_height,
  1221. ).grid(
  1222. column=column,
  1223. row=row,
  1224. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1225. )
  1226. tkinter.Button(
  1227. SCREEN,
  1228. bg=botton_color,
  1229. fg=word_color,
  1230. text="所有特征分类图",
  1231. command=add_feature_scatter_class_all,
  1232. font=FONT,
  1233. width=gui_width,
  1234. height=gui_height,
  1235. ).grid(
  1236. column=column + 1,
  1237. row=row,
  1238. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1239. )
  1240. tkinter.Button(
  1241. SCREEN,
  1242. bg=botton_color,
  1243. fg=word_color,
  1244. text="临近特征预测图",
  1245. command=add_predictive_heatmap,
  1246. font=FONT,
  1247. width=gui_width,
  1248. height=gui_height,
  1249. ).grid(
  1250. column=column + 2,
  1251. row=row,
  1252. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1253. )
  1254. row += 1
  1255. tkinter.Button(
  1256. SCREEN,
  1257. bg=botton_color,
  1258. fg=word_color,
  1259. text="所有特征预测图",
  1260. command=add_predictive_heatmap_more,
  1261. font=FONT,
  1262. width=gui_width,
  1263. height=gui_height,
  1264. ).grid(
  1265. column=column,
  1266. row=row,
  1267. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1268. )
  1269. tkinter.Button(
  1270. SCREEN,
  1271. bg=botton_color,
  1272. fg=word_color,
  1273. text="矩阵热力图",
  1274. command=add_numpy_to_heatmap,
  1275. font=FONT,
  1276. width=gui_width,
  1277. height=gui_height,
  1278. ).grid(
  1279. column=column + 1,
  1280. row=row,
  1281. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1282. )
  1283. tkinter.Button(
  1284. SCREEN,
  1285. bg=botton_color,
  1286. fg=word_color,
  1287. text="数据y-x散点图",
  1288. command=add_feature_y_x,
  1289. font=FONT,
  1290. width=gui_width,
  1291. height=gui_height,
  1292. ).grid(
  1293. column=column + 2,
  1294. row=row,
  1295. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1296. )
  1297. row += 1
  1298. tkinter.Button(
  1299. SCREEN,
  1300. bg=botton_color,
  1301. fg=word_color,
  1302. text="聚类树状图",
  1303. command=add_cluster_tree,
  1304. font=FONT,
  1305. width=gui_width,
  1306. height=gui_height,
  1307. ).grid(
  1308. column=column,
  1309. row=row,
  1310. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1311. )
  1312. tkinter.Button(
  1313. SCREEN,
  1314. bg=botton_color,
  1315. fg=word_color,
  1316. text="获取数据",
  1317. command=add_view_data,
  1318. font=FONT,
  1319. width=gui_width,
  1320. height=gui_height,
  1321. ).grid(
  1322. column=column + 1,
  1323. row=row,
  1324. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1325. )
  1326. tkinter.Button(
  1327. SCREEN,
  1328. bg=botton_color,
  1329. fg=word_color,
  1330. text="矩阵散点图",
  1331. command=add_matrix_scatter,
  1332. font=FONT,
  1333. width=gui_width,
  1334. height=gui_height,
  1335. ).grid(
  1336. column=column + 2,
  1337. row=row,
  1338. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1339. )
  1340. row += 1
  1341. tkinter.Button(
  1342. SCREEN,
  1343. bg=botton_color,
  1344. fg=word_color,
  1345. text="特征相关性",
  1346. command=add_correlation,
  1347. font=FONT,
  1348. width=gui_width,
  1349. height=gui_height,
  1350. ).grid(
  1351. column=column,
  1352. row=row,
  1353. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1354. )
  1355. tkinter.Button(
  1356. SCREEN,
  1357. bg=botton_color,
  1358. fg=word_color,
  1359. text="曲线拟合",
  1360. command=curve_fitting,
  1361. font=FONT,
  1362. width=gui_width,
  1363. height=gui_height,
  1364. ).grid(
  1365. column=column + 1,
  1366. row=row,
  1367. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1368. )
  1369. tkinter.Button(
  1370. SCREEN,
  1371. bg=botton_color,
  1372. fg=word_color,
  1373. text="快速傅里叶",
  1374. command=add_fast_fourier,
  1375. font=FONT,
  1376. width=gui_width,
  1377. height=gui_height,
  1378. ).grid(
  1379. column=column + 2,
  1380. row=row,
  1381. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1382. )
  1383. row += 1
  1384. tkinter.Button(
  1385. SCREEN,
  1386. bg=botton_color,
  1387. fg=word_color,
  1388. text="数据统计",
  1389. command=add_statistics,
  1390. font=FONT,
  1391. width=gui_width,
  1392. height=gui_height,
  1393. ).grid(
  1394. column=column,
  1395. row=row,
  1396. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1397. )
  1398. tkinter.Button(
  1399. SCREEN,
  1400. bg=botton_color,
  1401. fg=word_color,
  1402. text="双逆向傅里叶",
  1403. command=add_reverse_fast_fourier2,
  1404. font=FONT,
  1405. width=gui_width,
  1406. height=gui_height,
  1407. ).grid(
  1408. column=column + 1,
  1409. row=row,
  1410. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1411. )
  1412. tkinter.Button(
  1413. SCREEN,
  1414. bg=botton_color,
  1415. fg=word_color,
  1416. text="逆向傅里叶",
  1417. command=add_reverse_fast_fourier,
  1418. font=FONT,
  1419. width=gui_width,
  1420. height=gui_height,
  1421. ).grid(
  1422. column=column + 2,
  1423. row=row,
  1424. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1425. )
  1426. row += 1
  1427. tkinter.Button(
  1428. SCREEN,
  1429. bg=botton_color,
  1430. fg=word_color,
  1431. text="分类模型评估",
  1432. command=show_class_score,
  1433. font=FONT,
  1434. width=gui_width,
  1435. height=gui_height,
  1436. ).grid(
  1437. column=column,
  1438. row=row,
  1439. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1440. )
  1441. tkinter.Button(
  1442. SCREEN,
  1443. bg=botton_color,
  1444. fg=word_color,
  1445. text="回归模型评估",
  1446. command=show_regression_score,
  1447. font=FONT,
  1448. width=gui_width,
  1449. height=gui_height,
  1450. ).grid(
  1451. column=column + 1,
  1452. row=row,
  1453. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1454. )
  1455. tkinter.Button(
  1456. SCREEN,
  1457. bg=botton_color,
  1458. fg=word_color,
  1459. text="聚类模型评估",
  1460. command=show_clustering_score,
  1461. font=FONT,
  1462. width=gui_width,
  1463. height=gui_height,
  1464. ).grid(
  1465. column=column + 2,
  1466. row=row,
  1467. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1468. )
  1469. row += 1
  1470. tkinter.Label(
  1471. SCREEN,
  1472. text="【学习器配置】",
  1473. bg=bg_color,
  1474. fg=word_color,
  1475. font=FONT,
  1476. width=gui_width * 3,
  1477. height=gui_height,
  1478. ).grid(
  1479. column=column,
  1480. columnspan=3,
  1481. row=row,
  1482. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1483. ) # 设置说明
  1484. global global_settings
  1485. row += 1
  1486. global_settings = []
  1487. lable = ["聚类仅邻近特征", "导出单独页面", "导出表格CSV"] # 复选框
  1488. for i in range(3):
  1489. global_settings.append(tkinter.IntVar())
  1490. tkinter.Checkbutton(
  1491. SCREEN,
  1492. bg=bg_color,
  1493. fg=word_color,
  1494. activebackground=bg_color,
  1495. activeforeground=word_color,
  1496. selectcolor=bg_color,
  1497. text=lable[i],
  1498. variable=global_settings[-1],
  1499. command=global_seeting,
  1500. ).grid(column=column + i, row=row, sticky=tkinter.W)
  1501. row += 1
  1502. lable = ["导出模型", "压缩为tar.gz", "创建新目录"] # 复选框
  1503. for i in range(3):
  1504. global_settings.append(tkinter.IntVar())
  1505. tkinter.Checkbutton(
  1506. SCREEN,
  1507. bg=bg_color,
  1508. fg=word_color,
  1509. activebackground=bg_color,
  1510. activeforeground=word_color,
  1511. selectcolor=bg_color,
  1512. text=lable[i],
  1513. variable=global_settings[-1],
  1514. command=global_seeting,
  1515. ).grid(column=column + i, row=row, sticky=tkinter.W)
  1516. for i in global_settings[1:]:
  1517. i.set(1)
  1518. global_seeting()
  1519. global learner_parameters
  1520. row += 1
  1521. learner_parameters = tkinter.Text(
  1522. SCREEN, width=gui_width * 3, height=gui_height * 6
  1523. )
  1524. learner_parameters.grid(
  1525. column=column,
  1526. row=row,
  1527. columnspan=3,
  1528. rowspan=6,
  1529. sticky=tkinter.E + tkinter.W + tkinter.N + tkinter.S,
  1530. )
  1531. row += 6
  1532. tkinter.Label(
  1533. SCREEN,
  1534. text="【矩阵运算】",
  1535. bg=bg_color,
  1536. fg=word_color,
  1537. font=FONT,
  1538. width=gui_width * 3,
  1539. height=gui_height,
  1540. ).grid(
  1541. column=column,
  1542. columnspan=3,
  1543. row=row,
  1544. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1545. ) # 设置说明
  1546. global calculation_box, calculation_type, value
  1547. row += 1
  1548. calculation_box = tkinter.Listbox(
  1549. SCREEN, width=gui_width * 3, height=gui_height * 1
  1550. )
  1551. calculation_box.grid(
  1552. column=column,
  1553. row=row,
  1554. columnspan=3,
  1555. rowspan=1,
  1556. sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N,
  1557. )
  1558. row += 1
  1559. tkinter.Label(
  1560. SCREEN,
  1561. text="运算类型:",
  1562. bg=bg_color,
  1563. fg=word_color,
  1564. font=FONT,
  1565. width=gui_width,
  1566. height=gui_height,
  1567. ).grid(column=column, row=row)
  1568. calculation_type = tkinter.Entry(SCREEN, width=gui_width * 2)
  1569. calculation_type.grid(
  1570. column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
  1571. )
  1572. row += 1
  1573. tkinter.Label(
  1574. SCREEN,
  1575. text="键入参数:",
  1576. bg=bg_color,
  1577. fg=word_color,
  1578. font=FONT,
  1579. width=gui_width,
  1580. height=gui_height,
  1581. ).grid(column=column, row=row)
  1582. value = tkinter.Entry(SCREEN, width=gui_width * 2)
  1583. value.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  1584. row += 1
  1585. tkinter.Button(
  1586. SCREEN,
  1587. bg=botton_color,
  1588. fg=word_color,
  1589. text="选择参数",
  1590. command=add_calculation_object,
  1591. font=FONT,
  1592. width=gui_width,
  1593. height=gui_height,
  1594. ).grid(
  1595. column=column,
  1596. row=row,
  1597. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1598. )
  1599. tkinter.Button(
  1600. SCREEN,
  1601. bg=botton_color,
  1602. fg=word_color,
  1603. text="键入参数",
  1604. command=add_calculation_number,
  1605. font=FONT,
  1606. width=gui_width,
  1607. height=gui_height,
  1608. ).grid(
  1609. column=column + 1,
  1610. row=row,
  1611. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1612. )
  1613. tkinter.Button(
  1614. SCREEN,
  1615. bg=botton_color,
  1616. fg=word_color,
  1617. text="矩阵运算",
  1618. command=calculation,
  1619. font=FONT,
  1620. width=gui_width,
  1621. height=gui_height,
  1622. ).grid(
  1623. column=column + 2,
  1624. row=row,
  1625. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1626. )
  1627. SCREEN.mainloop()
  1628. def add_reverse_fast_fourier2(): # 添加Lenear的核心
  1629. add_leaner("[2]Reverse_Fast_Fourier")
  1630. def add_reverse_fast_fourier(): # 添加Lenear的核心
  1631. add_leaner("Reverse_Fast_Fourier")
  1632. def add_fast_fourier(): # 添加Lenear的核心
  1633. add_leaner("Fast_Fourier")
  1634. def curve_fitting():
  1635. file_dir = askopenfilename(title="导入参数")
  1636. with open(file_dir, "r") as f:
  1637. learner_controller.add_curve_fitting(f.read())
  1638. update_leaner()
  1639. def show_clustering_score():
  1640. show_score(2)
  1641. def show_regression_score():
  1642. show_score(1)
  1643. def show_class_score():
  1644. show_score(0)
  1645. def show_score(func):
  1646. learner = get_learner(True)
  1647. save_dir = askdirectory(title="选择保存位置")
  1648. data = learner_controller.model_evaluation(
  1649. learner, save_dir, get_name(False, True), get_name(False, False), func
  1650. )
  1651. webbrowser.open(data[0])
  1652. webbrowser.open(data[1]) # 还可以打开文件管理器
  1653. update_sheet_box()
  1654. def calculation():
  1655. global calculation_list, calculation_method, calculation_type
  1656. func = calculation_type.get()
  1657. if len(calculation_list) == 2 and 1 in calculation_method:
  1658. learner_controller.calculation_matrix(
  1659. calculation_list, calculation_method, func
  1660. )
  1661. update_sheet_box()
  1662. def add_calculation_core(num, type_):
  1663. global calculation_list, calculation_method
  1664. if len(calculation_list) == 2:
  1665. del calculation_list[0]
  1666. del calculation_method[0]
  1667. calculation_list.append(num)
  1668. calculation_method.append(type_)
  1669. def update_calculation_box():
  1670. global calculation_list, calculation_method, calculation_box
  1671. calculation_box.delete(0, tkinter.END)
  1672. a = ["第一参数", "第二参数"]
  1673. b = ["参数", "矩阵"]
  1674. calculation_box.insert(
  1675. tkinter.END,
  1676. *[
  1677. f"{a[i]} {calculation_list[i]} {b[calculation_method[i]]}"
  1678. for i in range(len(calculation_list))
  1679. ],
  1680. )
  1681. def add_calculation_number():
  1682. global calculation_box, calculation_type, value
  1683. num = eval(value.get(), {})
  1684. add_calculation_core(num, 0)
  1685. update_calculation_box()
  1686. def add_calculation_object():
  1687. name = get_name()
  1688. add_calculation_core(name, 1)
  1689. update_calculation_box()
  1690. def del_leaner():
  1691. learn = get_learner(True)
  1692. set_learne = get_learner(False) # 获取学习器Learner
  1693. if set_learne != learn:
  1694. learner_controller.del_leaner(learn)
  1695. update_leaner()
  1696. def global_seeting():
  1697. global global_settings
  1698. args = [bool(i.get()) for i in global_settings]
  1699. Learn_Numpy.set_global(*args)
  1700. def reshape():
  1701. global learner_controller, processing_type, shape
  1702. numpy_shape = eval(f"[{shape.get()}]")[0]
  1703. learner_controller.reshape(get_name(), numpy_shape)
  1704. update_sheet_box()
  1705. def transpose():
  1706. global learner_controller, processing_type, shape
  1707. try:
  1708. func = eval(f"[{shape.get()}]")
  1709. except BaseException:
  1710. func = None
  1711. learner_controller.transpose(get_name(), func)
  1712. update_sheet_box()
  1713. def del_ndim():
  1714. global learner_controller
  1715. learner_controller.del_ndim(get_name())
  1716. update_sheet_box()
  1717. def reval():
  1718. global learner_controller, processing_type
  1719. reval_type = processing_type.get()
  1720. learner_controller.reval(get_name(), reval_type)
  1721. update_sheet_box()
  1722. def two_split():
  1723. global learner_controller, processing_type, shape
  1724. split_type = processing_type.get()
  1725. learner_controller.two_split(get_name(), shape.get(), split_type)
  1726. update_sheet_box()
  1727. def split():
  1728. global learner_controller, processing_type, shape
  1729. split_type = processing_type.get()
  1730. try:
  1731. split_shape_list = eval(f"[{shape.get()}]", {})[0]
  1732. except BaseException:
  1733. split_shape_list = 2
  1734. learner_controller.split(get_name(), split_shape_list, split_type)
  1735. update_sheet_box()
  1736. def merge():
  1737. global merge_list, learner_controller, processing_type
  1738. if len(merge_list) < 1:
  1739. return False
  1740. merge_type = processing_type.get()
  1741. learner_controller.merge(merge_list, merge_type)
  1742. update_sheet_box()
  1743. def update_merge_box():
  1744. global merge_list, merge_box
  1745. merge_box.delete(0, tkinter.END)
  1746. merge_box.insert(tkinter.END, *merge_list)
  1747. def merge_del():
  1748. global merge_list, merge_box
  1749. del merge_list[merge_box.curselection()[0]]
  1750. update_merge_box()
  1751. def merge_add():
  1752. global merge_list
  1753. name = get_name()
  1754. merge_list.append(name)
  1755. update_merge_box()
  1756. def visualization_results():
  1757. learner = get_learner(True)
  1758. save_dir = askdirectory(title="选择保存位置")
  1759. data = learner_controller.model_visualization(learner, save_dir)
  1760. webbrowser.open(data[0])
  1761. webbrowser.open(data[1]) # 还可以打开文件管理器
  1762. update_sheet_box()
  1763. def get_learner_parameters():
  1764. global learner_parameters
  1765. return learner_parameters.get("0.0", tkinter.END)
  1766. def score_learner():
  1767. learner = get_learner()
  1768. socore = learner_controller.score(
  1769. get_name(False, True), get_name(False, False), learner
  1770. )
  1771. tkinter.messagebox.showinfo("测试完成", f"针对测试数据评分结果为:{socore}")
  1772. def predict_learner():
  1773. learner = get_learner()
  1774. data = learner_controller.predict(get_name(False, True), learner)
  1775. title = f"CoTan数据处理 学习器:{learner}"
  1776. creat_text_sheet(data, title)
  1777. update_sheet_box()
  1778. def fit_learner():
  1779. learner = get_learner()
  1780. try:
  1781. split = float(data_split.get())
  1782. if split < 0 or 1 < split:
  1783. raise Exception
  1784. except BaseException:
  1785. split = 0.3
  1786. socore = learner_controller.fit_model(
  1787. get_name(False, True),
  1788. get_name(False, False),
  1789. learner,
  1790. Text=get_learner_parameters(),
  1791. split=split,
  1792. )
  1793. tkinter.messagebox.showinfo(
  1794. "训练完成",
  1795. f"针对训练数据({(1 - split) * 100}%)评分结果为:{socore[0]}\n"
  1796. f"针对测试数据评分({split * 100}%)结果为:{socore[1]}",
  1797. )
  1798. def set_x_data():
  1799. global x_data
  1800. x_data.set(get_name())
  1801. def set_y_data():
  1802. global y_data
  1803. y_data.set(get_name())
  1804. def set_learner():
  1805. global learner_output
  1806. learner_output.set(get_learner(True))
  1807. def get_learner(return_box=False):
  1808. global learn_dict, learner_box, learner_output
  1809. if return_box:
  1810. try:
  1811. return list(learn_dict.keys())[learner_box.curselection()[0]]
  1812. except BaseException:
  1813. try:
  1814. return list(learn_dict.keys)[0]
  1815. except BaseException:
  1816. return get_learner(False)
  1817. else:
  1818. try:
  1819. return learner_output.get()
  1820. except BaseException:
  1821. return None
  1822. def add_statistics(): # 添加Lenear的核心
  1823. add_leaner("Statistics")
  1824. def add_correlation():
  1825. add_leaner("Correlation")
  1826. def add_matrix_scatter():
  1827. add_leaner("MatrixScatter")
  1828. def add_view_data():
  1829. learner_controller.add_view_data(get_learner(), parameters=get_learner_parameters())
  1830. update_leaner()
  1831. def add_cluster_tree():
  1832. add_leaner("ClusterTree")
  1833. def add_feature_y_x():
  1834. add_leaner("FeatureY-X")
  1835. def add_numpy_to_heatmap():
  1836. add_leaner("HeatMap")
  1837. def add_predictive_heatmap_more(): # 添加Lenear的核心
  1838. learner_controller.add_predictive_heat_map_more(
  1839. get_learner(), parameters=get_learner_parameters()
  1840. )
  1841. update_leaner()
  1842. def add_predictive_heatmap(): # 添加Lenear的核心
  1843. learner_controller.add_predictive_heat_map(
  1844. get_learner(), parameters=get_learner_parameters()
  1845. )
  1846. update_leaner()
  1847. def add_feature_scatter_class_all():
  1848. add_leaner("FeatureScatterClass_all")
  1849. def add_feature_scatter_all():
  1850. add_leaner("FeatureScatter_all")
  1851. def add_feature_scatter_class():
  1852. add_leaner("FeatureScatterClass")
  1853. def add_feature_scatter():
  1854. add_leaner("FeatureScatter")
  1855. def add_class_bar():
  1856. add_leaner("ClassBar")
  1857. def add_dbscan():
  1858. add_leaner("DBSCAN")
  1859. def add_agglomerative():
  1860. add_leaner("Agglomerative")
  1861. def add_k_means():
  1862. add_leaner("k-means")
  1863. def add_mlp_class():
  1864. add_leaner("MLP_class")
  1865. def add_mlp():
  1866. add_leaner("MLP")
  1867. def add_svr():
  1868. add_leaner("SVR")
  1869. def add_svc():
  1870. add_leaner("SVC")
  1871. def add_gradient_tree():
  1872. add_leaner("GradientTree")
  1873. def add_gradient_tree_class():
  1874. add_leaner("GradientTree_class")
  1875. def add_tsne():
  1876. add_leaner("t-SNE")
  1877. def add_nmf():
  1878. add_leaner("NMF")
  1879. def add_lda():
  1880. add_leaner("LDA")
  1881. def add_kpca():
  1882. add_leaner("KPCA")
  1883. def add_rpca():
  1884. add_leaner("RPCA")
  1885. def add_pca():
  1886. add_leaner("PCA")
  1887. def add_missed():
  1888. add_leaner("Missed")
  1889. def add_label():
  1890. add_leaner("Label")
  1891. def add_one_hot_encoder():
  1892. add_leaner("OneHotEncoder")
  1893. def add_discretization():
  1894. add_leaner("Discretization")
  1895. def add_binarizer():
  1896. add_leaner("Binarizer")
  1897. def add_regularization():
  1898. add_leaner("Regularization")
  1899. def add_fuzzy_quantization():
  1900. add_leaner("Fuzzy_quantization")
  1901. def add_mapzoom():
  1902. add_leaner("Mapzoom")
  1903. def add_sigmod_scaler():
  1904. add_leaner("sigmodScaler")
  1905. def add_decimal_scaler():
  1906. add_leaner("decimalScaler")
  1907. def add_atan_scaler():
  1908. add_leaner("atanScaler")
  1909. def add_log_scaler():
  1910. add_leaner("LogScaler")
  1911. def add_min_max_scaler():
  1912. add_leaner("MinMaxScaler")
  1913. def add_z_score():
  1914. add_leaner("Z-Score")
  1915. def add_forest():
  1916. add_leaner("Forest")
  1917. def add_forest_class():
  1918. add_leaner("Forest_class")
  1919. def add_tree_class():
  1920. add_leaner("Tree_class")
  1921. def add_tree():
  1922. add_leaner("Tree")
  1923. def add_select_k_best():
  1924. add_leaner("SelectKBest")
  1925. def add_knn_class():
  1926. add_leaner("Knn_class")
  1927. def add_logistic_regression():
  1928. add_leaner("LogisticRegression")
  1929. def add_lasso():
  1930. add_leaner("Lasso")
  1931. def add_variance():
  1932. add_leaner("Variance")
  1933. def add_knn():
  1934. add_leaner("Knn")
  1935. def add_ridge():
  1936. add_leaner("Ridge")
  1937. def add_line():
  1938. add_leaner("Line")
  1939. def add_select_from_model(): # 添加Lenear的核心
  1940. learner_controller.add_select_from_model(
  1941. get_learner(), parameters=get_learner_parameters()
  1942. )
  1943. update_leaner()
  1944. def add_leaner(learner_type): # 添加Lenear的核心
  1945. learner_controller.add_learner(learner_type, parameters=get_learner_parameters())
  1946. update_leaner()
  1947. def update_leaner():
  1948. global learn_dict, learner_box
  1949. learn_dict = learner_controller.return_learner()
  1950. learner_box.delete(0, tkinter.END)
  1951. learner_box.insert(tkinter.END, *learn_dict.keys())
  1952. def to_html_one():
  1953. global PATH, to_html_type
  1954. html_dir = f"{PATH}/$Show_Sheet.html"
  1955. try:
  1956. name = get_name()
  1957. if name is None:
  1958. raise Exception
  1959. learner_controller.to_html_one(name, html_dir)
  1960. webbrowser.open(html_dir)
  1961. except BaseException:
  1962. # pass
  1963. raise
  1964. def to_html():
  1965. global PATH, to_html_type
  1966. html_dir = f"{PATH}/$Show_Sheet.html"
  1967. try:
  1968. name = get_name()
  1969. if name is None:
  1970. raise Exception
  1971. learner_controller.to_html(name, html_dir, to_html_type.get())
  1972. webbrowser.open(html_dir)
  1973. except BaseException:
  1974. pass
  1975. def to_csv():
  1976. global SCREEN, sep, encoding, dtype_str, Index_must
  1977. save_dir = asksaveasfilename(title="选择保存的CSV", filetypes=[("CSV", ".csv")])
  1978. csv_sep = sep.get()
  1979. name = get_name()
  1980. learner_controller.to_csv(save_dir, name, csv_sep)
  1981. update_sheet_box()
  1982. def add_csv():
  1983. global SCREEN, sep, encoding, dtype_str, sheet_name
  1984. csv_dir = askopenfilename(title="选择载入的CSV", filetypes=[("CSV", ".csv")])
  1985. if csv_dir == "":
  1986. return False
  1987. sep = sep.get()
  1988. encoding = encoding.get()
  1989. must_str = bool(dtype_str.get())
  1990. name = sheet_name.get().replace(" ", "")
  1991. if name == "":
  1992. name = os.path.splitext(os.path.split(csv_dir)[1])[0]
  1993. if encoding == "":
  1994. with open(csv_dir, "rb") as f:
  1995. encoding = chardet.detect(f.read())["encoding"]
  1996. if sep == "":
  1997. sep = ","
  1998. learner_controller.read_csv(
  1999. csv_dir, name, encoding, must_str, sep,
  2000. )
  2001. update_sheet_box()
  2002. def add_python():
  2003. global SCREEN, sep, encoding, dtype_str, Index_must
  2004. python_dir = askopenfilename(
  2005. title="选择载入的py", filetypes=[("Python", ".py"), ("Txt", ".txt")]
  2006. )
  2007. name = sheet_name.get().replace(" ", "")
  2008. if name == "":
  2009. name = os.path.splitext(os.path.split(python_dir)[1])[0]
  2010. with open(python_dir, "r") as f:
  2011. learner_controller.add_python(f.read(), name)
  2012. update_sheet_box()
  2013. def get_name(get_from_box=True, is_x_data=True): # 获得名字统一接口
  2014. global sheet_list, sheet_box, x_data
  2015. if get_from_box:
  2016. try:
  2017. return sheet_list[sheet_box.curselection()[0]]
  2018. except BaseException:
  2019. try:
  2020. return sheet_list[0]
  2021. except BaseException:
  2022. return None
  2023. else:
  2024. try:
  2025. if is_x_data:
  2026. return x_data.get()
  2027. else:
  2028. return y_data.get()
  2029. except BaseException:
  2030. return None
  2031. def update_sheet_box():
  2032. global SCREEN, sheet_box, sheet_list
  2033. sheet_list = list(learner_controller.get_form().keys())
  2034. sheet_box.delete(0, tkinter.END)
  2035. sheet_box.insert(tkinter.END, *sheet_list)
  2036. def creat_text_sheet(data, name):
  2037. global bg_color
  2038. new_top = tkinter.Toplevel(bg=bg_color)
  2039. new_top.title(name)
  2040. new_top.geometry("+10+10") # 设置所在位置
  2041. text = ScrolledText(new_top, font=("黑体", 13), height=50)
  2042. text.pack(fill=tkinter.BOTH)
  2043. text.insert("0.0", data)
  2044. text.config(state=tkinter.DISABLED)
  2045. new_top.resizable(width=False, height=False)