Advertisement
cardel

Untitled

Sep 13th, 2017
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Octave 1.29 KB | None | 0 0
  1. #Autor: Carlos Andres Delgado Saavedra
  2. #Descripcion: Ejemplo para la carga de un archivo separado por comas
  3. #Fechas: 12 de Septiembre de 2017
  4.  
  5.  
  6. #Se crea una celda, ya que tenemos
  7. [read] = textread ('example.data','%s');
  8.  
  9. #Procesamos los datos
  10. #Vamos a codificar
  11. # YELLOW = -1
  12. # PURPLE = 1
  13. # SMALL = -1
  14. # LARGE = 1
  15. # DIP = -1
  16. # STRETCH = 1
  17. # CHILD = -1
  18. # ADULT = 1
  19. # T = 1
  20. # F = -1
  21. entradas = [];
  22. salidas = [];
  23. #Separar por comas
  24. for i = 1:rows(read)
  25.   lecturaLinea = read{i,1};
  26.   lecturaLinea = regexprep(lecturaLinea,"YELLOW|SMALL|DIP|CHILD|F", "-1");
  27.   lecturaLinea = regexprep(lecturaLinea,"PURPLE|LARGE|STRETCH|ADULT|T", "1");
  28.  
  29.   fila = strsplit (lecturaLinea, ",");
  30.   fila = arrayfun(@(N,M) str2num(fila{N,M}), 1:rows(fila), 1:columns(fila));
  31.  
  32.   entradas=[entradas; fila(1:columns(fila)-1)];
  33.   salidas= [salidas; fila(columns(fila))];
  34.   #leemos elemento por elemento
  35.  
  36. endfor
  37.  
  38. #Ahora podemos disponer de las entradas y salidas procesadas
  39.  
  40. #Conjunto de entrenamiento
  41. #80% de los elementos
  42. elementos = randperm(0.8*rows(entradas));
  43. entrenamientoIn = entradas(elementos,:);
  44. entrenamientoOut = salidas(elementos,:);
  45.  
  46. #Borramos los datos
  47.  
  48. #Conjunto de pruebas
  49. pruebaIn = entradas;
  50. pruebaOut = salidas;
  51.  
  52. pruebaIn(elementos,:) = [];
  53. pruebaOut(elementos,:) = [];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement