resumen
1 comparativa
empresa: | gfi | tree | accenture | divisadero |
---|---|---|---|---|
ponente: | gonzalo | julia + cristian | javier | jaime |
servidor | NA (usb) | github | NA (zadeh) | |
formato | 10 CSV | 1 RData | 1 CSV | 1 CSV |
registros | < 100 k | 5 k | 1 M | 500 k |
variables | 100 | 20 | 50 | 5 |
tamaño | 1 M | 100 k | 50 M | 2 M |
informática | utf8 iso8859 | github | comandos (CLI) | procesamiento distribuido (paralelizar) |
leng. visual | anaconda | |||
sql R::merge | jupyter | |||
estadística | xgboost | descriptiva | ||
CORvas | univariante | |||
undersampling | ||||
conclusiones | conectar tablas | servidor público | datos > RAM | 1ª consulta => 1 GB «ya no es bigdata» |
objetivo: segmentación -> móvil/ordenata |
2 problemas en general
- codificación de ficheros de texto
- utf-8, iso-8859-1 = latin-1, iso-8859-15 = latin-9
- file
~/public_html/master/manadine/curso2/seminarios $ file * resumen-latin1.org: ISO-8859 text resumen.html: XML 1.0 document, UTF-8 Unicode text resumen.org: UTF-8 Unicode text
- file
- iconv, GNU recode, R read.table (encoding=…., fileEncoding=….)
- ? read.table
There are two approaches for reading input that is not in the local encoding. If the input is known to be UTF-8 or Latin1, use the ‘encoding’ argument to declare that. If the input is in some other encoding, then it may be translated on input. The ‘fileEncoding’ argument achieves this by setting up a connection to do the re-encoding into the current locale. Note that on Windows or other systems not running in a UTF-8 locale, this may not be possible.
- ? read.table
- utf-8, iso-8859-1 = latin-1, iso-8859-15 = latin-9
- sintaxis y tipos de datos en R
- class str names
- as.character as.numeric
- factor
- as.matrix as.data.frame
- ficheros grandes
- R
read.table (skip=...., nrows=....) # saltar filas read.table (colClasses=c(NA,"NULL"....) # saltar columnas
- bash, GNU coreutils, AWK
- número de filas:
wc -l fichero.txt
- número de columnas:
awk '{print NF}' fichero.txt # separado por blancos awk -F',' '{print NF}' fichero.txt # separado por comas
- cortar filas
head -n 100000 fichero.txt | tail -n 10000 # filas 90.001-100.000 split -l 10000 fichero.txt # dividir en trozos de 10.000 filas shuf -n 5000 fichero.txt > muestra.txt # muestrear 5.000 filas
- cortar columnas
cut -c -100 # los 100 primeros caracteres de cada renglón cut -d',' -f 3-10 # los campos del tercero al décimo de cada registro
- ejemplo
cut -d',' -f1 vuelos.csv | uniq -c # tarda tres minutos en carleos2 cut -d',' -f2 vuelos.csv | sort -n | uniq -c # tarda cuatro minutos en carleos2
- número de filas:
- mlr (miller johnkerl)
mlr --csvlite count-distinct -f Year vuelos.csv # tarda seis minutos en carleos2 mlr --csvlite count-distinct -f Month vuelos.csv # tarda siete minutos en carleos2
- PSPP
- tarda diez minutos en carleos2 para las dos variables
- http://www.gnu.org/software/pspp/
- Support for over 1 billion cases.
- Support for over 1 billion variables.
/home/manadine/dat/vuelos $ pspp PSPP is free software and you are welcome to distribute copies of it under certain conditions; type "show copying." to see the conditions. There is ABSOLUTELY NO WARRANTY for PSPP; type "show warranty." for details. GNU pspp 1.2.0 PSPP> get data /type=txt /file='vuelos.csv' /delimiters="," /firstcase=2 /variables=anno f4 mes f2. PSPP> display variables. Variable Descripción Posición ═══════════════════════════════ anno Formato: F4.0 1 mes Formato: F2.0 2 PSPP> frequencies /var=anno mes. aviso: El registro termina con datos que no forman parte de ningún campo. ... aviso: El registro termina con datos que no forman parte de ningún campo. anotación: Las advertencias (101) han superado el límite (100). Se detiene el procesamiento de sintaxis. anno ╭───────────────┬─────┬──────────┬──────────┬───────────────┬─────────────────╮ │ Etiqueta de │Valor│Frecuencia│Porcentaje│ Porcentaje │ Porcentaje │ │ Valor │ │ │ │ Válido │ Acumulado │ ╞═══════════════╪═════╪══════════╪══════════╪═══════════════╪═════════════════╡ │ │ 1987│ 1311826│ 1,06│ 1,06│ 1,06│ │ │ 1988│ 5202096│ 4,21│ 4,21│ 5,27│ │ │ 1989│ 5041200│ 4,08│ 4,08│ 9,35│ │ │ 1990│ 5270893│ 4,27│ 4,27│ 13,62│ │ │ 1991│ 5076925│ 4,11│ 4,11│ 17,73│ ╵ ╵ ╵ ╵ ╵ ╵ ╵ ╭───────────────┬─────┬──────────┬──────────┬───────────────┬─────────────────╮ │ Etiqueta de │Valor│Frecuencia│Porcentaje│ Porcentaje │ Porcentaje │ │ Valor │ │ │ │ Válido │ Acumulado │ ╞═══════════════╪═════╪══════════╪══════════╪═══════════════╪═════════════════╡ │ │ 1992│ 5092157│ 4,12│ 4,12│ 21,85│ │ │ 1993│ 5070501│ 4,10│ 4,10│ 25,96│ │ │ 1994│ 5180048│ 4,19│ 4,19│ 30,15│ │ │ 1995│ 5327435│ 4,31│ 4,31│ 34,46│ │ │ 1996│ 5351983│ 4,33│ 4,33│ 38,79│ │ │ 1997│ 5411843│ 4,38│ 4,38│ 43,18│ │ │ 1998│ 5384721│ 4,36│ 4,36│ 47,53│ │ │ 1999│ 5527884│ 4,47│ 4,47│ 52,01│ │ │ 2000│ 5683047│ 4,60│ 4,60│ 56,61│ │ │ 2001│ 5967780│ 4,83│ 4,83│ 61,44│ │ │ 2002│ 5271359│ 4,27│ 4,27│ 65,71│ │ │ 2003│ 6488540│ 5,25│ 5,25│ 70,96│ │ │ 2004│ 7129270│ 5,77│ 5,77│ 76,73│ │ │ 2005│ 7140596│ 5,78│ 5,78│ 82,51│ │ │ 2006│ 7141922│ 5,78│ 5,78│ 88,29│ │ │ 2007│ 7453215│ 6,03│ 6,03│ 94,33│ │ │ 2008│ 7009728│ 5,67│ 5,67│ 100,00│ ╞═══════════════╧═════╪══════════╪══════════╪═══════════════╪═════════════════╡ │ Total│ 123534969│ 100,0│ 100,0│ │ ╰─────────────────────┴──────────┴──────────┴───────────────┴─────────────────╯ anno ╭─────────────────┬─────────╮ │N Válido │123534969│ │ Perdidos│ 0│ │Media │ 1998,62│ │Desv Std │ 6,23│ │Mínimo │ 1987,00│ │Máximo │ 2008,00│ ╰─────────────────┴─────────╯ mes ╭───────────────┬─────┬──────────┬──────────┬───────────────┬─────────────────╮ │ Etiqueta de │Valor│Frecuencia│Porcentaje│ Porcentaje │ Porcentaje │ │ Valor │ │ │ │ Válido │ Acumulado │ ╞═══════════════╪═════╪══════════╪══════════╪═══════════════╪═════════════════╡ │ │ 1│ 10272489│ 8,32│ 8,32│ 8,32│ │ │ 2│ 9431225│ 7,63│ 7,63│ 15,95│ │ │ 3│ 10448039│ 8,46│ 8,46│ 24,41│ │ │ 4│ 10081982│ 8,16│ 8,16│ 32,57│ │ │ 5│ 10330467│ 8,36│ 8,36│ 40,93│ │ │ 6│ 10226946│ 8,28│ 8,28│ 49,21│ │ │ 7│ 10571942│ 8,56│ 8,56│ 57,77│ │ │ 8│ 10646835│ 8,62│ 8,62│ 66,39│ ╵ ╵ ╵ ╵ ╵ ╵ ╵ ╭───────────────┬─────┬──────────┬──────────┬───────────────┬─────────────────╮ │ Etiqueta de │Valor│Frecuencia│Porcentaje│ Porcentaje │ Porcentaje │ │ Valor │ │ │ │ Válido │ Acumulado │ ╞═══════════════╪═════╪══════════╪══════════╪═══════════════╪═════════════════╡ │ │ 9│ 9975954│ 8,08│ 8,08│ 74,46│ │ │ 10│ 10758658│ 8,71│ 8,71│ 83,17│ │ │ 11│ 10218176│ 8,27│ 8,27│ 91,44│ │ │ 12│ 10572256│ 8,56│ 8,56│ 100,00│ ╞═══════════════╧═════╪══════════╪══════════╪═══════════════╪═════════════════╡ │ Total│ 123534969│ 100,0│ 100,0│ │ ╰─────────────────────┴──────────┴──────────┴───────────────┴─────────────────╯ mes ╭─────────────────┬─────────╮ │N Válido │123534969│ │ Perdidos│ 0│ │Media │ 6,55│ │Desv Std │ 3,44│ │Mínimo │ 1,00│ │Máximo │ 12,00│ ╰─────────────────┴─────────╯ PSPP> quit.
- SQLlite3
/home/manadine/dat/vuelos $ sqlite3 SQLite version 3.27.2 2019-02-25 16:06:06 Enter ".help" for usage hints. Connected to a transient in-memory database. Use ".open FILENAME" to reopen on a persistent database. sqlite> .open vuelos.db sqlite> .mode csv sqlite> .import vuelos.csv vuelos sqlite> .quit
tarda quince minutos en carleos2 para importar los datos; para calcular las frecuencias de una variable, tarda unos cinco minutos:
/home/manadine/dat/vuelos $ sqlite3 vuelos.db SQLite version 3.27.2 2019-02-25 16:06:06 Enter ".help" for usage hints. sqlite> select Month, count(Month) from vuelos group by Month; select time('now'); 1|10272489 10|10758658 11|10218176 12|10572256 2|9431225 3|10448039 4|10081982 5|10330467 6|10226946 7|10571942 8|10646835 9|9975954 08:39:35 sqlite> .quit
- R