daily pastebin goal
44%
SHARE
TWEET

this tempestado one day vaiacabar

11eimilia11 Feb 21st, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pandas as pd
  2. import cv2
  3. import numpy as np
  4. from Lista02 import FuncoesML as fun
  5. from sklearn.model_selection import KFold
  6. from sklearn.neighbors import KNeighborsClassifier
  7. from sklearn.tree import DecisionTreeClassifier
  8. from sklearn.naive_bayes import GaussianNB
  9. from sklearn.svm import SVC
  10. import time
  11. from sklearn.linear_model import LogisticRegression
  12. from sklearn.neural_network import MLPClassifier
  13. from sklearn.ensemble import RandomForestClassifier
  14. from sklearn.metrics import recall_score
  15. from sklearn.metrics import precision_score
  16. from sklearn.metrics import f1_score
  17.  
  18. #lendo a imagem
  19. print('comecou load images')
  20. squares = []
  21. squares = fun.loadFiles('C:/Users/Auricelia/Desktop/DataSetsML/New_shapes_dataset/squares/*.jpg', squares)
  22.  
  23. circles = []
  24. circles = fun.loadFiles('C:/Users/Auricelia/Desktop/DataSetsML/New_shapes_dataset/circles/*.jpg',circles)
  25.  
  26. triangles = []
  27. triangles = fun.loadFiles('C:/Users/Auricelia/Desktop/DataSetsML/New_shapes_dataset/triangles/*.jpg', triangles)
  28.  
  29. ellipses = []
  30. ellipses = fun.loadFiles('C:/Users/Auricelia/Desktop/DataSetsML/New_shapes_dataset/ellipses/*.jpg', ellipses)
  31.  
  32. trapezia = []
  33. trapezia = fun.loadFiles('C:/Users/Auricelia/Desktop/DataSetsML/New_shapes_dataset/trapezia/*.jpg', trapezia)
  34.  
  35. rectangles = []
  36. rectangles = fun.loadFiles('C:/Users/Auricelia/Desktop/DataSetsML/New_shapes_dataset/rectangles/*.jpg', rectangles)
  37.  
  38. rhombuses = []
  39. rhombuses = fun.loadFiles('C:/Users/Auricelia/Desktop/DataSetsML/New_shapes_dataset/rhombuses/*.jpg', rhombuses)
  40.  
  41. lines = []
  42. lines = fun.loadFiles('C:/Users/Auricelia/Desktop/DataSetsML/New_shapes_dataset/lines/*.jpg', lines)
  43.  
  44. hexagons = []
  45. hexagons = fun.loadFiles('C:/Users/Auricelia/Desktop/DataSetsML/New_shapes_dataset/hexagons/*.jpg', hexagons)
  46.  
  47. print('terminou load images')
  48.  
  49. # Selecionando aleatoriamente 72 imagens de cada classe
  50.  
  51. squares_selec, squares_naoselec = fun.seleciona_imagens(squares,72)
  52. circles_selec, circles_naoselec = fun.seleciona_imagens(circles,72)
  53. triangles_selec, triangles_naoselec = fun.seleciona_imagens(triangles,72)
  54. ellipses_selec, ellipses_naoselec = fun.seleciona_imagens(ellipses,72)
  55. trapezia_selec, trapezia_naoselec = fun.seleciona_imagens(trapezia,72)
  56. rectangles_selec, rectangles_naoselec = fun.seleciona_imagens(rectangles,72)
  57. rhombuses_selec, rhombuses_naoselec = fun.seleciona_imagens(rhombuses,72)
  58. lines_selec, lines_naoselec = fun.seleciona_imagens(lines,72)
  59. hexagons_selec, hexagons_naoselec = fun.seleciona_imagens(hexagons,72)
  60.  
  61. #Salvando em pastas diferentes as imagens para seleção de características e as de teste
  62.  
  63. fun.save_images(squares_selec,'C:/Users/Auricelia/Desktop/DataSetsML/Random/RandomSquares/')
  64. fun.save_images(squares_naoselec,'C:/Users/Auricelia/Desktop/DataSetsML/Not_Random/Squares/')
  65. fun.save_images(circles_selec,'C:/Users/Auricelia/Desktop/DataSetsML/Random/RandomCircles/')
  66. fun.save_images(circles_naoselec,'C:/Users/Auricelia/Desktop/DataSetsML/Not_Random/Circles/')
  67. fun.save_images(triangles_selec,'C:/Users/Auricelia/Desktop/DataSetsML/Random/RandomTriangles/')
  68. fun.save_images(triangles_naoselec,'C:/Users/Auricelia/Desktop/DataSetsML/Not_Random/Triangles/')
  69. fun.save_images(ellipses_selec, 'C:/Users/Auricelia/Desktop/DataSetsML/Random/RandomEllipses/')
  70. fun.save_images(ellipses_naoselec,'C:/Users/Auricelia/Desktop/DataSetsML/Not_Random/Ellipses/')
  71. fun.save_images(trapezia_selec,'C:/Users/Auricelia/Desktop/DataSetsML/Random/RandomTrapezia/')
  72. fun.save_images(trapezia_naoselec,'C:/Users/Auricelia/Desktop/DataSetsML/Not_Random/Trapezia/')
  73. fun.save_images(rectangles_selec,'C:/Users/Auricelia/Desktop/DataSetsML/Random/RandomRectangles/')
  74. fun.save_images(rectangles_naoselec, 'C:/Users/Auricelia/Desktop/DataSetsML/Not_Random/Rectangles/')
  75. fun.save_images(rhombuses_selec,'C:/Users/Auricelia/Desktop/DataSetsML/Random/RandomRhombuses/')
  76. fun.save_images(rhombuses_naoselec, 'C:/Users/Auricelia/Desktop/DataSetsML/Not_Random/Rhombuses/')
  77. fun.save_images(lines_selec, 'C:/Users/Auricelia/Desktop/DataSetsML/Random/RandomLines/')
  78. fun.save_images(lines_naoselec, 'C:/Users/Auricelia/Desktop/DataSetsML/Not_Random/Lines/')
  79. fun.save_images(hexagons_selec, 'C:/Users/Auricelia/Desktop/DataSetsML/Random/RandomHexagons/')
  80. fun.save_images(hexagons_naoselec, 'C:/Users/Auricelia/Desktop/DataSetsML/Not_Random/Hexagons/')
  81.  
  82.  
  83.  
  84. # PRE PROCESSING
  85.  
  86. #criando cópias de cada uma das pastas para redimensionar as imagens
  87. #quadrados
  88.  
  89. squares16_s = squares_selec.copy()
  90. squares16_n = squares_naoselec.copy()
  91.  
  92. squares32_s = squares_selec.copy()
  93. squares32_n = squares_naoselec.copy()
  94.  
  95. squares64_s = squares_selec.copy()
  96. squares64_n = squares_naoselec.copy()
  97.  
  98. squares128_s = squares_selec.copy()
  99. squares128_n = squares_naoselec.copy()
  100.  
  101. squares16_s = fun.resizeImages(squares16_s,16,16)
  102. squares16_n = fun.resizeImages(squares16_n,16,16)
  103.  
  104. squares32_s = fun.resizeImages(squares32_s,32,32)
  105. squares32_n = fun.resizeImages(squares32_n,32,32)
  106.  
  107. squares64_s = fun.resizeImages(squares64_s,64,64)
  108. squares64_n = fun.resizeImages(squares64_n,64,64)
  109.  
  110. squares128_s = fun.resizeImages(squares128_s,128,128)
  111. squares128_n = fun.resizeImages(squares128_n,128,128)
  112.  
  113. #círculos
  114. circles16_s = circles_selec.copy()
  115. circles16_n = circles_naoselec.copy()
  116.  
  117. circles32_s = circles_selec.copy()
  118. circles32_n = circles_naoselec.copy()
  119.  
  120. circles64_s = circles_selec.copy()
  121. circles64_n = circles_naoselec.copy()
  122.  
  123. circles128_s = circles_selec.copy()
  124. circles128_n = circles_naoselec.copy()
  125.  
  126. circles16_s = fun.resizeImages(circles16_s,16,16)
  127. circles16_n = fun.resizeImages(circles16_n,16,16)
  128.  
  129. circles32_s = fun.resizeImages(circles32_s,32,32)
  130. circles32_n = fun.resizeImages(circles32_n,32,32)
  131.  
  132. circles64_s = fun.resizeImages(circles64_s,64,64)
  133. circles64_n = fun.resizeImages(circles64_n,64,64)
  134. circles128_s = fun.resizeImages(circles128_s,128,128)
  135. circles128_n = fun.resizeImages(circles128_n,128,128)
  136.  
  137. #elipses
  138. ellipsis16_s = ellipses_selec.copy()
  139. ellipsis16_n = ellipses_naoselec.copy()
  140.  
  141. ellipsis32_s = ellipses_selec.copy()
  142. ellipsis32_n = ellipses_naoselec.copy()
  143.  
  144. ellipsis64_s = ellipses_selec.copy()
  145. ellipsis64_n = ellipses_naoselec.copy()
  146.  
  147. ellipsis128_s = ellipses_selec.copy()
  148. ellipsis128_n = ellipses_naoselec.copy()
  149.  
  150. ellipsis16_s = fun.resizeImages(ellipsis16_s,16,16)
  151. ellipsis16_n = fun.resizeImages(ellipsis16_n,16,16)
  152.  
  153. ellipsis32_s = fun.resizeImages(ellipsis32_s,32,32)
  154. ellipsis32_n = fun.resizeImages(ellipsis32_n,32,32)
  155.  
  156. ellipsis64_s = fun.resizeImages(ellipsis64_s,64,64)
  157. ellipsis64_n = fun.resizeImages(ellipsis64_n,64,64)
  158.  
  159. ellipsis128_s = fun.resizeImages(ellipsis128_s,128,128)
  160. ellipsis128_n = fun.resizeImages(ellipsis128_n,128,128)
  161.  
  162. #hexágonos
  163. hexagons16_s = hexagons_selec.copy()
  164. hexagons16_n = hexagons_naoselec.copy()
  165. hexagons32_s = hexagons_selec.copy()
  166. hexagons32_n = hexagons_naoselec.copy()
  167. hexagons64_s = hexagons_selec.copy()
  168. hexagons64_n = hexagons_naoselec.copy()
  169. hexagons128_s = hexagons_selec.copy()
  170. hexagons128_n = hexagons_naoselec.copy()
  171.  
  172. hexagons16_s = fun.resizeImages(hexagons16_s,16,16)
  173. hexagons16_n = fun.resizeImages(hexagons16_n,16,16)
  174. hexagons32_s = fun.resizeImages(hexagons32_s,32,32)
  175. hexagons32_n = fun.resizeImages(hexagons32_n,32,32)
  176. hexagons64_s = fun.resizeImages(hexagons64_s,64,64)
  177. hexagons64_n = fun.resizeImages(hexagons64_n,64,64)
  178. hexagons128_s = fun.resizeImages(hexagons128_s,128,128)
  179. hexagons128_n = fun.resizeImages(hexagons128_n,128,128)
  180.  
  181. #linhas
  182. lines16_s = lines_selec.copy()
  183. lines16_n = lines_naoselec.copy()
  184. lines32_s = lines_selec.copy()
  185. lines32_n = lines_naoselec.copy()
  186. lines64_s = lines_selec.copy()
  187. lines64_n = lines_naoselec.copy()
  188. lines128_s = lines_selec.copy()
  189. lines128_n = lines_naoselec.copy()
  190.  
  191. lines16_s = fun.resizeImages(lines16_s,16,16)
  192. lines16_n = fun.resizeImages(lines16_n,16,16)
  193. lines32_s = fun.resizeImages(lines32_s,32,32)
  194. lines32_n = fun.resizeImages(lines32_n,32,32)
  195. lines64_s = fun.resizeImages(lines64_s,64,64)
  196. lines64_n = fun.resizeImages(lines64_n,64,64)
  197. lines128_s = fun.resizeImages(lines128_s,128,128)
  198. lines128_n = fun.resizeImages(lines128_n,128,128)
  199.  
  200. #retângulos
  201. rectangles16_s = rectangles_selec.copy()
  202. rectangles16_n = rectangles_naoselec.copy()
  203. rectangles32_s = rectangles_selec.copy()
  204. rectangles32_n = rectangles_naoselec.copy()
  205. rectangles64_s = rectangles_selec.copy()
  206. rectangles64_n = rectangles_naoselec.copy()
  207. rectangles128_s = rectangles_selec.copy()
  208. rectangles128_n = rectangles_naoselec.copy()
  209.  
  210. rectangles16_s = fun.resizeImages(rectangles16_s,16,16)
  211. rectangles16_n = fun.resizeImages(rectangles16_n,16,16)
  212. rectangles32_s = fun.resizeImages(rectangles32_s,32,32)
  213. rectangles32_n = fun.resizeImages(rectangles32_n,32,32)
  214. rectangles64_s = fun.resizeImages(rectangles64_s,64,64)
  215. rectangles64_n = fun.resizeImages(rectangles64_n,64,64)
  216. rectangles128_s = fun.resizeImages(rectangles128_s,128,128)
  217. rectangles128_n = fun.resizeImages(rectangles128_n,128,128)
  218.  
  219. #losangos
  220. rhombuses16_s = rhombuses_selec.copy()
  221. rhombuses16_n = rhombuses_naoselec.copy()
  222. rhombuses32_s = rhombuses_selec.copy()
  223. rhombuses32_n = rhombuses_naoselec.copy()
  224. rhombuses64_s = rhombuses_selec.copy()
  225. rhombuses64_n = rhombuses_naoselec.copy()
  226. rhombuses128_s = rhombuses_selec.copy()
  227. rhombuses128_n = rhombuses_naoselec.copy()
  228.  
  229. rhombuses16_s = fun.resizeImages(rhombuses16_s,16,16)
  230. rhombuses16_n = fun.resizeImages(rhombuses16_n,16,16)
  231. rhombuses32_s = fun.resizeImages(rhombuses32_s,32,32)
  232. rhombuses32_n = fun.resizeImages(rhombuses32_n,32,32)
  233. rhombuses64_s = fun.resizeImages(rhombuses64_s,64,64)
  234. rhombuses64_n = fun.resizeImages(rhombuses64_n,64,64)
  235. rhombuses128_s = fun.resizeImages(rhombuses128_s,128,128)
  236. rhombuses128_n = fun.resizeImages(rhombuses128_n,128,128)
  237.  
  238. #trapézios
  239. trapezia16_s = trapezia_selec.copy()
  240. trapezia16_n = trapezia_naoselec.copy()
  241. trapezia32_s = trapezia_selec.copy()
  242. trapezia32_n = trapezia_naoselec.copy()
  243. trapezia64_s = trapezia_selec.copy()
  244. trapezia64_n = trapezia_naoselec.copy()
  245. trapezia128_s = trapezia_selec.copy()
  246. trapezia128_n = trapezia_naoselec.copy()
  247.  
  248. trapezia16_s = fun.resizeImages(trapezia16_s,16,16)
  249. trapezia16_n = fun.resizeImages(trapezia16_n,16,16)
  250. trapezia32_s = fun.resizeImages(trapezia32_s,32,32)
  251. trapezia32_n = fun.resizeImages(trapezia32_n,32,32)
  252. trapezia64_s = fun.resizeImages(trapezia64_s,64,64)
  253. trapezia64_n = fun.resizeImages(trapezia64_n,64,64)
  254. trapezia128_s = fun.resizeImages(trapezia128_s,128,128)
  255. trapezia128_n = fun.resizeImages(trapezia128_n,128,128)
  256.  
  257. #triângulos
  258. triangles16_s = triangles_selec.copy()
  259. triangles16_n = triangles_naoselec.copy()
  260. triangles32_s = triangles_selec.copy()
  261. triangles32_n = triangles_naoselec.copy()
  262. triangles64_s = triangles_selec.copy()
  263. triangles64_n = triangles_naoselec.copy()
  264. triangles128_s = triangles_selec.copy()
  265. triangles128_n = triangles_naoselec.copy()
  266.  
  267. triangles16_s = fun.resizeImages(triangles16_s,16,16)
  268. triangles16_n = fun.resizeImages(triangles16_n,16,16)
  269. triangles32_s = fun.resizeImages(triangles32_s,32,32)
  270. triangles32_n = fun.resizeImages(triangles32_n,32,32)
  271. triangles64_s = fun.resizeImages(triangles64_s,64,64)
  272. triangles64_n = fun.resizeImages(triangles64_n,64,64)
  273. triangles128_s = fun.resizeImages(triangles128_s,128,128)
  274. triangles128_n = fun.resizeImages(triangles128_n,128,128)
  275.  
  276. #convertendo para níveis de cinza
  277.  
  278. squares16_s = fun.grayConversion(squares16_s)
  279. squares16_n = fun.grayConversion(squares16_n)
  280. squares32_s = fun.grayConversion(squares32_s)
  281. squares32_n = fun.grayConversion(squares32_n)
  282. squares64_s = fun.grayConversion(squares64_s)
  283. squares64_n = fun.grayConversion(squares64_n)
  284. squares128_s = fun.grayConversion(squares128_s)
  285. squares128_n = fun.grayConversion(squares128_n)
  286.  
  287.  
  288. circles16_s = fun.grayConversion(circles16_s)
  289. circles16_n = fun.grayConversion(circles16_n)
  290. circles32_s = fun.grayConversion(circles32_s)
  291. circles32_n = fun.grayConversion(circles32_n)
  292. circles64_s = fun.grayConversion(circles64_s)
  293. circles64_n = fun.grayConversion(circles64_n)
  294. circles128_s = fun.grayConversion(circles128_s)
  295. circles128_n = fun.grayConversion(circles128_n)
  296.  
  297. triangles16_s = fun.grayConversion(triangles16_s)
  298. triangles16_n = fun.grayConversion(triangles16_n)
  299. triangles32_s = fun.grayConversion(triangles32_s)
  300. triangles32_n = fun.grayConversion(triangles32_n)
  301. triangles64_s = fun.grayConversion(triangles64_s)
  302. triangles64_n = fun.grayConversion(triangles64_n)
  303. triangles128_s = fun.grayConversion(triangles128_s)
  304. triangles128_n = fun.grayConversion(triangles128_n)
  305.  
  306.  
  307. trapezia16_s = fun.grayConversion(trapezia16_s)
  308. trapezia16_n = fun.grayConversion(trapezia16_n)
  309. trapezia32_s = fun.grayConversion(trapezia32_s)
  310. trapezia32_n = fun.grayConversion(trapezia32_n)
  311. trapezia64_s = fun.grayConversion(trapezia64_s)
  312. trapezia64_n = fun.grayConversion(trapezia64_n)
  313. trapezia128_s = fun.grayConversion(trapezia128_s)
  314. trapezia128_n = fun.grayConversion(trapezia128_n)
  315.  
  316. rhombuses16_s = fun.grayConversion(rhombuses16_s)
  317. rhombuses16_n = fun.grayConversion(rhombuses16_n)
  318. rhombuses32_s = fun.grayConversion(rhombuses32_s)
  319. rhombuses32_n = fun.grayConversion(rhombuses32_n)
  320. rhombuses64_s = fun.grayConversion(rhombuses64_s)
  321. rhombuses64_n = fun.grayConversion(rhombuses64_n)
  322. rhombuses128_s = fun.grayConversion(rhombuses128_s)
  323. rhombuses128_n = fun.grayConversion(rhombuses128_n)
  324.  
  325. rectangles16_s = fun.grayConversion(rectangles16_s)
  326. rectangles16_n = fun.grayConversion(rectangles16_n)
  327. rectangles32_s = fun.grayConversion(rectangles32_s)
  328. rectangles32_n = fun.grayConversion(rectangles32_n)
  329. rectangles64_s = fun.grayConversion(rectangles64_s)
  330. rectangles64_n = fun.grayConversion(rectangles64_n)
  331. rectangles128_s = fun.grayConversion(rectangles128_s)
  332. rectangles128_n = fun.grayConversion(rectangles128_n)
  333.  
  334. lines16_s = fun.grayConversion(lines16_s)
  335. lines16_n = fun.grayConversion(lines16_n)
  336. lines32_s = fun.grayConversion(lines32_s)
  337. lines32_n = fun.grayConversion(lines32_n)
  338. lines64_s = fun.grayConversion(lines64_s)
  339. lines64_n = fun.grayConversion(lines64_n)
  340. lines128_s = fun.grayConversion(lines128_s)
  341. lines128_n = fun.grayConversion(lines128_n)
  342.  
  343. hexagons16_s = fun.grayConversion(hexagons16_s)
  344. hexagons16_n = fun.grayConversion(hexagons16_n)
  345. hexagons32_s = fun.grayConversion(hexagons32_s)
  346. hexagons32_n = fun.grayConversion(hexagons32_n)
  347. hexagons64_s = fun.grayConversion(hexagons64_s)
  348. hexagons64_n = fun.grayConversion(hexagons64_n)
  349. hexagons128_s = fun.grayConversion(hexagons128_s)
  350. hexagons128_n = fun.grayConversion(hexagons128_n)
  351.  
  352. ellipsis16_s = fun.grayConversion(ellipsis16_s)
  353. ellipsis16_n = fun.grayConversion(ellipsis16_n)
  354. ellipsis32_s = fun.grayConversion(ellipsis32_s)
  355. ellipsis32_n = fun.grayConversion(ellipsis32_n)
  356. ellipsis64_s = fun.grayConversion(ellipsis64_s)
  357. ellipsis64_n = fun.grayConversion(ellipsis64_n)
  358. ellipsis128_s = fun.grayConversion(ellipsis128_s)
  359. ellipsis128_n = fun.grayConversion(ellipsis128_n)
  360.  
  361. #aplicando o filtro gaussiano
  362.  
  363. squares16_s = fun.blurConversion(squares16_s,5,0)
  364. squares16_n = fun.blurConversion(squares16_n,5,0)
  365. squares32_s = fun.blurConversion(squares32_s,5,0)
  366. squares32_n = fun.blurConversion(squares32_n,5,0)
  367. squares64_s = fun.blurConversion(squares64_s,5,0)
  368. squares64_n = fun.blurConversion(squares64_n,5,0)
  369. squares128_s = fun.blurConversion(squares128_s,5,0)
  370. squares128_n = fun.blurConversion(squares128_n,5,0)
  371.  
  372. circles16_s = fun.blurConversion(circles16_s, 5, 0)
  373. circles16_n = fun.blurConversion(circles16_n, 5, 0)
  374. circles32_s = fun.blurConversion(circles32_s,5 ,0)
  375. circles32_n = fun.blurConversion(circles32_n,5 ,0)
  376. circles64_s = fun.blurConversion(circles64_s,5,0)
  377. circles64_n = fun.blurConversion(circles64_n,5,0)
  378. circles128_s = fun.blurConversion(circles128_s,5,0)
  379. circles128_n = fun.blurConversion(circles128_n,5,0)
  380.  
  381. triangles16_s = fun.blurConversion(triangles16_s,5,0)
  382. triangles16_n = fun.blurConversion(triangles16_n,5,0)
  383. triangles32_s = fun.blurConversion(triangles32_s,5,0)
  384. triangles32_n = fun.blurConversion(triangles32_n,5,0)
  385. triangles64_s = fun.blurConversion(triangles64_s,5,0)
  386. triangles64_n = fun.blurConversion(triangles64_n,5,0)
  387. triangles128_s = fun.blurConversion(triangles128_s,5,0)
  388. triangles128_n = fun.blurConversion(triangles128_n,5,0)
  389.  
  390. trapezia16_s = fun.blurConversion(trapezia16_s,5,0)
  391. trapezia16_n = fun.blurConversion(trapezia16_n,5,0)
  392. trapezia32_s = fun.blurConversion(trapezia32_s,5,0)
  393. trapezia64_s = fun.blurConversion(trapezia64_s,5,0)
  394. trapezia64_n = fun.blurConversion(trapezia64_n,5,0)
  395. trapezia128_s = fun.blurConversion(trapezia128_s,5,0)
  396. trapezia128_n = fun.blurConversion(trapezia128_n,5,0)
  397.  
  398. rhombuses16_s = fun.blurConversion(rhombuses16_s,5,0)
  399. rhombuses16_n = fun.blurConversion(rhombuses16_n,5,0)
  400. rhombuses32_s = fun.blurConversion(rhombuses32_s,5,0)
  401. rhombuses32_n = fun.blurConversion(rhombuses32_n,5,0)
  402. rhombuses64_s = fun.blurConversion(rhombuses64_s,5,0)
  403. rhombuses64_n = fun.blurConversion(rhombuses64_n,5,0)
  404. rhombuses128_s = fun.blurConversion(rhombuses128_s,5,0)
  405. rhombuses128_n = fun.blurConversion(rhombuses128_n,5,0)
  406.  
  407. rectangles16_s = fun.blurConversion(rectangles16_s,5,0)
  408. rectangles16_n = fun.blurConversion(rectangles16_n,5,0)
  409. rectangles32_s = fun.blurConversion(rectangles32_s,5,0)
  410. rectangles32_n = fun.blurConversion(rectangles32_n,5,0)
  411. rectangles64_s = fun.blurConversion(rectangles64_s,5,0)
  412. rectangles64_n = fun.blurConversion(rectangles64_n,5,0)
  413. rectangles128_s = fun.blurConversion(rectangles128_s,5,0)
  414. rectangles128_n = fun.blurConversion(rectangles128_n,5,0)
  415.  
  416. lines16_s = fun.blurConversion(lines16_s,5,0)
  417. lines16_n = fun.blurConversion(lines16_n,5,0)
  418. lines32_s = fun.blurConversion(lines32_s,5,0)
  419. lines32_n = fun.blurConversion(lines32_n,5,0)
  420. lines64_s = fun.blurConversion(lines64_s,5,0)
  421. lines64_n = fun.blurConversion(lines64_n,5,0)
  422. lines128_s = fun.blurConversion(lines128_s,5,0)
  423. lines128_n = fun.blurConversion(lines128_n,5,0)
  424.  
  425. hexagons16_s = fun.blurConversion(hexagons16_s,5,0)
  426. hexagons16_n = fun.blurConversion(hexagons16_n,5,0)
  427. hexagons32_s = fun.blurConversion(hexagons32_s,5,0)
  428. hexagons32_n = fun.blurConversion(hexagons32_n,5,0)
  429. hexagons64_s = fun.blurConversion(hexagons64_s,5,0)
  430. hexagons64_n = fun.blurConversion(hexagons64_n,5,0)
  431. hexagons128_s = fun.blurConversion(hexagons128_s,5,0)
  432. hexagons128_n = fun.blurConversion(hexagons128_n,5,0)
  433.  
  434. ellipsis16_s = fun.blurConversion(ellipsis16_s,5,0)
  435. ellipsis16_n = fun.blurConversion(ellipsis16_n,5,0)
  436. ellipsis32_s = fun.blurConversion(ellipsis32_s,5,0)
  437. ellipsis32_n = fun.blurConversion(ellipsis32_n,5,0)
  438. ellipsis64_s = fun.blurConversion(ellipsis64_s,5,0)
  439. ellipsis64_n = fun.blurConversion(ellipsis64_n,5,0)
  440. ellipsis128_s = fun.blurConversion(ellipsis128_s,5,0)
  441. ellipsis128_n = fun.blurConversion(ellipsis128_n,5,0)
  442.  
  443.  
  444. #convertendo para binária
  445. squares16_s = fun.binaryConversion(squares16_s,255,31)
  446. squares16_n = fun.binaryConversion(squares16_n,255,31)
  447. squares32_s = fun.binaryConversion(squares32_s,255,31)
  448. squares32_n = fun.binaryConversion(squares32_n,255,31)
  449. squares64_s = fun.binaryConversion(squares64_s,255,31)
  450. squares64_n = fun.binaryConversion(squares64_n,255,31)
  451. squares128_s = fun.binaryConversion(squares128_s,255,31)
  452. squares128_n = fun.binaryConversion(squares128_n,255,31)
  453.  
  454. circles16_s = fun.binaryConversion(circles16_s, 255, 31)
  455. circles16_n = fun.binaryConversion(circles16_n, 255, 31)
  456. circles32_s = fun.binaryConversion(circles32_s,255,31)
  457. circles32_n = fun.binaryConversion(circles32_n,255,31)
  458. circles64_s = fun.binaryConversion(circles64_s,255,31)
  459. circles64_n = fun.binaryConversion(circles64_n,255,31)
  460. circles128_s = fun.binaryConversion(circles128_s,255,31)
  461. circles128_n = fun.binaryConversion(circles128_n,255,31)
  462.  
  463. triangles16_s = fun.binaryConversion(triangles16_s,255,31)
  464. triangles16_n = fun.binaryConversion(triangles16_n,255,31)
  465. triangles32_s = fun.binaryConversion(triangles32_s,255,31)
  466. triangles32_n = fun.binaryConversion(triangles32_n,255,31)
  467. triangles64_s = fun.binaryConversion(triangles64_s,255,31)
  468. triangles64_n = fun.binaryConversion(triangles64_n,255,31)
  469. triangles128_s = fun.binaryConversion(triangles128_s,255,31)
  470. triangles128_n = fun.binaryConversion(triangles128_n,255,31)
  471.  
  472. trapezia16_s = fun.binaryConversion(trapezia16_s,255,31)
  473. trapezia16_n = fun.binaryConversion(trapezia16_n,255,31)
  474. trapezia32_s = fun.binaryConversion(trapezia32_s,255,31)
  475. trapezia32_n = fun.binaryConversion(trapezia32_n,255,31)
  476. trapezia64_s = fun.binaryConversion(trapezia64_s,255,31)
  477. trapezia64_n = fun.binaryConversion(trapezia64_n,255,31)
  478. trapezia128_s = fun.binaryConversion(trapezia128_s,255,31)
  479. trapezia128_n = fun.binaryConversion(trapezia128_n,255,31)
  480.  
  481. rhombuses16_s = fun.binaryConversion(rhombuses16_s,255,31)
  482. rhombuses16_n = fun.binaryConversion(rhombuses16_n,255,31)
  483. rhombuses32_s = fun.binaryConversion(rhombuses32_s,255,31)
  484. rhombuses32_n = fun.binaryConversion(rhombuses32_n,255,31)
  485. rhombuses64_s = fun.binaryConversion(rhombuses64_s,255,31)
  486. rhombuses64_n = fun.binaryConversion(rhombuses64_n,255,31)
  487. rhombuses128_s = fun.binaryConversion(rhombuses128_s,255,31)
  488. rhombuses128_n = fun.binaryConversion(rhombuses128_n,255,31)
  489.  
  490. rectangles16_s = fun.binaryConversion(rectangles16_s,255,31)
  491. rectangles16_n = fun.binaryConversion(rectangles16_n,255,31)
  492. rectangles32_s = fun.binaryConversion(rectangles32_s,255,31)
  493. rectangles32_n = fun.binaryConversion(rectangles32_n,255,31)
  494. rectangles64_s = fun.binaryConversion(rectangles64_s,255,31)
  495. rectangles64_n = fun.binaryConversion(rectangles64_n,255,31)
  496. rectangles128_s = fun.binaryConversion(rectangles128_s,255,31)
  497. rectangles128_n = fun.binaryConversion(rectangles128_n,255,31)
  498.  
  499. lines16_s = fun.binaryConversion(lines16_s,255,31)
  500. lines16_n = fun.binaryConversion(lines16_n,255,31)
  501. lines32_s = fun.binaryConversion(lines32_s,255,31)
  502. lines32_n = fun.binaryConversion(lines32_n,255,31)
  503. lines64_s = fun.binaryConversion(lines64_s,255,31)
  504. lines64_n = fun.binaryConversion(lines64_n,255,31)
  505. lines128_s = fun.binaryConversion(lines128_s,255,31)
  506. lines128_n = fun.binaryConversion(lines128_n,255,31)
  507.  
  508. hexagons16_s = fun.binaryConversion(hexagons16_s,255,31)
  509. hexagons16_n = fun.binaryConversion(hexagons16_n,255,31)
  510. hexagons32_s = fun.binaryConversion(hexagons32_s,255,31)
  511. hexagons32_n = fun.binaryConversion(hexagons32_n,255,31)
  512. hexagons64_s = fun.binaryConversion(hexagons64_s,255,31)
  513. hexagons64_n = fun.binaryConversion(hexagons64_n,255,31)
  514. hexagons128_s = fun.binaryConversion(hexagons128_s,255,31)
  515. hexagons128_n = fun.binaryConversion(hexagons128_n,255,31)
  516.  
  517. ellipsis16_s = fun.binaryConversion(ellipsis16_s,255,31)
  518. ellipsis16_n = fun.binaryConversion(ellipsis16_n,255,31)
  519. ellipsis32_s = fun.binaryConversion(ellipsis32_s,255,31)
  520. ellipsis32_n = fun.binaryConversion(ellipsis32_n,255,31)
  521. ellipsis64_s = fun.binaryConversion(ellipsis64_s,255,31)
  522. ellipsis64_n = fun.binaryConversion(ellipsis64_n,255,31)
  523. ellipsis128_s = fun.binaryConversion(ellipsis128_s,255,31)
  524. ellipsis128_n = fun.binaryConversion(ellipsis128_n,255,31)
  525.  
  526. #invertendo as cores
  527.  
  528. squares16_s = fun.invertConversion(squares16_s)
  529. squares16_n = fun.invertConversion(squares16_n)
  530. squares32_s = fun.invertConversion(squares32_s)
  531. squares32_n = fun.invertConversion(squares32_n)
  532. squares64_s = fun.invertConversion(squares64_s)
  533. squares64_n = fun.invertConversion(squares64_n)
  534. squares128_s = fun.invertConversion(squares128_s)
  535. squares128_n = fun.invertConversion(squares128_n)
  536.  
  537. circles16_s = fun.invertConversion(circles16_s)
  538. circles16_n = fun.invertConversion(circles16_n)
  539. circles32_s = fun.invertConversion(circles32_s)
  540. circles32_n = fun.invertConversion(circles32_n)
  541. circles64_s = fun.invertConversion(circles64_s)
  542. circles64_n = fun.invertConversion(circles64_n)
  543. circles128_s = fun.invertConversion(circles128_s)
  544. circles128_n = fun.invertConversion(circles128_n)
  545.  
  546. triangles16_s = fun.invertConversion(triangles16_s)
  547. triangles16_n = fun.invertConversion(triangles16_n)
  548. triangles32_s = fun.invertConversion(triangles32_s)
  549. triangles32_n = fun.invertConversion(triangles32_n)
  550. triangles64_s = fun.invertConversion(triangles64_s)
  551. triangles64_n = fun.invertConversion(triangles64_n)
  552. triangles128_s = fun.invertConversion(triangles128_s)
  553. triangles128_n = fun.invertConversion(triangles128_n)
  554.  
  555. trapezia16_s = fun.invertConversion(trapezia16_s)
  556. trapezia16_n = fun.invertConversion(trapezia16_n)
  557. trapezia32_s = fun.invertConversion(trapezia32_s)
  558. trapezia32_n = fun.invertConversion(trapezia32_n)
  559. trapezia64_s = fun.invertConversion(trapezia64_s)
  560. trapezia64_n = fun.invertConversion(trapezia64_n)
  561. trapezia128_s = fun.invertConversion(trapezia128_s)
  562. trapezia128_n = fun.invertConversion(trapezia128_n)
  563.  
  564. rhombuses16_s = fun.invertConversion(rhombuses16_s)
  565. rhombuses16_n = fun.invertConversion(rhombuses16_n)
  566. rhombuses32_s = fun.invertConversion(rhombuses32_s)
  567. rhombuses32_n = fun.invertConversion(rhombuses32_n)
  568. rhombuses64_s = fun.invertConversion(rhombuses64_s)
  569. rhombuses64_n = fun.invertConversion(rhombuses64_n)
  570. rhombuses128_s = fun.invertConversion(rhombuses128_s)
  571. rhombuses128_n = fun.invertConversion(rhombuses128_n)
  572.  
  573. rectangles16_s = fun.invertConversion(rectangles16_s)
  574. rectangles16_n = fun.invertConversion(rectangles16_n)
  575. rectangles32_s = fun.invertConversion(rectangles32_s)
  576. rectangles32_n = fun.invertConversion(rectangles32_n)
  577. rectangles64_s = fun.invertConversion(rectangles64_s)
  578. rectangles64_n = fun.invertConversion(rectangles64_n)
  579. rectangles128_s = fun.invertConversion(rectangles128_s)
  580. rectangles128_n = fun.invertConversion(rectangles128_n)
  581.  
  582. lines16_s = fun.invertConversion(lines16_s)
  583. lines16_n = fun.invertConversion(lines16_n)
  584. lines32_s = fun.invertConversion(lines32_s)
  585. lines32_n = fun.invertConversion(lines32_n)
  586. lines64_s = fun.invertConversion(lines64_s)
  587. lines64_n = fun.invertConversion(lines64_n)
  588. lines128_s = fun.invertConversion(lines128_s)
  589. lines128_n = fun.invertConversion(lines128_n)
  590.  
  591. hexagons16_s = fun.invertConversion(hexagons16_s)
  592. hexagons16_n = fun.invertConversion(hexagons16_n)
  593. hexagons32_s = fun.invertConversion(hexagons32_s)
  594. hexagons32_n = fun.invertConversion(hexagons32_n)
  595. hexagons64_s = fun.invertConversion(hexagons64_s)
  596. hexagons64_n = fun.invertConversion(hexagons64_n)
  597. hexagons128_s = fun.invertConversion(hexagons128_s)
  598. hexagons128_n = fun.invertConversion(hexagons128_n)
  599.  
  600. ellipsis16_s = fun.invertConversion(ellipsis16_s)
  601. ellipsis16_n = fun.invertConversion(ellipsis16_n)
  602. ellipsis32_s = fun.invertConversion(ellipsis32_s)
  603. ellipsis32_n = fun.invertConversion(ellipsis32_n)
  604. ellipsis64_s = fun.invertConversion(ellipsis64_s)
  605. ellipsis64_n = fun.invertConversion(ellipsis64_n)
  606. ellipsis128_s = fun.invertConversion(ellipsis128_s)
  607. ellipsis128_n = fun.invertConversion(ellipsis128_n)
  608. print('terminou pre processing')
  609.  
  610. # extraindo caracteristicas das imagens
  611.  
  612. squares128_vector_s = fun.extratorCaracteristicas(squares128_s)
  613. squares128_vector_n = fun.extratorCaracteristicas(squares128_n)
  614. circles128_vector_s = fun.extratorCaracteristicas(circles128_s)
  615. circles128_vector_n = fun.extratorCaracteristicas(circles128_n)
  616. triangles128_vector_s = fun.extratorCaracteristicas(triangles128_s)
  617. triangles128_vector_n = fun.extratorCaracteristicas(triangles128_n)
  618. trapezia128_vector_s = fun.extratorCaracteristicas(trapezia128_s)
  619. trapezia128_vector_n = fun.extratorCaracteristicas(trapezia128_n)
  620. rhombuses128_vector_s = fun.extratorCaracteristicas(rhombuses128_s)
  621. rhombuses128_vector_n = fun.extratorCaracteristicas(rhombuses128_n)
  622. rectangles128_vector_s = fun.extratorCaracteristicas(rectangles128_s)
  623. rectangles128_vector_n = fun.extratorCaracteristicas(rectangles128_n)
  624. lines128_vector_s = fun.extratorCaracteristicas(lines128_s)
  625. lines128_vector_n = fun.extratorCaracteristicas(lines128_n)
  626. hexagons128_vector_s = fun.extratorCaracteristicas(hexagons128_s)
  627. hexagons128_vector_n = fun.extratorCaracteristicas(hexagons128_n)
  628. ellipsis128_vector_s = fun.extratorCaracteristicas(ellipsis128_s)
  629. ellipsis128_vector_n = fun.extratorCaracteristicas(ellipsis128_n)
  630.  
  631. squares64_vector_s = fun.extratorCaracteristicas(squares64_s)
  632. squares64_vector_n = fun.extratorCaracteristicas(squares64_n)
  633. circles64_vector_s = fun.extratorCaracteristicas(circles64_s)
  634. circles64_vector_n = fun.extratorCaracteristicas(circles64_n)
  635. triangles64_vector_s = fun.extratorCaracteristicas(triangles64_s)
  636. triangles64_vector_n = fun.extratorCaracteristicas(triangles64_n)
  637. trapezia64_vector_s = fun.extratorCaracteristicas(trapezia64_s)
  638. trapezia64_vector_n = fun.extratorCaracteristicas(trapezia64_n)
  639. rhombuses64_vector_s = fun.extratorCaracteristicas(rhombuses64_s)
  640. rhombuses64_vector_n = fun.extratorCaracteristicas(rhombuses64_n)
  641. rectangles64_vector_s = fun.extratorCaracteristicas(rectangles64_s)
  642. rectangles64_vector_n = fun.extratorCaracteristicas(rectangles64_n)
  643. lines64_vector_s = fun.extratorCaracteristicas(lines64_s)
  644. lines64_vector_n = fun.extratorCaracteristicas(lines64_n)
  645. hexagons64_vector_s = fun.extratorCaracteristicas(hexagons64_s)
  646. hexagons64_vector_n = fun.extratorCaracteristicas(hexagons64_n)
  647. ellipsis64_vector_s = fun.extratorCaracteristicas(ellipsis64_s)
  648. ellipsis64_vector_n = fun.extratorCaracteristicas(ellipsis64_n)
  649.  
  650. squares32_vector_s = fun.extratorCaracteristicas(squares32_s)
  651. squares32_vector_n = fun.extratorCaracteristicas(squares32_n)
  652. circles32_vector_s = fun.extratorCaracteristicas(circles32_s)
  653. circles32_vector_n = fun.extratorCaracteristicas(circles32_n)
  654. triangles32_vector_s = fun.extratorCaracteristicas(triangles32_s)
  655. triangles32_vector_n = fun.extratorCaracteristicas(triangles32_n)
  656. trapezia32_vector_s = fun.extratorCaracteristicas(trapezia32_s)
  657. trapezia32_vector_n = fun.extratorCaracteristicas(trapezia32_n)
  658. rhombuses32_vector_s = fun.extratorCaracteristicas(rhombuses32_s)
  659. rhombuses32_vector_n = fun.extratorCaracteristicas(rhombuses32_n)
  660. rectangles32_vector_s = fun.extratorCaracteristicas(rectangles32_s)
  661. rectangles32_vector_n = fun.extratorCaracteristicas(rectangles32_n)
  662. lines32_vector_s = fun.extratorCaracteristicas(lines32_s)
  663. lines32_vector_n = fun.extratorCaracteristicas(lines32_n)
  664. hexagons32_vector_s = fun.extratorCaracteristicas(hexagons32_s)
  665. hexagons32_vector_n = fun.extratorCaracteristicas(hexagons32_n)
  666. ellipsis32_vector_s = fun.extratorCaracteristicas(ellipsis32_s)
  667. ellipsis32_vector_n = fun.extratorCaracteristicas(ellipsis32_n)
  668.  
  669.  
  670. squares16_vector_s = fun.extratorCaracteristicas(squares16_s)
  671. squares16_vector_n = fun.extratorCaracteristicas(squares16_n)
  672. circles16_vector_s = fun.extratorCaracteristicas(circles16_s)
  673. circles16_vector_n = fun.extratorCaracteristicas(circles16_n)
  674. triangles16_vector_s = fun.extratorCaracteristicas(triangles16_s)
  675. triangles16_vector_n = fun.extratorCaracteristicas(triangles16_n)
  676. trapezia16_vector_s = fun.extratorCaracteristicas(trapezia16_s)
  677. trapezia16_vector_n = fun.extratorCaracteristicas(trapezia16_n)
  678. rhombuses16_vector_s = fun.extratorCaracteristicas(rhombuses16_s)
  679. rhombuses16_vector_n = fun.extratorCaracteristicas(rhombuses16_n)
  680. rectangles16_vector_s = fun.extratorCaracteristicas(rectangles16_s)
  681. rectangles16_vector_n = fun.extratorCaracteristicas(rectangles16_n)
  682. lines16_vector_s = fun.extratorCaracteristicas(lines16_s)
  683. lines16_vector_n = fun.extratorCaracteristicas(lines16_n)
  684. hexagons16_vector_s = fun.extratorCaracteristicas(hexagons16_s)
  685. hexagons16_vector_n = fun.extratorCaracteristicas(hexagons16_n)
  686. ellipsis16_vector_s = fun.extratorCaracteristicas(ellipsis16_s)
  687. ellipsis16_vector_n = fun.extratorCaracteristicas(ellipsis16_n)
  688.  
  689.  
  690. print('terminou extracao carac')
  691.  
  692. # transformando os vetores em dataframes
  693.  
  694.  
  695. squares128_vector_s = pd.DataFrame(squares128_vector_s)
  696. squares128_vector_n = pd.DataFrame(squares128_vector_n)
  697. circles128_vector_s = pd.DataFrame(circles128_vector_s)
  698. circles128_vector_n = pd.DataFrame(circles128_vector_n)
  699. triangles128_vector_s = pd.DataFrame(triangles128_vector_s)
  700. triangles128_vector_n = pd.DataFrame(triangles128_vector_n)
  701. trapezia128_vector_s = pd.DataFrame(trapezia128_vector_s)
  702. trapezia128_vector_n = pd.DataFrame(trapezia128_vector_n)
  703. rhombuses128_vector_s = pd.DataFrame(rhombuses128_vector_s)
  704. rhombuses128_vector_n = pd.DataFrame(rhombuses128_vector_n)
  705. rectangles128_vector_s = pd.DataFrame(rectangles128_vector_s)
  706. rectangles128_vector_n = pd.DataFrame(rectangles128_vector_n)
  707. lines128_vector_s = pd.DataFrame(lines128_vector_s)
  708. lines128_vector_n = pd.DataFrame(lines128_vector_n)
  709. hexagons128_vector_s = pd.DataFrame(hexagons128_vector_s)
  710. hexagons128_vector_n = pd.DataFrame(hexagons128_vector_n)
  711. ellipsis128_vector_s = pd.DataFrame(ellipsis128_vector_s)
  712. ellipsis128_vector_n = pd.DataFrame(ellipsis128_vector_n)
  713.  
  714. squares32_vector_s = pd.DataFrame(squares32_vector_s)
  715. squares32_vector_n = pd.DataFrame(squares32_vector_n)
  716. circles32_vector_s = pd.DataFrame(circles32_vector_s)
  717. circles32_vector_n = pd.DataFrame(circles32_vector_n)
  718. triangles32_vector_s = pd.DataFrame(triangles32_vector_s)
  719. triangles32_vector_n = pd.DataFrame(triangles32_vector_n)
  720. trapezia32_vector_s = pd.DataFrame(trapezia32_vector_s)
  721. trapezia32_vector_n = pd.DataFrame(trapezia32_vector_n)
  722. rhombuses32_vector_s = pd.DataFrame(rhombuses32_vector_s)
  723. rhombuses32_vector_n = pd.DataFrame(rhombuses32_vector_n)
  724. rectangles32_vector_s = pd.DataFrame(rectangles32_vector_s)
  725. rectangles32_vector_n = pd.DataFrame(rectangles32_vector_n)
  726. hexagons32_vector_s = pd.DataFrame(hexagons32_vector_s)
  727. hexagons32_vector_n = pd.DataFrame(hexagons32_vector_n)
  728. ellipsis32_vector_s = pd.DataFrame(ellipsis32_vector_s)
  729. ellipsis32_vector_n = pd.DataFrame(ellipsis32_vector_n)
  730. lines32_vector_s = pd.DataFrame(lines32_vector_s)
  731. lines32_vector_n = pd.DataFrame(lines32_vector_n)
  732.  
  733. squares64_vector_s = pd.DataFrame(squares64_vector_s)
  734. squares64_vector_n = pd.DataFrame(squares64_vector_n)
  735. circles64_vector_s = pd.DataFrame(circles64_vector_s)
  736. circles64_vector_n = pd.DataFrame(circles64_vector_n)
  737. triangles64_vector_s = pd.DataFrame(triangles64_vector_s)
  738. triangles64_vector_n = pd.DataFrame(triangles64_vector_n)
  739. trapezia64_vector_s = pd.DataFrame(trapezia64_vector_s)
  740. trapezia64_vector_n = pd.DataFrame(trapezia64_vector_n)
  741. rhombuses64_vector_s = pd.DataFrame(rhombuses64_vector_s)
  742. rhombuses64_vector_n = pd.DataFrame(rhombuses64_vector_n)
  743. rectangles64_vector_s = pd.DataFrame(rectangles64_vector_s)
  744. rectangles64_vector_n = pd.DataFrame(rectangles64_vector_n)
  745. lines64_vector_s = pd.DataFrame(lines64_vector_s)
  746. lines64_vector_n = pd.DataFrame(lines64_vector_n)
  747. hexagons64_vector_s = pd.DataFrame(hexagons64_vector_s)
  748. hexagons64_vector_n = pd.DataFrame(hexagons64_vector_n)
  749. ellipsis64_vector_s = pd.DataFrame(ellipsis64_vector_s)
  750. ellipsis64_vector_n = pd.DataFrame(ellipsis64_vector_n)
  751.  
  752.  
  753. circles16_vector_s = pd.DataFrame(circles16_vector_s)
  754. circles16_vector_n = pd.DataFrame(circles16_vector_n)
  755. squares16_vector_s = pd.DataFrame(squares16_vector_s)
  756. squares16_vector_n = pd.DataFrame(squares16_vector_n)
  757. triangles16_vector_s = pd.DataFrame(triangles16_vector_s)
  758. triangles16_vector_n = pd.DataFrame(triangles16_vector_n)
  759. trapezia16_vector_s = pd.DataFrame(trapezia16_vector_s)
  760. trapezia16_vector_n = pd.DataFrame(trapezia16_vector_n)
  761. rhombuses16_vector_s = pd.DataFrame(rhombuses16_vector_s)
  762. rhombuses16_vector_n = pd.DataFrame(rhombuses16_vector_n)
  763. rectangles16_vector_s = pd.DataFrame(rectangles16_vector_s)
  764. rectangles16_vector_n = pd.DataFrame(rectangles16_vector_n)
  765. lines16_vector_s = pd.DataFrame(lines16_vector_s)
  766. lines16_vector_n = pd.DataFrame(lines16_vector_n)
  767. hexagons16_vector_s = pd.DataFrame(hexagons16_vector_s)
  768. hexagons16_vector_n = pd.DataFrame(hexagons16_vector_n)
  769. ellipsis16_vector_s = pd.DataFrame(ellipsis16_vector_s)
  770. ellipsis16_vector_n = pd.DataFrame(ellipsis16_vector_n)
  771.  
  772.  
  773. print('terminou transformar em dataframe')
  774.  
  775. #incluindo a classe nos dataframes
  776.  
  777. squares128_vector_s['Classe'] = 'square'
  778. squares128_vector_n['Classe'] = 'square'
  779. circles128_vector_s['Classe'] = 'circle'
  780. circles128_vector_n['Classe'] = 'circle'
  781. triangles128_vector_s['Classe'] = 'triangle'
  782. triangles128_vector_n['Classe'] = 'triangle'
  783. trapezia128_vector_s['Classe'] = 'trapezia'
  784. trapezia128_vector_n['Classe'] = 'trapezia'
  785. rhombuses128_vector_s['Classe'] = 'rhombuse'
  786. rhombuses128_vector_n['Classe'] = 'rhombuse'
  787. rectangles128_vector_s['Classe'] = 'rectangle'
  788. rectangles128_vector_n['Classe'] = 'rectangle'
  789. lines128_vector_s['Classe'] = 'line'
  790. lines128_vector_n['Classe'] = 'line'
  791. hexagons128_vector_s['Classe'] = 'hexagon'
  792. hexagons128_vector_n['Classe'] = 'hexagon'
  793. ellipsis128_vector_s['Classe'] = 'ellipse'
  794. ellipsis128_vector_n['Classe'] = 'ellipse'
  795.  
  796. squares32_vector_s['Classe'] = 'square'
  797. squares32_vector_n['Classe'] = 'square'
  798. circles32_vector_s['Classe'] = 'circle'
  799. circles32_vector_n['Classe'] = 'circle'
  800. triangles32_vector_s['Classe'] = 'triangle'
  801. triangles32_vector_n['Classe'] = 'triangle'
  802. trapezia32_vector_s['Classe'] = 'trapezia'
  803. trapezia32_vector_n['Classe'] = 'trapezia'
  804. rhombuses32_vector_s['Classe'] = 'rhombuse'
  805. rhombuses32_vector_n['Classe'] = 'rhombuse'
  806. rectangles32_vector_s['Classe'] = 'rectangle'
  807. rectangles32_vector_n['Classe'] = 'rectangle'
  808. lines32_vector_s['Classe'] = 'line'
  809. lines32_vector_n['Classe'] = 'line'
  810. hexagons32_vector_s['Classe'] = 'hexagon'
  811. hexagons32_vector_n['Classe'] = 'hexagon'
  812. ellipsis32_vector_s['Classe'] = 'ellipse'
  813. ellipsis32_vector_n['Classe'] = 'ellipse'
  814.  
  815. squares64_vector_s['Classe'] = 'square'
  816. squares64_vector_n['Classe'] = 'square'
  817. circles64_vector_s['Classe'] = 'circle'
  818. circles64_vector_n['Classe'] = 'circle'
  819. triangles64_vector_s['Classe'] = 'triangle'
  820. triangles64_vector_n['Classe'] = 'triangle'
  821. trapezia64_vector_s['Classe'] = 'trapezia'
  822. trapezia64_vector_n['Classe'] = 'trapezia'
  823. rhombuses64_vector_s['Classe'] = 'rhombuse'
  824. rhombuses64_vector_n['Classe'] = 'rhombuse'
  825. rectangles64_vector_s['Classe'] = 'rectangle'
  826. rectangles64_vector_n['Classe'] = 'rectangle'
  827. lines64_vector_s['Classe'] = 'line'
  828. lines64_vector_n['Classe'] = 'line'
  829. hexagons64_vector_s['Classe'] = 'hexagon'
  830. hexagons64_vector_n['Classe'] = 'hexagon'
  831. ellipsis64_vector_s['Classe'] = 'ellipse'
  832. ellipsis64_vector_n['Classe'] = 'ellipse'
  833.  
  834.  
  835. squares16_vector_s['Classe'] = 'square'
  836. squares16_vector_n['Classe'] = 'square'
  837. circles16_vector_s['Classe'] = 'circle'
  838. circles16_vector_n['Classe'] = 'circle'
  839. triangles16_vector_s['Classe'] = 'triangle'
  840. triangles16_vector_n['Classe'] = 'triangle'
  841. trapezia16_vector_s['Classe'] = 'trapezia'
  842. trapezia16_vector_n['Classe'] = 'trapezia'
  843. rhombuses16_vector_s['Classe'] = 'rhombuse'
  844. rhombuses16_vector_n['Classe'] = 'rhombuse'
  845. rectangles16_vector_s['Classe'] = 'rectangle'
  846. rectangles16_vector_n['Classe'] = 'rectangle'
  847. lines16_vector_s['Classe'] = 'line'
  848. lines16_vector_n['Classe'] = 'line'
  849. hexagons16_vector_s['Classe'] = 'hexagon'
  850. hexagons16_vector_n['Classe'] = 'hexagon'
  851. ellipsis16_vector_s['Classe'] = 'ellipse'
  852. ellipsis16_vector_n['Classe'] = 'ellipse'
  853.  
  854.  
  855.  
  856. dfs64_s = [squares64_vector_s,circles64_vector_s,triangles64_vector_s,trapezia64_vector_s,rhombuses64_vector_s,
  857.          rectangles64_vector_s,lines64_vector_s,hexagons64_vector_s,ellipsis64_vector_s]
  858.  
  859. dfs64_n = [squares64_vector_n,circles64_vector_n,triangles64_vector_n,trapezia64_vector_n,rhombuses64_vector_n,
  860.          rectangles64_vector_n,lines64_vector_n,hexagons64_vector_n,ellipsis64_vector_n]
  861.  
  862. dfs128_s = [squares128_vector_s,circles128_vector_s,triangles128_vector_s,trapezia128_vector_s,rhombuses128_vector_s,
  863.           rectangles128_vector_s,lines128_vector_s,hexagons128_vector_s,ellipsis128_vector_s]
  864.  
  865. dfs128_n = [squares128_vector_n,circles128_vector_n,triangles128_vector_n,trapezia128_vector_n,rhombuses128_vector_n,
  866.           rectangles128_vector_n,lines128_vector_n,hexagons128_vector_n,ellipsis128_vector_n]
  867.  
  868. dfs32_s = [squares32_vector_s,circles32_vector_s,triangles32_vector_s,trapezia32_vector_s,rhombuses32_vector_s,
  869.          rectangles32_vector_s,lines32_vector_s,hexagons32_vector_s,ellipsis32_vector_s]
  870.  
  871. dfs32_n = [squares32_vector_n,circles32_vector_n,triangles32_vector_n,trapezia32_vector_n,rhombuses32_vector_n,
  872.          rectangles32_vector_n,lines32_vector_n,hexagons32_vector_n,ellipsis32_vector_n]
  873.  
  874. dfs16_s = [squares16_vector_s,circles16_vector_s,triangles16_vector_s,trapezia16_vector_s,rhombuses16_vector_s,
  875.        rectangles16_vector_s,lines16_vector_s,hexagons16_vector_s,ellipsis16_vector_s]
  876. dfs16_n = [squares16_vector_n,circles16_vector_n,triangles16_vector_n,trapezia16_vector_n,rhombuses16_vector_n,
  877.        rectangles16_vector_n,lines16_vector_n,hexagons16_vector_n,ellipsis16_vector_n]
  878.  
  879.  
  880.  
  881. # USANDO AS IMAGENS 128x128
  882.  
  883. dataFrame128_s = pd.concat(dfs128_s, ignore_index=True)
  884. dataFrame128_2_s = dataFrame128_s.copy()
  885. del dataFrame128_s['Classe']
  886. dataFrame128_s.to_csv('C:/Users/Auricelia/Desktop/DataSetsML/Images_128_s_NOCLASS.csv')
  887. dataFrame128_s = fun.normalizar(dataFrame128_s)
  888. dataFrame128_s.fillna(0)
  889. dataFrame128_s['Classe'] = dataFrame128_2_s['Classe']
  890. dataFrame128_s.to_csv('C:/Users/Auricelia/Desktop/DataSetsML/Images_128_s.csv')
  891.  
  892. dataFrame128_n = pd.concat(dfs128_n, ignore_index=True)
  893. dataFrame128_n.to_csv('C:/Users/Auricelia/Desktop/DataSetsML/Images_128_n.csv')
  894. dataFrame128_2_n = dataFrame128_n.copy()
  895. del dataFrame128_n['Classe']
  896. dataFrame128_n = fun.normalizar(dataFrame128_n)
  897. dataFrame128_n.fillna(0)
  898. dataFrame128_n['Classe'] = dataFrame128_2_n['Classe']
  899.  
  900. dataFrame64_s = pd.concat(dfs64_s, ignore_index=True)
  901. print(dataFrame64_s)
  902. dataFrame64_s = dataFrame64_s.fillna(0)
  903. print(dataFrame64_s)
  904. dataFrame64_2_s = dataFrame64_s.copy()
  905. del dataFrame64_s['Classe']
  906. dataFrame64_s.to_csv('C:/Users/Auricelia/Desktop/DataSetsML/Images_64_sNOCLASS.csv')
  907. dataFrame64_s = fun.normalizar(dataFrame64_s)
  908. dataFrame64_s['Classe'] = dataFrame64_2_s['Classe']
  909. dataFrame64_s.to_csv('C:/Users/Auricelia/Desktop/DataSetsML/Images_64_s.csv')
  910.  
  911. dataFrame64_n = pd.concat(dfs64_n, ignore_index=True)
  912. print(dataFrame64_n)
  913. dataFrame64_n.to_csv('C:/Users/Auricelia/Desktop/DataSetsML/Images_64_n.csv')
  914. dataFrame64_n = dataFrame64_n.fillna(0)
  915. print(dataFrame64_n)
  916. dataFrame64_2_n = dataFrame64_n.copy()
  917. del dataFrame64_n['Classe']
  918. dataFrame64_n = fun.normalizar(dataFrame64_n)
  919. dataFrame64_n['Classe'] = dataFrame64_2_n['Classe']
  920.  
  921. dataFrame32_s = pd.concat(dfs32_s, ignore_index=True)
  922. dataFrame32_s = dataFrame32_s.fillna(0)
  923. dataFrame32_2_s = dataFrame32_s.copy()
  924. del dataFrame32_s['Classe']
  925. dataFrame32_s.to_csv('C:/Users/Auricelia/Desktop/DataSetsML/Images_32_sNOCLASS.csv')
  926. dataFrame32_s = fun.normalizar(dataFrame32_s)
  927. dataFrame32_s['Classe'] = dataFrame32_2_s['Classe']
  928. dataFrame32_s.to_csv('C:/Users/Auricelia/Desktop/DataSetsML/Images_32_s.csv')
  929.  
  930. dataFrame32_n = pd.concat(dfs32_n, ignore_index=True)
  931. dataFrame32_n.to_csv('C:/Users/Auricelia/Desktop/DataSetsML/Images_32_n.csv')
  932. dataFrame32_n = dataFrame32_n.fillna(0)
  933. dataFrame32_2_n = dataFrame32_n.copy()
  934. del dataFrame32_n['Classe']
  935. dataFrame32_n = fun.normalizar(dataFrame32_n)
  936. dataFrame32_n['Classe'] = dataFrame32_2_n['Classe']
  937.  
  938. dataFrame16_s = pd.concat(dfs16_s, ignore_index=True)
  939. dataFrame16_s = dataFrame16_s.fillna(0)
  940. dataFrame16_2_s = dataFrame16_s.copy()
  941. del dataFrame16_s['Classe']
  942. dataFrame16_s.to_csv('C:/Users/Auricelia/Desktop/DataSetsML/Images_16_sNOCLASS.csv')
  943. dataFrame16_s = fun.normalizar(dataFrame16_s)
  944. dataFrame16_s['Classe'] = dataFrame16_2_s['Classe']
  945. dataFrame16_s.to_csv('C:/Users/Auricelia/Desktop/DataSetsML/Images_16_s.csv')
  946.  
  947. dataFrame16_n = pd.concat(dfs16_n, ignore_index=True)
  948. dataFrame16_n.to_csv('C:/Users/Auricelia/Desktop/DataSetsML/Images_16_n.csv')
  949. dataFrame16_n = dataFrame16_n.fillna(0)
  950. dataFrame16_2_n = dataFrame16_n.copy()
  951. del dataFrame16_n['Classe']
  952. dataFrame16_n = fun.normalizar(dataFrame16_n)
  953. dataFrame16_n['Classe'] = dataFrame16_2_n['Classe']
  954.  
  955. # Criando o objeto do tipo k-folds com 10 folds
  956. # kfold = KFold(10, True, 1)
  957.  
  958.  
  959. # Criando o k-fold com 5 folds para execução do algoritmo genético
  960. kfold = KFold(5, True, 1)
  961.  
  962. #Inicializando o Classificador do algoritmo genético
  963.  
  964. # Random Forest Classifier
  965. RandomForest = RandomForestClassifier()
  966. RandomForest_acerto = []
  967. # RandomForest_tempo = []
  968. # RandomForest_precision = []
  969. # RandomForest_recall = []
  970. # RandomForest_fscore = []
  971.  
  972. #criando a população com 20 cromossomos de tamanho 38
  973. cromossomos = fun.create_population(20, 38)
  974.  
  975. for cromo in cromossomos:
  976.     positions = fun.positions_chromossome(cromo)
  977.     imagens, df_classe = fun.decode_chromossome(cromo)
  978.     imagens = np.array(imagens)
  979.     caracteristicas = fun.carac_imagens(positions, imagens)
  980.  
  981.     for x in range(0, 10):
  982.  
  983.         tempo1 = time.time()
  984.         cols = list(df_classe.columns)
  985.         cols.remove('Classe')
  986.         df_images_noclass = df_classe[cols]
  987.         df_images_class = df_classe['Classe']
  988.         c = kfold.split(df_classe)
  989.  
  990.         for train_index, test_index in c:
  991.  
  992.             noclass_train, noclass_test = df_images_noclass.iloc[train_index], df_images_noclass.iloc[test_index]
  993.             class_train, class_test = df_images_class.iloc[train_index], df_images_class.iloc[test_index]
  994.  
  995.             RandomForest_inicio = time.time()
  996.             RandomForest.fit(noclass_train, class_train)
  997.             RandomForest_acerto.append(RandomForest.score(noclass_test, class_test))
  998.  
  999.  
  1000.         df_classe = df_classe.sample(frac=1)
  1001.         print("Terminou a ", x)
  1002.         tempo2 = time.time()
  1003.         print("Tempo da rodada ", x, (tempo2 - tempo1) / 60)
  1004.  
  1005.     tempofinal = time.time()
  1006.  
  1007. print('acuracia media ',np.mean(RandomForest_acerto))
  1008. print('acuracia' )
  1009. print(RandomForest_acerto)
  1010. # Instanciando os algoritmos e seus vetores de tempo e acurácia
  1011. '''
  1012. #instanciando DataFrame com dados de saida
  1013. DadosSaida = []
  1014. DadosSaida = pd.DataFrame(DadosSaida)
  1015.  
  1016.  
  1017. # Random Forest Classifier
  1018. RandomForest = RandomForestClassifier()
  1019. RandomForest_acerto = []
  1020. RandomForest_tempo = []
  1021. RandomForest_precision = []
  1022. RandomForest_recall = []
  1023. RandomForest_fscore = []
  1024.  
  1025. # SVM com função de kernel linear
  1026. SVMachine_L = SVC(kernel='linear')
  1027. SVMachine_L_acerto = []
  1028. SVMachine_L_tempo = []
  1029. SVMachine_L_precision = []
  1030. SVMachine_L_recall = []
  1031. SVMachine_L_fscore = []
  1032.  
  1033. #SVM com função de kernel RBF
  1034. SVMachine_RBF = SVC(kernel='rbf', gamma='scale')
  1035. SVMachine_RBF_acerto = []
  1036. SVMachine_RBF_tempo = []
  1037. SVMachine_RBF_precision = []
  1038. SVMachine_RBF_recall = []
  1039. SVMachine_RBF_fscore = []
  1040.  
  1041. # KNN com k = 3, 5, 7
  1042. KNN_3 = KNeighborsClassifier(n_neighbors=3, metric='euclidean')
  1043. KNN_3_acerto = []
  1044. KNN_3_tempo = []
  1045. KNN_3_precision = []
  1046. KNN_3_recall = []
  1047. KNN_3_fscore = []
  1048.  
  1049. KNN_5 = KNeighborsClassifier(n_neighbors=5, metric='euclidean')
  1050. KNN_5_acerto = []
  1051. KNN_5_tempo = []
  1052. KNN_5_precision = []
  1053. KNN_5_recall = []
  1054. KNN_5_fscore = []
  1055.  
  1056. KNN_7 =  KNeighborsClassifier(n_neighbors=7, metric='euclidean')
  1057. KNN_7_acerto = []
  1058. KNN_7_tempo = []
  1059. KNN_7_precision = []
  1060. KNN_7_recall = []
  1061. KNN_7_fscore = []
  1062.  
  1063. # KNN Ponderado com k = 3, 5, 7
  1064. KNNP_3 = KNeighborsClassifier(n_neighbors=3, weights='distance',metric='euclidean')
  1065. KNNP_3_acerto = []
  1066. KNNP_3_tempo = []
  1067. KNNP_3_precision = []
  1068. KNNP_3_recall = []
  1069. KNNP_3_fscore = []
  1070.  
  1071. KNNP_5 = KNeighborsClassifier(n_neighbors=5, weights='distance', metric='euclidean')
  1072. KNNP_5_acerto = []
  1073. KNNP_5_tempo = []
  1074. KNNP_5_precision = []
  1075. KNNP_5_recall = []
  1076. KNNP_5_fscore = []
  1077.  
  1078. KNNP_7 = KNeighborsClassifier(n_neighbors=7, weights='distance', metric='euclidean')
  1079. KNNP_7_acerto = []
  1080. KNNP_7_tempo = []
  1081. KNNP_7_precision = []
  1082. KNNP_7_recall = []
  1083. KNNP_7_fscore = []
  1084.  
  1085. # Naïve Bayes
  1086. NaiveBayes = GaussianNB()
  1087. NaiveBayes_acerto = []
  1088. NaiveBayes_tempo = []
  1089. NaiveBayes_precision = []
  1090. NaiveBayes_recall = []
  1091. NaiveBayes_fscore = []
  1092.  
  1093. # Árvore de decisão
  1094. DecisionTree = DecisionTreeClassifier()
  1095. DecisionTree_acerto = []
  1096. DecisionTree_tempo = []
  1097. DecisionTree_precision = []
  1098. DecisionTree_recall = []
  1099. DecisionTree_fscore = []
  1100.  
  1101. # MultiLayer Perceptron
  1102. MLP = MLPClassifier()
  1103. MLP_acerto = []
  1104. MLP_tempo = []
  1105. MLPP_precision = []
  1106. MLP_recall = []
  1107. MLP_fscore = []
  1108.  
  1109. # Regressão Logística
  1110. RegrLogistica = LogisticRegression(solver='lbfgs')
  1111. RegrLogistica_acerto = []
  1112. RegrLogistica_tempo = []
  1113. RegreLogistica_precision = []
  1114. RegrLogistica_recall = []
  1115. RegrLogistica_fscore = []
  1116.  
  1117. # ____________________ USANDO IMAGENS 128x128
  1118.  
  1119. print('comecou o K fold')
  1120.  
  1121. tempoinicial = time.time()
  1122.  
  1123. for x in range(0, 10):
  1124.  
  1125.    tempo1 = time.time()
  1126.    cols = list(dataFrame128.columns)
  1127.    cols.remove('Classe')
  1128.    df_images_noclass = dataFrame128[cols]
  1129.    df_images_class = dataFrame128['Classe']
  1130.    c = kfold.split(dataFrame128)
  1131.  
  1132.    for train_index, test_index in c:
  1133.  
  1134.        noclass_train, noclass_test = df_images_noclass.iloc[train_index], df_images_noclass.iloc[test_index]
  1135.        class_train, class_test = df_images_class.iloc[train_index], df_images_class.iloc[test_index]
  1136.  
  1137.        KNN3_inicio = time.time()
  1138.        KNN_3.fit(noclass_train, class_train)
  1139.        KNN_3_acerto.append(KNN_3.score(noclass_test, class_test))
  1140.        KNN_3_recall. append(recall_score(class_test, KNN_3.predict(noclass_test),average='weighted'))
  1141.        KNN_3_precision.append(precision_score(class_test,KNN_3.predict(noclass_test),average='weighted'))
  1142.        KNN_3_fscore.append(f1_score(class_test,KNN_3.predict(noclass_test),average='weighted'))
  1143.        KNN3_fim = time.time()
  1144.        KNN_3_tempo.append(KNN3_fim - KNN3_inicio)
  1145.  
  1146.        KNN5_inicio = time.time()
  1147.        KNN_5.fit(noclass_train, class_train)
  1148.        KNN_5_acerto.append(KNN_5.score(noclass_test, class_test))
  1149.        KNN_5_recall.append(recall_score(class_test,KNN_5.predict(noclass_test),average='weighted'))
  1150.        KNN_5_precision.append(precision_score(class_test,KNN_5.predict(noclass_test),average='weighted'))
  1151.        KNN_5_fscore.append(f1_score(class_test,KNN_5.predict(noclass_test),average='weighted'))
  1152.        KNN5_fim = time.time()
  1153.        KNN_5_tempo.append(KNN5_fim - KNN5_inicio)
  1154.  
  1155.  
  1156.  
  1157.        KNN7_inicio = time.time()
  1158.        KNN_7.fit(noclass_train, class_train)
  1159.        KNN_7_acerto.append(KNN_3.score(noclass_test, class_test))
  1160.        KNN_7_precision.append(precision_score(class_test,KNN_7.predict(noclass_test),average='weighted'))
  1161.        KNN_7_recall.append(recall_score(class_test,KNN_7.predict(noclass_test),average='weighted'))
  1162.        KNN_7_fscore.append(f1_score(class_test,KNN_7.predict(noclass_test),average='weighted'))
  1163.        KNN7_fim = time.time()
  1164.        KNN_7_tempo.append(KNN3_fim - KNN3_inicio)
  1165.  
  1166.        KNNP3_inicio = time.time()
  1167.        KNNP_3.fit(noclass_train, class_train)
  1168.        KNNP_3_acerto.append(KNNP_3.score(noclass_test, class_test))
  1169.        KNNP_3_precision.append(precision_score(class_test,KNNP_3.predict(noclass_test),average='weighted'))
  1170.        KNNP_3_recall.append(recall_score(class_test,KNNP_3.predict(noclass_test),average='weighted'))
  1171.        KNNP_3_fscore.append(f1_score(class_test,KNNP_3.predict(noclass_test),average='weighted'))
  1172.        KNNP3_fim = time.time()
  1173.        KNNP_3_tempo.append(KNNP3_fim - KNNP3_inicio)
  1174.  
  1175.        KNNP5_inicio = time.time()
  1176.        KNNP_5.fit(noclass_train, class_train)
  1177.        KNNP_5_acerto.append(KNNP_5.score(noclass_test, class_test))
  1178.        KNNP_5_precision.append(precision_score(class_test,KNNP_5.predict(noclass_test),average='weighted'))
  1179.        KNNP_5_recall.append(recall_score(class_test,KNNP_5.predict(noclass_test),average='weighted'))
  1180.        KNNP_5_fscore.append(f1_score(class_test,KNNP_5.predict(noclass_test),average='weighted'))
  1181.        KNNP5_fim = time.time()
  1182.        KNNP_5_tempo.append(KNNP5_fim - KNNP5_inicio)
  1183.  
  1184.        KNNP7_inicio = time.time()
  1185.        KNNP_7.fit(noclass_train, class_train)
  1186.        KNNP_7_acerto.append(KNNP_7.score(noclass_test, class_test))
  1187.        KNNP_7_precision.append(precision_score(class_test,KNNP_7.predict(noclass_test),average='weighted'))
  1188.        KNNP_7_recall.append(recall_score(class_test,KNNP_7.predict(noclass_test),average='weighted'))
  1189.        KNNP_7_fscore.append(f1_score(class_test,KNNP_7.predict(noclass_test),average='weighted'))
  1190.        KNNP7_fim = time.time()
  1191.        KNNP_7_tempo.append(KNNP7_fim - KNNP7_inicio)
  1192.  
  1193.        NaiveBayes_inicio = time.time()
  1194.        NaiveBayes.fit(noclass_train, class_train)
  1195.        NaiveBayes_acerto.append(NaiveBayes.score(noclass_test, class_test))
  1196.        NaiveBayes_precision.append(precision_score(class_test,NaiveBayes.predict(noclass_test),average='weighted'))
  1197.        NaiveBayes_recall.append(recall_score(class_test,NaiveBayes.predict(noclass_test),average='weighted'))
  1198.        NaiveBayes_fscore.append(f1_score(class_test,NaiveBayes.predict(noclass_test),average='weighted'))
  1199.        NaiveBayes_fim = time.time()
  1200.        NaiveBayes_tempo.append(NaiveBayes_fim - NaiveBayes_inicio)
  1201.  
  1202.        DecisionTree_inicio = time.time()
  1203.        DecisionTree.fit(noclass_train, class_train)
  1204.        DecisionTree_acerto.append(DecisionTree.score(noclass_test, class_test))
  1205.        DecisionTree_precision.append(precision_score(class_test,DecisionTree.predict(noclass_test),average='weighted'))
  1206.        DecisionTree_recall.append(recall_score(class_test,DecisionTree.predict(noclass_test),average='weighted'))
  1207.        DecisionTree_fscore.append(f1_score(class_test,DecisionTree.predict(noclass_test),average='weighted'))
  1208.        DecisionTree_fim = time.time()
  1209.        DecisionTree_tempo.append(DecisionTree_fim - DecisionTree_inicio)
  1210.  
  1211.        SVMachine_L_inicio = time.time()
  1212.        SVMachine_L.fit(noclass_train, class_train)
  1213.        SVMachine_L_acerto.append(SVMachine_L.score(noclass_test, class_test))
  1214.        SVMachine_L_precision.append(precision_score(class_test,SVMachine_L.predict(noclass_test),average='weighted'))
  1215.        SVMachine_L_recall.append(recall_score(class_test,SVMachine_L.predict(noclass_test),average='weighted'))
  1216.        SVMachine_L_fscore.append(f1_score(class_test,SVMachine_L.predict(noclass_test),average='weighted'))
  1217.        SVMachine_L_fim = time.time()
  1218.        SVMachine_L_tempo.append(SVMachine_L_fim - SVMachine_L_inicio)
  1219.  
  1220.        SVMachine_RBF_inicio = time.time()
  1221.        SVMachine_RBF.fit(noclass_train, class_train)
  1222.        SVMachine_RBF_acerto.append(SVMachine_RBF.score(noclass_test, class_test))
  1223.        SVMachine_RBF_recall.append(recall_score(class_test,SVMachine_RBF.predict(noclass_test),average='weighted'))
  1224.        SVMachine_RBF_precision.append(precision_score(class_test,SVMachine_RBF.predict(noclass_test),average='weighted'))
  1225.        SVMachine_RBF_fscore.append(f1_score(class_test,SVMachine_RBF.predict(noclass_test),average='weighted'))
  1226.        SVMachine_RBF_fim = time.time()
  1227.        SVMachine_RBF_tempo.append(SVMachine_RBF_fim - SVMachine_RBF_inicio)
  1228.  
  1229.        RegrLogistica_inicio = time.time()
  1230.        RegrLogistica.fit(noclass_train, class_train)
  1231.        RegrLogistica_acerto.append(RegrLogistica.score(noclass_test, class_test))
  1232.        RegreLogistica_precision.append(precision_score(class_test, (RegrLogistica.predict(noclass_test)),average='weighted'))
  1233.        RegrLogistica_recall.append(recall_score(class_test,RegrLogistica.predict(noclass_test),average='weighted'))
  1234.        RegrLogistica_fscore.append(f1_score(class_test,RegrLogistica.predict(noclass_test),average='weighted'))
  1235.        RegrLogistica_fim = time.time()
  1236.        RegrLogistica_tempo.append(RegrLogistica_fim - RegrLogistica_inicio)
  1237.  
  1238.        MLP_inicio = time.time()
  1239.        MLP.fit(noclass_train, class_train)
  1240.        MLP_acerto.append(MLP.score(noclass_test, class_test))
  1241.        MLPP_precision.append(precision_score(class_test,MLP.predict(noclass_test),average='weighted'))
  1242.        MLP_recall.append(recall_score(class_test,MLP.predict(noclass_test),average='weighted'))
  1243.        MLP_fscore.append(f1_score(class_test,MLP.predict(noclass_test),average='weighted'))
  1244.        MLP_fim = time.time()
  1245.        MLP_tempo.append(MLP_fim - MLP_inicio)
  1246.  
  1247.        RandomForest_inicio = time.time()
  1248.        RandomForest.fit(noclass_train, class_train)
  1249.        RandomForest_acerto.append(RandomForest.score(noclass_test, class_test))
  1250.        RandomForest_recall.append(recall_score(class_test,RandomForest.predict(noclass_test),average='weighted'))
  1251.        RandomForest_precision.append(precision_score(class_test,RandomForest.predict(noclass_test),average='weighted'))
  1252.        RandomForest_fscore.append(f1_score(class_test,RandomForest.predict(noclass_test),average='weighted'))
  1253.        RandomForest_fim = time.time()
  1254.        RandomForest_tempo.append(RandomForest_fim - RandomForest_inicio)
  1255.  
  1256.  
  1257.    dataFrame128 = dataFrame128.sample(frac=1)
  1258.    print("Terminou a ", x)
  1259.    tempo2 = time.time()
  1260.    print("Tempo da rodada ", x, (tempo2 - tempo1) / 60)
  1261.  
  1262. tempofinal = time.time()
  1263.  
  1264. fun.tendencia_central('KNN k = 3', KNN_3_acerto, KNN_3_tempo)
  1265. fun.tendencia_central('KNN k = 5', KNN_5_acerto, KNN_5_tempo)
  1266. fun.tendencia_central('KNN k = 7', KNN_7_acerto, KNN_7_tempo)
  1267. fun.tendencia_central('KNN Ponderado k = 3', KNNP_3_acerto, KNNP_3_tempo)
  1268. fun.tendencia_central('KNN Ponderado k = 5', KNNP_5_acerto, KNNP_5_tempo)
  1269. fun.tendencia_central('KNN Ponderado k = 7', KNNP_7_acerto, KNNP_7_tempo)
  1270. fun.tendencia_central('Naïve Bayes', NaiveBayes_acerto, NaiveBayes_tempo)
  1271. fun.tendencia_central('Árvore de decisão', DecisionTree_acerto, DecisionTree_tempo)
  1272. fun.tendencia_central('MLP', MLP_acerto, MLP_tempo)
  1273. fun.tendencia_central('Regressão Logística', RegrLogistica_acerto, RegrLogistica_tempo)
  1274. fun.tendencia_central('SVM linear', SVMachine_L_acerto, SVMachine_L_tempo)
  1275. fun.tendencia_central('SVM RBF', SVMachine_RBF_acerto, SVMachine_RBF_tempo)
  1276. fun.tendencia_central('Random Forest', RandomForest_acerto,RandomForest_tempo)
  1277.  
  1278. Acuracia128 = [KNN_3_acerto,KNN_5_acerto,KNN_7_acerto,KNNP_3_acerto,KNNP_5_acerto,KNNP_7_acerto,
  1279.               NaiveBayes_acerto,DecisionTree_acerto,MLP_acerto,RegrLogistica_acerto,SVMachine_L_acerto,
  1280.               SVMachine_RBF_acerto,RandomForest_acerto]
  1281. Precision128 = [KNN_3_precision,KNN_5_precision,KNN_7_precision,KNNP_3_precision,KNNP_5_precision,KNNP_7_precision,
  1282.         NaiveBayes_precision,DecisionTree_precision,MLPP_precision,RegreLogistica_precision,SVMachine_L_precision,
  1283.         SVMachine_RBF_precision,RandomForest_precision]
  1284. Recall128 = [KNN_3_recall,KNN_5_recall,KNN_7_recall,KNNP_3_recall,KNNP_5_recall,KNNP_7_recall,NaiveBayes_recall,
  1285.          DecisionTree_recall,MLP_recall,RegrLogistica_recall,SVMachine_L_recall,SVMachine_RBF_recall,RandomForest_recall]
  1286.  
  1287. Fscore128 = [KNN_3_fscore,KNN_5_fscore,KNN_7_fscore,KNNP_3_fscore,KNN_5_fscore,KNN_7_fscore,NaiveBayes_fscore,DecisionTree_fscore,
  1288.          MLP_fscore,RegrLogistica_fscore,SVMachine_L_fscore, SVMachine_RBF_fscore,RandomForest_fscore]
  1289.  
  1290. Acuracia128 = pd.DataFrame(Acuracia128)
  1291. Precision128 = pd.DataFrame(Precision128)
  1292. Recall128 = pd.DataFrame(Recall128)
  1293. Fscore128 = pd.DataFrame(Fscore128)
  1294.  
  1295. Acuracia128.to_csv('C:/Users/Auricelia/Desktop/DataSetsML/Acuracia128.csv')
  1296. Precision128.to_csv('C:/Users/Auricelia/Desktop/DataSetsML/Precision128.csv')
  1297. Recall128.to_csv('C:/Users/Auricelia/Desktop/DataSetsML/Recall128.csv')
  1298. Fscore128.to_csv('C:/Users/Auricelia/Desktop/DataSetsML/Fscore128.csv')
  1299.  
  1300. mediasacuracias = {
  1301.  
  1302.  
  1303.    "KNN Ponderado k = 3": np.mean(KNNP_3_acerto),
  1304.    "KNN Ponderado k = 5": np.mean(KNNP_5_acerto),
  1305.    "KNN Ponderado k = 7": np.mean(KNNP_7_acerto),
  1306.    "Naive Bayes": np.mean(NaiveBayes_acerto),
  1307.    "KNN k = 3": np.mean(KNN_3_acerto),
  1308.    "KNN k = 5": np.mean(KNN_5_acerto),
  1309.    "KNN k = 7": np.mean(KNN_7_acerto),
  1310.    "Decision Tree": np.mean(DecisionTree_acerto),
  1311.    "SVM Linear": np.mean(SVMachine_L_acerto),
  1312.    "SVM RBF": np.mean(SVMachine_RBF_acerto),
  1313.    "Regressao Logistica": np.mean(RegrLogistica_acerto),
  1314.    "MLP": np.mean(MLP_acerto),
  1315.    "Random Forest": np.mean(RandomForest_acerto)
  1316. }
  1317.  
  1318.  
  1319.  
  1320. mediasacuracias = sorted(mediasacuracias.items(),
  1321.                         key=lambda x: x[1])
  1322. print(mediasacuracias)
  1323. print("Tempo total: ", (tempofinal - tempoinicial) / 60)
  1324.  
  1325.  
  1326. ## USANDO A BASE COM IMAGENS DE 64x64
  1327.  
  1328.  
  1329.  
  1330. print('comecou o K fold')
  1331.  
  1332. tempoinicial = time.time()
  1333.  
  1334. for x in range(0, 10):
  1335.  
  1336.    tempo1 = time.time()
  1337.    cols = list(dataFrame64.columns)
  1338.    cols.remove('Classe')
  1339.    df_images_noclass = dataFrame64[cols]
  1340.    df_images_class = dataFrame64['Classe']
  1341.    c = kfold.split(dataFrame64)
  1342.  
  1343.    for train_index, test_index in c:
  1344.  
  1345.        noclass_train, noclass_test = df_images_noclass.iloc[train_index], df_images_noclass.iloc[test_index]
  1346.        class_train, class_test = df_images_class.iloc[train_index], df_images_class.iloc[test_index]
  1347.  
  1348.        KNN3_inicio = time.time()
  1349.        KNN_3.fit(noclass_train, class_train)
  1350.        KNN_3_acerto.append(KNN_3.score(noclass_test, class_test))
  1351.        KNN_3_recall. append(recall_score(class_test, KNN_3.predict(noclass_test),average='weighted'))
  1352.        KNN_3_precision.append(precision_score(class_test,KNN_3.predict(noclass_test),average='weighted'))
  1353.        KNN_3_fscore.append(f1_score(class_test,KNN_3.predict(noclass_test),average='weighted'))
  1354.        KNN3_fim = time.time()
  1355.        KNN_3_tempo.append(KNN3_fim - KNN3_inicio)
  1356.  
  1357.        KNN5_inicio = time.time()
  1358.        KNN_5.fit(noclass_train, class_train)
  1359.        KNN_5_acerto.append(KNN_5.score(noclass_test, class_test))
  1360.        KNN_5_recall.append(recall_score(class_test,KNN_5.predict(noclass_test),average='weighted'))
  1361.        KNN_5_precision.append(precision_score(class_test,KNN_5.predict(noclass_test),average='weighted'))
  1362.        KNN_5_fscore.append(f1_score(class_test,KNN_5.predict(noclass_test),average='weighted'))
  1363.        KNN5_fim = time.time()
  1364.        KNN_5_tempo.append(KNN5_fim - KNN5_inicio)
  1365.  
  1366.  
  1367.  
  1368.        KNN7_inicio = time.time()
  1369.        KNN_7.fit(noclass_train, class_train)
  1370.        KNN_7_acerto.append(KNN_3.score(noclass_test, class_test))
  1371.        KNN_7_precision.append(precision_score(class_test,KNN_7.predict(noclass_test),average='weighted'))
  1372.        KNN_7_recall.append(recall_score(class_test,KNN_7.predict(noclass_test),average='weighted'))
  1373.        KNN_7_fscore.append(f1_score(class_test,KNN_7.predict(noclass_test),average='weighted'))
  1374.        KNN7_fim = time.time()
  1375.        KNN_7_tempo.append(KNN3_fim - KNN3_inicio)
  1376.  
  1377.        KNNP3_inicio = time.time()
  1378.        KNNP_3.fit(noclass_train, class_train)
  1379.        KNNP_3_acerto.append(KNNP_3.score(noclass_test, class_test))
  1380.        KNNP_3_precision.append(precision_score(class_test,KNNP_3.predict(noclass_test),average='weighted'))
  1381.        KNNP_3_recall.append(recall_score(class_test,KNNP_3.predict(noclass_test),average='weighted'))
  1382.        KNNP_3_fscore.append(f1_score(class_test,KNNP_3.predict(noclass_test),average='weighted'))
  1383.        KNNP3_fim = time.time()
  1384.        KNNP_3_tempo.append(KNNP3_fim - KNNP3_inicio)
  1385.  
  1386.        KNNP5_inicio = time.time()
  1387.        KNNP_5.fit(noclass_train, class_train)
  1388.        KNNP_5_acerto.append(KNNP_5.score(noclass_test, class_test))
  1389.        KNNP_5_precision.append(precision_score(class_test,KNNP_5.predict(noclass_test),average='weighted'))
  1390.        KNNP_5_recall.append(recall_score(class_test,KNNP_5.predict(noclass_test),average='weighted'))
  1391.        KNNP_5_fscore.append(f1_score(class_test,KNNP_5.predict(noclass_test),average='weighted'))
  1392.        KNNP5_fim = time.time()
  1393.        KNNP_5_tempo.append(KNNP5_fim - KNNP5_inicio)
  1394.  
  1395.        KNNP7_inicio = time.time()
  1396.        KNNP_7.fit(noclass_train, class_train)
  1397.        KNNP_7_acerto.append(KNNP_7.score(noclass_test, class_test))
  1398.        KNNP_7_precision.append(precision_score(class_test,KNNP_7.predict(noclass_test),average='weighted'))
  1399.        KNNP_7_recall.append(recall_score(class_test,KNNP_7.predict(noclass_test),average='weighted'))
  1400.        KNNP_7_fscore.append(f1_score(class_test,KNNP_7.predict(noclass_test),average='weighted'))
  1401.        KNNP7_fim = time.time()
  1402.        KNNP_7_tempo.append(KNNP7_fim - KNNP7_inicio)
  1403.  
  1404.        NaiveBayes_inicio = time.time()
  1405.        NaiveBayes.fit(noclass_train, class_train)
  1406.        NaiveBayes_acerto.append(NaiveBayes.score(noclass_test, class_test))
  1407.        NaiveBayes_precision.append(precision_score(class_test,NaiveBayes.predict(noclass_test),average='weighted'))
  1408.        NaiveBayes_recall.append(recall_score(class_test,NaiveBayes.predict(noclass_test),average='weighted'))
  1409.        NaiveBayes_fscore.append(f1_score(class_test,NaiveBayes.predict(noclass_test),average='weighted'))
  1410.        NaiveBayes_fim = time.time()
  1411.        NaiveBayes_tempo.append(NaiveBayes_fim - NaiveBayes_inicio)
  1412.  
  1413.        DecisionTree_inicio = time.time()
  1414.        DecisionTree.fit(noclass_train, class_train)
  1415.        DecisionTree_acerto.append(DecisionTree.score(noclass_test, class_test))
  1416.        DecisionTree_precision.append(precision_score(class_test,DecisionTree.predict(noclass_test),average='weighted'))
  1417.        DecisionTree_recall.append(recall_score(class_test,DecisionTree.predict(noclass_test),average='weighted'))
  1418.        DecisionTree_fscore.append(f1_score(class_test,DecisionTree.predict(noclass_test),average='weighted'))
  1419.        DecisionTree_fim = time.time()
  1420.        DecisionTree_tempo.append(DecisionTree_fim - DecisionTree_inicio)
  1421.  
  1422.        SVMachine_L_inicio = time.time()
  1423.        SVMachine_L.fit(noclass_train, class_train)
  1424.        SVMachine_L_acerto.append(SVMachine_L.score(noclass_test, class_test))
  1425.        SVMachine_L_precision.append(precision_score(class_test,SVMachine_L.predict(noclass_test),average='weighted'))
  1426.        SVMachine_L_recall.append(recall_score(class_test,SVMachine_L.predict(noclass_test),average='weighted'))
  1427.        SVMachine_L_fscore.append(f1_score(class_test,SVMachine_L.predict(noclass_test),average='weighted'))
  1428.        SVMachine_L_fim = time.time()
  1429.        SVMachine_L_tempo.append(SVMachine_L_fim - SVMachine_L_inicio)
  1430.  
  1431.        SVMachine_RBF_inicio = time.time()
  1432.        SVMachine_RBF.fit(noclass_train, class_train)
  1433.        SVMachine_RBF_acerto.append(SVMachine_RBF.score(noclass_test, class_test))
  1434.        SVMachine_RBF_recall.append(recall_score(class_test,SVMachine_RBF.predict(noclass_test),average='weighted'))
  1435.        SVMachine_RBF_precision.append(precision_score(class_test,SVMachine_RBF.predict(noclass_test),average='weighted'))
  1436.        SVMachine_RBF_fscore.append(f1_score(class_test,SVMachine_RBF.predict(noclass_test),average='weighted'))
  1437.        SVMachine_RBF_fim = time.time()
  1438.        SVMachine_RBF_tempo.append(SVMachine_RBF_fim - SVMachine_RBF_inicio)
  1439.  
  1440.        RegrLogistica_inicio = time.time()
  1441.        RegrLogistica.fit(noclass_train, class_train)
  1442.        RegrLogistica_acerto.append(RegrLogistica.score(noclass_test, class_test))
  1443.        RegreLogistica_precision.append(precision_score(class_test, (RegrLogistica.predict(noclass_test)),average='weighted'))
  1444.        RegrLogistica_recall.append(recall_score(class_test,RegrLogistica.predict(noclass_test),average='weighted'))
  1445.        RegrLogistica_fscore.append(f1_score(class_test,RegrLogistica.predict(noclass_test),average='weighted'))
  1446.        RegrLogistica_fim = time.time()
  1447.        RegrLogistica_tempo.append(RegrLogistica_fim - RegrLogistica_inicio)
  1448.  
  1449.        MLP_inicio = time.time()
  1450.        MLP.fit(noclass_train, class_train)
  1451.        MLP_acerto.append(MLP.score(noclass_test, class_test))
  1452.        MLPP_precision.append(precision_score(class_test,MLP.predict(noclass_test),average='weighted'))
  1453.        MLP_recall.append(recall_score(class_test,MLP.predict(noclass_test),average='weighted'))
  1454.        MLP_fscore.append(f1_score(class_test,MLP.predict(noclass_test),average='weighted'))
  1455.        MLP_fim = time.time()
  1456.        MLP_tempo.append(MLP_fim - MLP_inicio)
  1457.  
  1458.        RandomForest_inicio = time.time()
  1459.        RandomForest.fit(noclass_train, class_train)
  1460.        RandomForest_acerto.append(RandomForest.score(noclass_test, class_test))
  1461.        RandomForest_recall.append(recall_score(class_test,RandomForest.predict(noclass_test),average='weighted'))
  1462.        RandomForest_precision.append(precision_score(class_test,RandomForest.predict(noclass_test),average='weighted'))
  1463.        RandomForest_fscore.append(f1_score(class_test,RandomForest.predict(noclass_test),average='weighted'))
  1464.        RandomForest_fim = time.time()
  1465.        RandomForest_tempo.append(RandomForest_fim - RandomForest_inicio)
  1466.  
  1467.  
  1468.    dataFrame64 = dataFrame64.sample(frac=1)
  1469.    print("Terminou a ", x)
  1470.    tempo2 = time.time()
  1471.    print("Tempo da rodada ", x, (tempo2 - tempo1) / 60)
  1472.  
  1473. tempofinal = time.time()
  1474.  
  1475. fun.tendencia_central('KNN k = 3', KNN_3_acerto, KNN_3_tempo)
  1476. fun.tendencia_central('KNN k = 5', KNN_5_acerto, KNN_5_tempo)
  1477. fun.tendencia_central('KNN k = 7', KNN_7_acerto, KNN_7_tempo)
  1478. fun.tendencia_central('KNN Ponderado k = 3', KNNP_3_acerto, KNNP_3_tempo)
  1479. fun.tendencia_central('KNN Ponderado k = 5', KNNP_5_acerto, KNNP_5_tempo)
  1480. fun.tendencia_central('KNN Ponderado k = 7', KNNP_7_acerto, KNNP_7_tempo)
  1481. fun.tendencia_central('Naïve Bayes', NaiveBayes_acerto, NaiveBayes_tempo)
  1482. fun.tendencia_central('Árvore de decisão', DecisionTree_acerto, DecisionTree_tempo)
  1483. fun.tendencia_central('MLP', MLP_acerto, MLP_tempo)
  1484. fun.tendencia_central('Regressão Logística', RegrLogistica_acerto, RegrLogistica_tempo)
  1485. fun.tendencia_central('SVM linear', SVMachine_L_acerto, SVMachine_L_tempo)
  1486. fun.tendencia_central('SVM RBF', SVMachine_RBF_acerto, SVMachine_RBF_tempo)
  1487. fun.tendencia_central('Random Forest', RandomForest_acerto,RandomForest_tempo)
  1488.  
  1489. mediasacuracias = {
  1490.  
  1491.  
  1492.    "KNN Ponderado k = 3": np.mean(KNNP_3_acerto),
  1493.    "KNN Ponderado k = 5": np.mean(KNNP_5_acerto),
  1494.    "KNN Ponderado k = 7": np.mean(KNNP_7_acerto),
  1495.    "Naive Bayes": np.mean(NaiveBayes_acerto),
  1496.    "KNN k = 3": np.mean(KNN_3_acerto),
  1497.    "KNN k = 5": np.mean(KNN_5_acerto),
  1498.    "KNN k = 7": np.mean(KNN_7_acerto),
  1499.    "Decision Tree": np.mean(DecisionTree_acerto),
  1500.    "SVM Linear": np.mean(SVMachine_L_acerto),
  1501.    "SVM RBF": np.mean(SVMachine_RBF_acerto),
  1502.    "Regressao Logistica": np.mean(RegrLogistica_acerto),
  1503.    "MLP": np.mean(MLP_acerto),
  1504.    "Random Forest": np.mean(RandomForest_acerto)
  1505. }
  1506.  
  1507. mediasacuracias = sorted(mediasacuracias.items(),
  1508.                         key=lambda x: x[1])
  1509. print(mediasacuracias)
  1510. print("Tempo total: ", (tempofinal - tempoinicial) / 60)
  1511. Acuracia64 = [KNN_3_acerto,KNN_5_acerto,KNN_7_acerto,KNNP_3_acerto,KNNP_5_acerto,KNNP_7_acerto,
  1512.               NaiveBayes_acerto,DecisionTree_acerto,MLP_acerto,RegrLogistica_acerto,SVMachine_L_acerto,
  1513.               SVMachine_RBF_acerto,RandomForest_acerto]
  1514. Precision64 = [KNN_3_precision,KNN_5_precision,KNN_7_precision,KNNP_3_precision,KNNP_5_precision,KNNP_7_precision,
  1515.         NaiveBayes_precision,DecisionTree_precision,MLPP_precision,RegreLogistica_precision,SVMachine_L_precision,
  1516.         SVMachine_RBF_precision,RandomForest_precision]
  1517. Recall64 = [KNN_3_recall,KNN_5_recall,KNN_7_recall,KNNP_3_recall,KNNP_5_recall,KNNP_7_recall,NaiveBayes_recall,
  1518.          DecisionTree_recall,MLP_recall,RegrLogistica_recall,SVMachine_L_recall,SVMachine_RBF_recall,RandomForest_recall]
  1519.  
  1520. Fscore64 = [KNN_3_fscore,KNN_5_fscore,KNN_7_fscore,KNNP_3_fscore,KNN_5_fscore,KNN_7_fscore,NaiveBayes_fscore,DecisionTree_fscore,
  1521.          MLP_fscore,RegrLogistica_fscore,SVMachine_L_fscore, SVMachine_RBF_fscore,RandomForest_fscore]
  1522.  
  1523. Acuracia64 = pd.DataFrame(Acuracia64)
  1524. Precision64 = pd.DataFrame(Precision64)
  1525. Recall64 = pd.DataFrame(Recall64)
  1526. Fscore64 = pd.DataFrame(Fscore64)
  1527.  
  1528. Acuracia64.to_csv('C:/Users/Auricelia/Desktop/DataSetsML/Acuracia64.csv')
  1529. Precision64.to_csv('C:/Users/Auricelia/Desktop/DataSetsML/Precision64.csv')
  1530. Recall64.to_csv('C:/Users/Auricelia/Desktop/DataSetsML/Recall64.csv')
  1531. Fscore64.to_csv('C:/Users/Auricelia/Desktop/DataSetsML/Fscore64.csv')
  1532.  
  1533.  
  1534.  
  1535.  
  1536. # USANDO BASE DE 32x32
  1537.  
  1538.  
  1539.  
  1540. print('comecou o K fold')
  1541.  
  1542. tempoinicial = time.time()
  1543.  
  1544. for x in range(0, 10):
  1545.  
  1546.    tempo1 = time.time()
  1547.    cols = list(dataFrame32.columns)
  1548.    cols.remove('Classe')
  1549.    df_images_noclass = dataFrame32[cols]
  1550.    df_images_class = dataFrame32['Classe']
  1551.    c = kfold.split(dataFrame32)
  1552.  
  1553.    for train_index, test_index in c:
  1554.  
  1555.        noclass_train, noclass_test = df_images_noclass.iloc[train_index], df_images_noclass.iloc[test_index]
  1556.        class_train, class_test = df_images_class.iloc[train_index], df_images_class.iloc[test_index]
  1557.  
  1558.        KNN3_inicio = time.time()
  1559.        KNN_3.fit(noclass_train, class_train)
  1560.        KNN_3_acerto.append(KNN_3.score(noclass_test, class_test))
  1561.        KNN_3_recall. append(recall_score(class_test, KNN_3.predict(noclass_test),average='weighted'))
  1562.        KNN_3_precision.append(precision_score(class_test,KNN_3.predict(noclass_test),average='weighted'))
  1563.        KNN_3_fscore.append(f1_score(class_test,KNN_3.predict(noclass_test),average='weighted'))
  1564.        KNN3_fim = time.time()
  1565.        KNN_3_tempo.append(KNN3_fim - KNN3_inicio)
  1566.  
  1567.        KNN5_inicio = time.time()
  1568.        KNN_5.fit(noclass_train, class_train)
  1569.        KNN_5_acerto.append(KNN_5.score(noclass_test, class_test))
  1570.        KNN_5_recall.append(recall_score(class_test,KNN_5.predict(noclass_test),average='weighted'))
  1571.        KNN_5_precision.append(precision_score(class_test,KNN_5.predict(noclass_test),average='weighted'))
  1572.        KNN_5_fscore.append(f1_score(class_test,KNN_5.predict(noclass_test),average='weighted'))
  1573.        KNN5_fim = time.time()
  1574.        KNN_5_tempo.append(KNN5_fim - KNN5_inicio)
  1575.  
  1576.  
  1577.  
  1578.        KNN7_inicio = time.time()
  1579.        KNN_7.fit(noclass_train, class_train)
  1580.        KNN_7_acerto.append(KNN_3.score(noclass_test, class_test))
  1581.        KNN_7_precision.append(precision_score(class_test,KNN_7.predict(noclass_test),average='weighted'))
  1582.        KNN_7_recall.append(recall_score(class_test,KNN_7.predict(noclass_test),average='weighted'))
  1583.        KNN_7_fscore.append(f1_score(class_test,KNN_7.predict(noclass_test),average='weighted'))
  1584.        KNN7_fim = time.time()
  1585.        KNN_7_tempo.append(KNN3_fim - KNN3_inicio)
  1586.  
  1587.        KNNP3_inicio = time.time()
  1588.        KNNP_3.fit(noclass_train, class_train)
  1589.        KNNP_3_acerto.append(KNNP_3.score(noclass_test, class_test))
  1590.        KNNP_3_precision.append(precision_score(class_test,KNNP_3.predict(noclass_test),average='weighted'))
  1591.        KNNP_3_recall.append(recall_score(class_test,KNNP_3.predict(noclass_test),average='weighted'))
  1592.        KNNP_3_fscore.append(f1_score(class_test,KNNP_3.predict(noclass_test),average='weighted'))
  1593.        KNNP3_fim = time.time()
  1594.        KNNP_3_tempo.append(KNNP3_fim - KNNP3_inicio)
  1595.  
  1596.        KNNP5_inicio = time.time()
  1597.        KNNP_5.fit(noclass_train, class_train)
  1598.        KNNP_5_acerto.append(KNNP_5.score(noclass_test, class_test))
  1599.        KNNP_5_precision.append(precision_score(class_test,KNNP_5.predict(noclass_test),average='weighted'))
  1600.        KNNP_5_recall.append(recall_score(class_test,KNNP_5.predict(noclass_test),average='weighted'))
  1601.        KNNP_5_fscore.append(f1_score(class_test,KNNP_5.predict(noclass_test),average='weighted'))
  1602.        KNNP5_fim = time.time()
  1603.        KNNP_5_tempo.append(KNNP5_fim - KNNP5_inicio)
  1604.  
  1605.        KNNP7_inicio = time.time()
  1606.        KNNP_7.fit(noclass_train, class_train)
  1607.        KNNP_7_acerto.append(KNNP_7.score(noclass_test, class_test))
  1608.        KNNP_7_precision.append(precision_score(class_test,KNNP_7.predict(noclass_test),average='weighted'))
  1609.        KNNP_7_recall.append(recall_score(class_test,KNNP_7.predict(noclass_test),average='weighted'))
  1610.        KNNP_7_fscore.append(f1_score(class_test,KNNP_7.predict(noclass_test),average='weighted'))
  1611.        KNNP7_fim = time.time()
  1612.        KNNP_7_tempo.append(KNNP7_fim - KNNP7_inicio)
  1613.  
  1614.        NaiveBayes_inicio = time.time()
  1615.        NaiveBayes.fit(noclass_train, class_train)
  1616.        NaiveBayes_acerto.append(NaiveBayes.score(noclass_test, class_test))
  1617.        NaiveBayes_precision.append(precision_score(class_test,NaiveBayes.predict(noclass_test),average='weighted'))
  1618.        NaiveBayes_recall.append(recall_score(class_test,NaiveBayes.predict(noclass_test),average='weighted'))
  1619.        NaiveBayes_fscore.append(f1_score(class_test,NaiveBayes.predict(noclass_test),average='weighted'))
  1620.        NaiveBayes_fim = time.time()
  1621.        NaiveBayes_tempo.append(NaiveBayes_fim - NaiveBayes_inicio)
  1622.  
  1623.        DecisionTree_inicio = time.time()
  1624.        DecisionTree.fit(noclass_train, class_train)
  1625.        DecisionTree_acerto.append(DecisionTree.score(noclass_test, class_test))
  1626.        DecisionTree_precision.append(precision_score(class_test,DecisionTree.predict(noclass_test),average='weighted'))
  1627.        DecisionTree_recall.append(recall_score(class_test,DecisionTree.predict(noclass_test),average='weighted'))
  1628.        DecisionTree_fscore.append(f1_score(class_test,DecisionTree.predict(noclass_test),average='weighted'))
  1629.        DecisionTree_fim = time.time()
  1630.        DecisionTree_tempo.append(DecisionTree_fim - DecisionTree_inicio)
  1631.  
  1632.        SVMachine_L_inicio = time.time()
  1633.        SVMachine_L.fit(noclass_train, class_train)
  1634.        SVMachine_L_acerto.append(SVMachine_L.score(noclass_test, class_test))
  1635.        SVMachine_L_precision.append(precision_score(class_test,SVMachine_L.predict(noclass_test),average='weighted'))
  1636.        SVMachine_L_recall.append(recall_score(class_test,SVMachine_L.predict(noclass_test),average='weighted'))
  1637.        SVMachine_L_fscore.append(f1_score(class_test,SVMachine_L.predict(noclass_test),average='weighted'))
  1638.        SVMachine_L_fim = time.time()
  1639.        SVMachine_L_tempo.append(SVMachine_L_fim - SVMachine_L_inicio)
  1640.  
  1641.        SVMachine_RBF_inicio = time.time()
  1642.        SVMachine_RBF.fit(noclass_train, class_train)
  1643.        SVMachine_RBF_acerto.append(SVMachine_RBF.score(noclass_test, class_test))
  1644.        SVMachine_RBF_recall.append(recall_score(class_test,SVMachine_RBF.predict(noclass_test),average='weighted'))
  1645.        SVMachine_RBF_precision.append(precision_score(class_test,SVMachine_RBF.predict(noclass_test),average='weighted'))
  1646.        SVMachine_RBF_fscore.append(f1_score(class_test,SVMachine_RBF.predict(noclass_test),average='weighted'))
  1647.        SVMachine_RBF_fim = time.time()
  1648.        SVMachine_RBF_tempo.append(SVMachine_RBF_fim - SVMachine_RBF_inicio)
  1649.  
  1650.        RegrLogistica_inicio = time.time()
  1651.        RegrLogistica.fit(noclass_train, class_train)
  1652.        RegrLogistica_acerto.append(RegrLogistica.score(noclass_test, class_test))
  1653.        RegreLogistica_precision.append(precision_score(class_test, (RegrLogistica.predict(noclass_test)),average='weighted'))
  1654.        RegrLogistica_recall.append(recall_score(class_test,RegrLogistica.predict(noclass_test),average='weighted'))
  1655.        RegrLogistica_fscore.append(f1_score(class_test,RegrLogistica.predict(noclass_test),average='weighted'))
  1656.        RegrLogistica_fim = time.time()
  1657.        RegrLogistica_tempo.append(RegrLogistica_fim - RegrLogistica_inicio)
  1658.  
  1659.        MLP_inicio = time.time()
  1660.        MLP.fit(noclass_train, class_train)
  1661.        MLP_acerto.append(MLP.score(noclass_test, class_test))
  1662.        MLPP_precision.append(precision_score(class_test,MLP.predict(noclass_test),average='weighted'))
  1663.        MLP_recall.append(recall_score(class_test,MLP.predict(noclass_test),average='weighted'))
  1664.        MLP_fscore.append(f1_score(class_test,MLP.predict(noclass_test),average='weighted'))
  1665.        MLP_fim = time.time()
  1666.        MLP_tempo.append(MLP_fim - MLP_inicio)
  1667.  
  1668.        RandomForest_inicio = time.time()
  1669.        RandomForest.fit(noclass_train, class_train)
  1670.        RandomForest_acerto.append(RandomForest.score(noclass_test, class_test))
  1671.        RandomForest_recall.append(recall_score(class_test,RandomForest.predict(noclass_test),average='weighted'))
  1672.        RandomForest_precision.append(precision_score(class_test,RandomForest.predict(noclass_test),average='weighted'))
  1673.        RandomForest_fscore.append(f1_score(class_test,RandomForest.predict(noclass_test),average='weighted'))
  1674.        RandomForest_fim = time.time()
  1675.        RandomForest_tempo.append(RandomForest_fim - RandomForest_inicio)
  1676.  
  1677.  
  1678.    dataFrame32 = dataFrame32.sample(frac=1)
  1679.    print("Terminou a ", x)
  1680.    tempo2 = time.time()
  1681.    print("Tempo da rodada ", x, (tempo2 - tempo1) / 60)
  1682.  
  1683. tempofinal = time.time()
  1684.  
  1685. fun.tendencia_central('KNN k = 3', KNN_3_acerto, KNN_3_tempo)
  1686. fun.tendencia_central('KNN k = 5', KNN_5_acerto, KNN_5_tempo)
  1687. fun.tendencia_central('KNN k = 7', KNN_7_acerto, KNN_7_tempo)
  1688. fun.tendencia_central('KNN Ponderado k = 3', KNNP_3_acerto, KNNP_3_tempo)
  1689. fun.tendencia_central('KNN Ponderado k = 5', KNNP_5_acerto, KNNP_5_tempo)
  1690. fun.tendencia_central('KNN Ponderado k = 7', KNNP_7_acerto, KNNP_7_tempo)
  1691. fun.tendencia_central('Naïve Bayes', NaiveBayes_acerto, NaiveBayes_tempo)
  1692. fun.tendencia_central('Árvore de decisão', DecisionTree_acerto, DecisionTree_tempo)
  1693. fun.tendencia_central('MLP', MLP_acerto, MLP_tempo)
  1694. fun.tendencia_central('Regressão Logística', RegrLogistica_acerto, RegrLogistica_tempo)
  1695. fun.tendencia_central('SVM linear', SVMachine_L_acerto, SVMachine_L_tempo)
  1696. fun.tendencia_central('SVM RBF', SVMachine_RBF_acerto, SVMachine_RBF_tempo)
  1697. fun.tendencia_central('Random Forest', RandomForest_acerto,RandomForest_tempo)
  1698.  
  1699. mediasacuracias = {
  1700.  
  1701.  
  1702.    "KNN Ponderado k = 3": np.mean(KNNP_3_acerto),
  1703.    "KNN Ponderado k = 5": np.mean(KNNP_5_acerto),
  1704.    "KNN Ponderado k = 7": np.mean(KNNP_7_acerto),
  1705.    "Naive Bayes": np.mean(NaiveBayes_acerto),
  1706.    "KNN k = 3": np.mean(KNN_3_acerto),
  1707.    "KNN k = 5": np.mean(KNN_5_acerto),
  1708.    "KNN k = 7": np.mean(KNN_7_acerto),
  1709.    "Decision Tree": np.mean(DecisionTree_acerto),
  1710.    "SVM Linear": np.mean(SVMachine_L_acerto),
  1711.    "SVM RBF": np.mean(SVMachine_RBF_acerto),
  1712.    "Regressao Logistica": np.mean(RegrLogistica_acerto),
  1713.    "MLP": np.mean(MLP_acerto),
  1714.    "Random Forest": np.mean(RandomForest_acerto)
  1715. }
  1716.  
  1717. mediasacuracias = sorted(mediasacuracias.items(),
  1718.                         key=lambda x: x[1])
  1719. print(mediasacuracias)
  1720. print("Tempo total: ", (tempofinal - tempoinicial) / 60)
  1721. Acuracia32 = [KNN_3_acerto,KNN_5_acerto,KNN_7_acerto,KNNP_3_acerto,KNNP_5_acerto,KNNP_7_acerto,
  1722.               NaiveBayes_acerto,DecisionTree_acerto,MLP_acerto,RegrLogistica_acerto,SVMachine_L_acerto,
  1723.               SVMachine_RBF_acerto,RandomForest_acerto]
  1724. Precision32 = [KNN_3_precision,KNN_5_precision,KNN_7_precision,KNNP_3_precision,KNNP_5_precision,KNNP_7_precision,
  1725.         NaiveBayes_precision,DecisionTree_precision,MLPP_precision,RegreLogistica_precision,SVMachine_L_precision,
  1726.         SVMachine_RBF_precision,RandomForest_precision]
  1727. Recall32 = [KNN_3_recall,KNN_5_recall,KNN_7_recall,KNNP_3_recall,KNNP_5_recall,KNNP_7_recall,NaiveBayes_recall,
  1728.          DecisionTree_recall,MLP_recall,RegrLogistica_recall,SVMachine_L_recall,SVMachine_RBF_recall,RandomForest_recall]
  1729.  
  1730. Fscore32 = [KNN_3_fscore,KNN_5_fscore,KNN_7_fscore,KNNP_3_fscore,KNN_5_fscore,KNN_7_fscore,NaiveBayes_fscore,DecisionTree_fscore,
  1731.          MLP_fscore,RegrLogistica_fscore,SVMachine_L_fscore, SVMachine_RBF_fscore,RandomForest_fscore]
  1732.  
  1733. Acuracia32 = pd.DataFrame(Acuracia32)
  1734. Precision32 = pd.DataFrame(Precision32)
  1735. Recall32 = pd.DataFrame(Recall32)
  1736. Fscore32 = pd.DataFrame(Fscore32)
  1737.  
  1738. Acuracia32.to_csv('C:/Users/Auricelia/Desktop/DataSetsML/Acuracia32.csv')
  1739. Precision32.to_csv('C:/Users/Auricelia/Desktop/DataSetsML/Precision32.csv')
  1740. Recall32.to_csv('C:/Users/Auricelia/Desktop/DataSetsML/Recall32.csv')
  1741. Fscore32.to_csv('C:/Users/Auricelia/Desktop/DataSetsML/Fscore32.csv')
  1742.  
  1743.  
  1744. '''
  1745.  
  1746. '''
  1747.  
  1748. # USANDO A BASE COM IMAGENS 16x16
  1749.  
  1750. print('comecou o K fold')
  1751.  
  1752. tempoinicial = time.time()
  1753.  
  1754. for x in range(0, 10):
  1755.  
  1756.    tempo1 = time.time()
  1757.    cols = list(dataFrame16.columns)
  1758.    cols.remove('Classe')
  1759.    df_images_noclass = dataFrame16[cols]
  1760.    df_images_class = dataFrame16['Classe']
  1761.    c = kfold.split(dataFrame16)
  1762.  
  1763.    for train_index, test_index in c:
  1764.  
  1765.        noclass_train, noclass_test = df_images_noclass.iloc[train_index], df_images_noclass.iloc[test_index]
  1766.        class_train, class_test = df_images_class.iloc[train_index], df_images_class.iloc[test_index]
  1767.  
  1768.        KNN3_inicio = time.time()
  1769.        KNN_3.fit(noclass_train, class_train)
  1770.        KNN_3_acerto.append(KNN_3.score(noclass_test, class_test))
  1771.        KNN_3_recall. append(recall_score(class_test, KNN_3.predict(noclass_test),average='weighted'))
  1772.        KNN_3_precision.append(precision_score(class_test,KNN_3.predict(noclass_test),average='weighted'))
  1773.        KNN_3_fscore.append(f1_score(class_test,KNN_3.predict(noclass_test),average='weighted'))
  1774.        KNN3_fim = time.time()
  1775.        KNN_3_tempo.append(KNN3_fim - KNN3_inicio)
  1776.  
  1777.        KNN5_inicio = time.time()
  1778.        KNN_5.fit(noclass_train, class_train)
  1779.        KNN_5_acerto.append(KNN_5.score(noclass_test, class_test))
  1780.        KNN_5_recall.append(recall_score(class_test,KNN_5.predict(noclass_test),average='weighted'))
  1781.        KNN_5_precision.append(precision_score(class_test,KNN_5.predict(noclass_test),average='weighted'))
  1782.        KNN_5_fscore.append(f1_score(class_test,KNN_5.predict(noclass_test),average='weighted'))
  1783.        KNN5_fim = time.time()
  1784.        KNN_5_tempo.append(KNN5_fim - KNN5_inicio)
  1785.  
  1786.  
  1787.        KNN7_inicio = time.time()
  1788.        KNN_7.fit(noclass_train, class_train)
  1789.        KNN_7_acerto.append(KNN_3.score(noclass_test, class_test))
  1790.        KNN_7_precision.append(precision_score(class_test,KNN_7.predict(noclass_test),average='weighted'))
  1791.        KNN_7_recall.append(recall_score(class_test,KNN_7.predict(noclass_test),average='weighted'))
  1792.        KNN_7_fscore.append(f1_score(class_test,KNN_7.predict(noclass_test),average='weighted'))
  1793.        KNN7_fim = time.time()
  1794.        KNN_7_tempo.append(KNN3_fim - KNN3_inicio)
  1795.  
  1796.        KNNP3_inicio = time.time()
  1797.        KNNP_3.fit(noclass_train, class_train)
  1798.        KNNP_3_acerto.append(KNNP_3.score(noclass_test, class_test))
  1799.        KNNP_3_precision.append(precision_score(class_test,KNNP_3.predict(noclass_test),average='weighted'))
  1800.        KNNP_3_recall.append(recall_score(class_test,KNNP_3.predict(noclass_test),average='weighted'))
  1801.        KNNP_3_fscore.append(f1_score(class_test,KNNP_3.predict(noclass_test),average='weighted'))
  1802.        KNNP3_fim = time.time()
  1803.        KNNP_3_tempo.append(KNNP3_fim - KNNP3_inicio)
  1804.  
  1805.        KNNP5_inicio = time.time()
  1806.        KNNP_5.fit(noclass_train, class_train)
  1807.        KNNP_5_acerto.append(KNNP_5.score(noclass_test, class_test))
  1808.        KNNP_5_precision.append(precision_score(class_test,KNNP_5.predict(noclass_test),average='weighted'))
  1809.        KNNP_5_recall.append(recall_score(class_test,KNNP_5.predict(noclass_test),average='weighted'))
  1810.        KNNP_5_fscore.append(f1_score(class_test,KNNP_5.predict(noclass_test),average='weighted'))
  1811.        KNNP5_fim = time.time()
  1812.        KNNP_5_tempo.append(KNNP5_fim - KNNP5_inicio)
  1813.  
  1814.        KNNP7_inicio = time.time()
  1815.        KNNP_7.fit(noclass_train, class_train)
  1816.        KNNP_7_acerto.append(KNNP_7.score(noclass_test, class_test))
  1817.        KNNP_7_precision.append(precision_score(class_test,KNNP_7.predict(noclass_test),average='weighted'))
  1818.        KNNP_7_recall.append(recall_score(class_test,KNNP_7.predict(noclass_test),average='weighted'))
  1819.        KNNP_7_fscore.append(f1_score(class_test,KNNP_7.predict(noclass_test),average='weighted'))
  1820.        KNNP7_fim = time.time()
  1821.        KNNP_7_tempo.append(KNNP7_fim - KNNP7_inicio)
  1822.  
  1823.        NaiveBayes_inicio = time.time()
  1824.        NaiveBayes.fit(noclass_train, class_train)
  1825.        NaiveBayes_acerto.append(NaiveBayes.score(noclass_test, class_test))
  1826.        NaiveBayes_precision.append(precision_score(class_test,NaiveBayes.predict(noclass_test),average='weighted'))
  1827.        NaiveBayes_recall.append(recall_score(class_test,NaiveBayes.predict(noclass_test),average='weighted'))
  1828.        NaiveBayes_fscore.append(f1_score(class_test,NaiveBayes.predict(noclass_test),average='weighted'))
  1829.        NaiveBayes_fim = time.time()
  1830.        NaiveBayes_tempo.append(NaiveBayes_fim - NaiveBayes_inicio)
  1831.  
  1832.        DecisionTree_inicio = time.time()
  1833.        DecisionTree.fit(noclass_train, class_train)
  1834.        DecisionTree_acerto.append(DecisionTree.score(noclass_test, class_test))
  1835.        DecisionTree_precision.append(precision_score(class_test,DecisionTree.predict(noclass_test),average='weighted'))
  1836.        DecisionTree_recall.append(recall_score(class_test,DecisionTree.predict(noclass_test),average='weighted'))
  1837.        DecisionTree_fscore.append(f1_score(class_test,DecisionTree.predict(noclass_test),average='weighted'))
  1838.        DecisionTree_fim = time.time()
  1839.        DecisionTree_tempo.append(DecisionTree_fim - DecisionTree_inicio)
  1840.  
  1841.        SVMachine_L_inicio = time.time()
  1842.        SVMachine_L.fit(noclass_train, class_train)
  1843.        SVMachine_L_acerto.append(SVMachine_L.score(noclass_test, class_test))
  1844.        SVMachine_L_precision.append(precision_score(class_test,SVMachine_L.predict(noclass_test),average='weighted'))
  1845.        SVMachine_L_recall.append(recall_score(class_test,SVMachine_L.predict(noclass_test),average='weighted'))
  1846.        SVMachine_L_fscore.append(f1_score(class_test,SVMachine_L.predict(noclass_test),average='weighted'))
  1847.        SVMachine_L_fim = time.time()
  1848.        SVMachine_L_tempo.append(SVMachine_L_fim - SVMachine_L_inicio)
  1849.  
  1850.        SVMachine_RBF_inicio = time.time()
  1851.        SVMachine_RBF.fit(noclass_train, class_train)
  1852.        SVMachine_RBF_acerto.append(SVMachine_RBF.score(noclass_test, class_test))
  1853.        SVMachine_RBF_recall.append(recall_score(class_test,SVMachine_RBF.predict(noclass_test),average='weighted'))
  1854.        SVMachine_RBF_precision.append(precision_score(class_test,SVMachine_RBF.predict(noclass_test),average='weighted'))
  1855.        SVMachine_RBF_fscore.append(f1_score(class_test,SVMachine_RBF.predict(noclass_test),average='weighted'))
  1856.        SVMachine_RBF_fim = time.time()
  1857.        SVMachine_RBF_tempo.append(SVMachine_RBF_fim - SVMachine_RBF_inicio)
  1858.  
  1859.        RegrLogistica_inicio = time.time()
  1860.        RegrLogistica.fit(noclass_train, class_train)
  1861.        RegrLogistica_acerto.append(RegrLogistica.score(noclass_test, class_test))
  1862.        RegreLogistica_precision.append(precision_score(class_test, (RegrLogistica.predict(noclass_test)),average='weighted'))
  1863.        RegrLogistica_recall.append(recall_score(class_test,RegrLogistica.predict(noclass_test),average='weighted'))
  1864.        RegrLogistica_fscore.append(f1_score(class_test,RegrLogistica.predict(noclass_test),average='weighted'))
  1865.        RegrLogistica_fim = time.time()
  1866.        RegrLogistica_tempo.append(RegrLogistica_fim - RegrLogistica_inicio)
  1867.  
  1868.        MLP_inicio = time.time()
  1869.        MLP.fit(noclass_train, class_train)
  1870.        MLP_acerto.append(MLP.score(noclass_test, class_test))
  1871.        MLPP_precision.append(precision_score(class_test,MLP.predict(noclass_test),average='weighted'))
  1872.        MLP_recall.append(recall_score(class_test,MLP.predict(noclass_test),average='weighted'))
  1873.        MLP_fscore.append(f1_score(class_test,MLP.predict(noclass_test),average='weighted'))
  1874.        MLP_fim = time.time()
  1875.        MLP_tempo.append(MLP_fim - MLP_inicio)
  1876.  
  1877.        RandomForest_inicio = time.time()
  1878.        RandomForest.fit(noclass_train, class_train)
  1879.        RandomForest_acerto.append(RandomForest.score(noclass_test, class_test))
  1880.        RandomForest_recall.append(recall_score(class_test,RandomForest.predict(noclass_test),average='weighted'))
  1881.        RandomForest_precision.append(precision_score(class_test,RandomForest.predict(noclass_test),average='weighted'))
  1882.        RandomForest_fscore.append(f1_score(class_test,RandomForest.predict(noclass_test),average='weighted'))
  1883.        RandomForest_fim = time.time()
  1884.        RandomForest_tempo.append(RandomForest_fim - RandomForest_inicio)
  1885.  
  1886.  
  1887.    dataFrame16 = dataFrame16.sample(frac=1)
  1888.    print("Terminou a ", x)
  1889.    tempo2 = time.time()
  1890.    print("Tempo da rodada ", x, (tempo2 - tempo1) / 60)
  1891.  
  1892. tempofinal = time.time()
  1893.  
  1894. fun.tendencia_central('KNN k = 3', KNN_3_acerto, KNN_3_tempo)
  1895. fun.tendencia_central('KNN k = 5', KNN_5_acerto, KNN_5_tempo)
  1896. fun.tendencia_central('KNN k = 7', KNN_7_acerto, KNN_7_tempo)
  1897. fun.tendencia_central('KNN Ponderado k = 3', KNNP_3_acerto, KNNP_3_tempo)
  1898. fun.tendencia_central('KNN Ponderado k = 5', KNNP_5_acerto, KNNP_5_tempo)
  1899. fun.tendencia_central('KNN Ponderado k = 7', KNNP_7_acerto, KNNP_7_tempo)
  1900. fun.tendencia_central('Naïve Bayes', NaiveBayes_acerto, NaiveBayes_tempo)
  1901. fun.tendencia_central('Árvore de decisão', DecisionTree_acerto, DecisionTree_tempo)
  1902. fun.tendencia_central('MLP', MLP_acerto, MLP_tempo)
  1903. fun.tendencia_central('Regressão Logística', RegrLogistica_acerto, RegrLogistica_tempo)
  1904. fun.tendencia_central('SVM linear', SVMachine_L_acerto, SVMachine_L_tempo)
  1905. fun.tendencia_central('SVM RBF', SVMachine_RBF_acerto, SVMachine_RBF_tempo)
  1906. fun.tendencia_central('Random Forest', RandomForest_acerto,RandomForest_tempo)
  1907.  
  1908. mediasacuracias = {
  1909.  
  1910.  
  1911.    "KNN Ponderado k = 3": np.mean(KNNP_3_acerto),
  1912.    "KNN Ponderado k = 5": np.mean(KNNP_5_acerto),
  1913.    "KNN Ponderado k = 7": np.mean(KNNP_7_acerto),
  1914.    "Naive Bayes": np.mean(NaiveBayes_acerto),
  1915.    "KNN k = 3": np.mean(KNN_3_acerto),
  1916.    "KNN k = 5": np.mean(KNN_5_acerto),
  1917.    "KNN k = 7": np.mean(KNN_7_acerto),
  1918.    "Decision Tree": np.mean(DecisionTree_acerto),
  1919.    "SVM Linear": np.mean(SVMachine_L_acerto),
  1920.    "SVM RBF": np.mean(SVMachine_RBF_acerto),
  1921.    "Regressao Logistica": np.mean(RegrLogistica_acerto),
  1922.    "MLP": np.mean(MLP_acerto),
  1923.    "Random Forest": np.mean(RandomForest_acerto)
  1924. }
  1925.  
  1926. mediasacuracias = sorted(mediasacuracias.items(),
  1927.                         key=lambda x: x[1])
  1928. print(mediasacuracias)
  1929. print("Tempo total: ", (tempofinal - tempoinicial) / 60)
  1930. Acuracia16 = [KNN_3_acerto,KNN_5_acerto,KNN_7_acerto,KNNP_3_acerto,KNNP_5_acerto,KNNP_7_acerto,
  1931.               NaiveBayes_acerto,DecisionTree_acerto,MLP_acerto,RegrLogistica_acerto,SVMachine_L_acerto,
  1932.               SVMachine_RBF_acerto,RandomForest_acerto]
  1933. Precision16 = [KNN_3_precision,KNN_5_precision,KNN_7_precision,KNNP_3_precision,KNNP_5_precision,KNNP_7_precision,
  1934.         NaiveBayes_precision,DecisionTree_precision,MLPP_precision,RegreLogistica_precision,SVMachine_L_precision,
  1935.         SVMachine_RBF_precision,RandomForest_precision]
  1936. Recall16 = [KNN_3_recall,KNN_5_recall,KNN_7_recall,KNNP_3_recall,KNNP_5_recall,KNNP_7_recall,NaiveBayes_recall,
  1937.          DecisionTree_recall,MLP_recall,RegrLogistica_recall,SVMachine_L_recall,SVMachine_RBF_recall,RandomForest_recall]
  1938.  
  1939. Fscore16 = [KNN_3_fscore,KNN_5_fscore,KNN_7_fscore,KNNP_3_fscore,KNN_5_fscore,KNN_7_fscore,NaiveBayes_fscore,DecisionTree_fscore,
  1940.          MLP_fscore,RegrLogistica_fscore,SVMachine_L_fscore, SVMachine_RBF_fscore,RandomForest_fscore]
  1941.  
  1942. Acuracia16 = pd.DataFrame(Acuracia16)
  1943. Precision16 = pd.DataFrame(Precision16)
  1944. Recall16 = pd.DataFrame(Recall16)
  1945. Fscore16 = pd.DataFrame(Fscore16)
  1946.  
  1947. Acuracia16.to_csv('C:/Users/Auricelia/Desktop/DataSetsML/Acuracia16.csv')
  1948. Precision16.to_csv('C:/Users/Auricelia/Desktop/DataSetsML/Precision16.csv')
  1949. Recall16.to_csv('C:/Users/Auricelia/Desktop/DataSetsML/Recall16.csv')
  1950. Fscore16.to_csv('C:/Users/Auricelia/Desktop/DataSetsML/Fscore16.csv')
  1951. '''
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top