construindo soluções científicas com big data & mapreduce

63
Construindo Soluções Científicas com Big Data & MapReduce Marcel Caraciolo @marcelcaraciolo

Upload: marcel-caraciolo

Post on 18-Dec-2014

2.792 views

Category:

Technology


4 download

DESCRIPTION

My Presentation at PythonBrasil 2012 about building scientific solutions with Big Data and MapReduce using Python.

TRANSCRIPT

Page 1: Construindo Soluções Científicas com Big Data & MapReduce

Construindo Soluções Científicas com Big Data & MapReduce

Marcel Caraciolo@marcelcaraciolo

Page 2: Construindo Soluções Científicas com Big Data & MapReduce

Quem é Marcel ? Sergipano, porém recifense.Mestre em Ciência da Computação

Co-founder Pingmind & PyCursosCientista-Chefe do Atepassar.com

Evangelista Python, programador e admirador das “ciências ocultas” providas pela Inteligência Artificial

Escritor de blog: http://www.mobideia.com & http://aimotion.blogspot.com

Page 3: Construindo Soluções Científicas com Big Data & MapReduce

Antes da Computação Da Computação Distribuída

Page 4: Construindo Soluções Científicas com Big Data & MapReduce

Depois da Computação Da Computação Distribuída

Page 5: Construindo Soluções Científicas com Big Data & MapReduce

!"#$%"$#&'(')")(

*$+,(!"#$%"$#&'(')")(

!"#$%&'(%$)*%+%),-+.),#$$)*#/(#*)01.#2%03)

!4'1-%$)*%+%5)6$'70)5)1$-18)0+9#%25):%1.-(#)7#(#9%+#*5);2$)#+1<3)

Big Data, muitos dados.

Page 6: Construindo Soluções Científicas com Big Data & MapReduce

!"#$%&'(')*"+$#"''

!"#$%$&'()*+,"-.%(/%"01(

!"#$%&'"()%*+%

2"-&*3&(.4.+*(/"5607-8(

,"-./%('-0"&12%3/&124.(1%

500%6&'216%./7%!.281&%0#.(1%

91:.-/*1(9-.%'7/,(;-(5*5"+'(/"5607-8(

9211/%7.&.%(1/&21%:'#37%6&.&1%723;1%

<#.6)%!1-'2=%

,>!?@%:'(3.#%AB!%

!"#$%*(.-.%'7/,(

<$8(=.&.(

Page 7: Construindo Soluções Científicas com Big Data & MapReduce

!"#$%&'()#*+$$,-.#(''/$$

$011$*2))2'3$-.45#$67#&7$-7$'8$9-&."$:;<:=$$<$23$>$?3@#&3#@$67#&7$"-5#$-$,-.#(''/$$-..'63@$$$$9'&#$@"-3$>;$(2))2'3$A2#.#7$'8$.'3@#3@$BC#($$)23/7=$3#C7$7@'&2#7=$()'D$A'7@7=$3'@#7=$A"'@'$$-)(6*7=$#@.EF$7"-&#G$#-."$*'3@"E$

$$H')G7$>;%I$'8$G-@-$8'&$-3-)J727=$-GG7$<:$!I$'8$$.'*A&#77#G$G-@-$G-2)J$

Page 8: Construindo Soluções Científicas com Big Data & MapReduce

!"#$%&'!!

!())!*$++$,-!./&'/0!12)!*$++$,-!34$+5!6#&&6/!!789!:$++$,-!/&4';<!=.&'$&/!4!345!!>!"?!3464!@,'!4-4+5/$/!A&-&'46&3!34$+5!!!

"<&!B',:+&*C!

Page 9: Construindo Soluções Científicas com Big Data & MapReduce

!"#$%&'!!

!())!*$++$,-!./&'/0!12)!*$++$,-!34$+5!6#&&6/!!789!:$++$,-!/&4';<!=.&'$&/!4!345!!>!"?!3464!@,'!4-4+5/$/!A&-&'46&3!34$+5!!!

"<&!B',:+&*C!

Page 10: Construindo Soluções Científicas com Big Data & MapReduce

!"#$%&''&(!!

!)*+!#,-.'&/0!.'$('1!!2++!#,-.'&/0!3#$4'!!5$6-44$/0!3#$4'!0&378!9-(!!*+++!.'$('!!):!;<!0&#&!9-(!&/&78'3'!=$/$(&#$0!0&378!!!

>(&03?-/&7!0&#&!'#-(&=$1!#$6,/3@.$'!A!&/&78'3'!#--7'!B.'#!0-!/-#!C-(D!&#!#,$'$!'6&7$'!E!!

>,$!F(-G7$4H!

Page 11: Construindo Soluções Científicas com Big Data & MapReduce

!"#$%&'&$%"()*+",*+$-./0$

.,12()$$

.&3"'4$ .)1,5"'4$

.&12)

$ .&12)$

Page 12: Construindo Soluções Científicas com Big Data & MapReduce

Hadoop

Page 13: Construindo Soluções Científicas com Big Data & MapReduce

!"#$%&'%(#)**+%,%

!"#$%&"#'()*'(+(%"(&"#'(,-.%/#-/0,#'12,'"(,3#'4-("#'*%4/,%&0/#*'-#$."'5,2-#44%)3'2)'(')#/62,7'21'-2882*%/9'.(,*6(,#:'

Page 14: Construindo Soluções Científicas com Big Data & MapReduce

!"#$%&'()"'*&+&*'",)-&$('!"#$%%!&'((#)&#&*!+)(,-%.

.//'$)0(,123(),4'

5('%#4')0&')6'(%&'4(,)07&4('&$)'484(&94':1(%'*#,7&'0)')6'432'",)-&$(4'

;#%))'%#4')0&')6'(%&'2177&4('104(#**#<)0'=#>))"'?300107'@///4')6'4&,+&,4')0'=#>))"'

Page 15: Construindo Soluções Científicas com Big Data & MapReduce

!"#$%&'()*+),)

!"##$%&'"()'*'+,-'.&/01&'*'23$'4,5%&6''

'78193:&1:08&'5&93;/'"##$%&<=''''''

' ')&,819'>;$3;&'

-&'./0&)01)2.(00$)$&03'4/)

Page 16: Construindo Soluções Científicas com Big Data & MapReduce

!"#$%&"#"$'$()&*$+"$,&-../$0"#-$1.2$

3+456.%+&7$-&*&$&8&79"+"$

:#;*$<+8+84=$/&>#28"$"#&2%)$?&%)+8#$7.4$&8&79"+"$

@#.A"/&%+B&7$&8&79"+"$

@#8.<#$C8&79"+"$D204$D+"%.E#29$F2&0-$&8-$%.</7+&8%#$<&8&4#<#8*$G+-#.$&8-$+<&4#$&8&79"+"$

:2#8-$C8&79"+"$

Page 17: Construindo Soluções Científicas com Big Data & MapReduce

!"#$%&'&$()*##+$,$-#./$-0&1$

2$34)5#.637$$2$8)9':##;$$2$<##/-'$$2$=>?$$2$@0&.'A$2$B)&1CD4$$2$E'F$G#H;$I04'&$$2$G)"##J$$2$IF0K'H$2$B0.;'*$0.$$$$$

Page 18: Construindo Soluções Científicas com Big Data & MapReduce

!"#$$%&'($)*)+',&-&

!"#$%& '#()%*+,%-!./0&

12+34#&

!56%& 758&

96:;&

<;;=%%(%:&

0>;;(&

/?+@%& A;B5%& C25::&

Page 19: Construindo Soluções Científicas com Big Data & MapReduce

!"#$$%&#'()*'+,-$.&/&

Page 20: Construindo Soluções Científicas com Big Data & MapReduce

!"#$%&'(&

!""#

$%&'()*+&,#-&.&/&010#

Page 21: Construindo Soluções Científicas com Big Data & MapReduce

!"#$%&'()&&

!""#

!"#$$%&#'()*'+,)-#&./-&(0()-1&

Page 22: Construindo Soluções Científicas com Big Data & MapReduce

!"#$$%&'$(%$)*)+,&-&

.$/&+0"12*0&

3",2&30"12*0&

4"(*&4$#*&

5"%&6*#71*&!89:&&&&

Page 24: Construindo Soluções Científicas com Big Data & MapReduce

Exemplo de MapReducefrom mrjob.job import MRJobimport re

WORD_RE = re.compile(r"[\w']+")

class MRWordFreqCount(MRJob):

def mapper(self, _, line): for word in WORD_RE.findall(line): yield (word.lower(), 1)

def reducer(self, word, counts): yield (word, sum(counts))

if __name__ == '__main__': MRWordFreqCount().run()

Page 25: Construindo Soluções Científicas com Big Data & MapReduce

Projeto MrJob

Criado pela Equipe de Engenharia do Yelp

Totalmente Open-Source

Todo em Python

Utiliza Map-Reduce para Processamento

Permite rodar tanto no Amazon EMR como no Hadoop

Page 26: Construindo Soluções Científicas com Big Data & MapReduce

Objetivos do MrJobsSe você quer aprender MapReduce, ele é para você

Se você tem um problema cavalar e precisa de muito processamento e não está afim de mexer em Hadoop

Se você já tem um cluster Hadoop e quer rodar scripts Python

Se você quer migrar seu código Python do Hadoop para o EMR

Se você não quer escrever Python (Impossível!), não é para você!

Page 27: Construindo Soluções Científicas com Big Data & MapReduce

Passos importantes

sudo easy_install mrjob

Page 28: Construindo Soluções Científicas com Big Data & MapReduce

Vamos a uma demo...

Texto da posse de Obama em 2009.

Page 29: Construindo Soluções Científicas com Big Data & MapReduce

Desempenho MapReduce

Page 30: Construindo Soluções Científicas com Big Data & MapReduce

Mais informações

http://packages.python.org/mrjob/

https://github.com/Yelp/mrjob

Page 31: Construindo Soluções Científicas com Big Data & MapReduce

Distributed Computing with mrJobhttps://github.com/Yelp/mrjob

Elsayed et al: Pairwise Document Similarity in Large Collections with MapReduce

Page 32: Construindo Soluções Científicas com Big Data & MapReduce

Distributed Computing with mrJobhttps://github.com/Yelp/mrjob

Elsayed et al: Pairwise Document Similarity in Large Collections with MapReduce

Page 33: Construindo Soluções Científicas com Big Data & MapReduce

Atepassar Recommendationshttp://atepassar.com

Problema: Como recomendar novos amigos ?

Page 34: Construindo Soluções Científicas com Big Data & MapReduce

Atepassar Recommendationshttp://atepassar.com

Page 35: Construindo Soluções Científicas com Big Data & MapReduce

Atepassar Recommendationshttp://atepassar.com

marcel;jonas,maria,jose,amandamaria;carol,fabiola,amanda,marcelamanda;paula,patricia,maria,marcelcarol;maria,jose,patriciafabiola;mariapaula;fabio,amandapatricia;amanda,caroljose;marcel,caroljonas;marcel,fabiofabio;jonas,paulacarla

"marcel" [["carol", 2], ["fabio", 1], ["fabiola", 1], ["patricia", 1], ["paula", 1]]"maria" [["jose", 2], ["patricia", 2], ["jonas", 1], ["paula", 1]]"patricia" [["maria", 2], ["jose", 1], ["marcel", 1], ["paula", 1]]"paula" [["jonas", 1], ["marcel", 1], ["maria", 1], ["patricia", 1]]"amanda" [["carol", 2], ["fabio", 1], ["fabiola", 1], ["jonas", 1], ["jose", 1]]"carol" [["amanda", 2], ["marcel", 2], ["fabiola", 1]]"fabio" [["amanda", 1], ["marcel", 1]]"fabiola" [["amanda", 1], ["carol", 1], ["marcel", 1]]"jonas" [["amanda", 1], ["jose", 1], ["maria", 1], ["paula", 1]]"jose" [["maria", 2], ["amanda", 1], ["jonas", 1], ["patricia", 1]]

$python friends_recommender.py - r emr --num-ec2-instances 5 facebook_data.csv > output.dat

Page 36: Construindo Soluções Científicas com Big Data & MapReduce

Atepassar Recommendationshttp://atepassar.com

marcel;jonas,maria,jose,amandamaria;carol,fabiola,amanda,marcelamanda;paula,patricia,maria,marcelcarol;maria,jose,patriciafabiola;mariapaula;fabio,amandapatricia;amanda,caroljose;marcel,caroljonas;marcel,fabiofabio;jonas,paulacarla

"marcel" [["carol", 2], ["fabio", 1], ["fabiola", 1], ["patricia", 1], ["paula", 1]]"maria" [["jose", 2], ["patricia", 2], ["jonas", 1], ["paula", 1]]"patricia" [["maria", 2], ["jose", 1], ["marcel", 1], ["paula", 1]]"paula" [["jonas", 1], ["marcel", 1], ["maria", 1], ["patricia", 1]]"amanda" [["carol", 2], ["fabio", 1], ["fabiola", 1], ["jonas", 1], ["jose", 1]]"carol" [["amanda", 2], ["marcel", 2], ["fabiola", 1]]"fabio" [["amanda", 1], ["marcel", 1]]"fabiola" [["amanda", 1], ["carol", 1], ["marcel", 1]]"jonas" [["amanda", 1], ["jose", 1], ["maria", 1], ["paula", 1]]"jose" [["maria", 2], ["amanda", 1], ["jonas", 1], ["patricia", 1]]

$python friends_recommender.py - r emr --num-ec2-instances 5 facebook_data.csv > output.dat

marcel;jonas,maria,jose,amandacarol;maria,jose,patriciafabio;jonas,paula...

Page 37: Construindo Soluções Científicas com Big Data & MapReduce

Atepassar Recommendationshttp://atepassar.com

fsim(u,i) = w1 f1(u,i) + w2 f2(u,i) + b,

https://gist.github.com/3970945#file_atepassar_recommender.py

Page 38: Construindo Soluções Científicas com Big Data & MapReduce

Atepassar Recommendationshttp://atepassar.com

Celery - para agendamento dos jobs coletores e executores.

mrJob - para mapreduce e acesso ao Hadoop

MongoDb - para armazenamento das recomendações

Boto - acesso aos files do S3.

Page 39: Construindo Soluções Científicas com Big Data & MapReduce

Benchmarks

DatasetPure Python

w/ dictsPython w/ Scipy

and NumpyMapReduce(100 nodes small)

MovieLens 100k ~28 hrs ~12hrs ~= 5 hrs

http://www.grouplens.org/node/73

Pure python - Crab Crab Scipy NumpyCrab w/ MapReduce

Page 40: Construindo Soluções Científicas com Big Data & MapReduce

Benchmarks

DatasetPure Python

w/ dictsPython w/ Scipy

and NumpyMapReduce(100 nodes small)

MovieLens 100k ~28 hrs ~12hrs ~= 5 hrs

http://www.grouplens.org/node/73

0 7.5 15 22.5 30

Time ellapsed ( Top-N similar items)

Pure python - Crab Crab Scipy NumpyCrab w/ MapReduce

Page 41: Construindo Soluções Científicas com Big Data & MapReduce

Benchmarks

DatasetPure Python

w/ dictsPython w/ Scipy

and NumpyMapReduce(100 nodes small)

MovieLens 100k ~28 hrs ~12hrs ~= 5 hrs

http://www.grouplens.org/node/73

0 7.5 15 22.5 30

Time ellapsed ( Top-N similar items)

Pure python - Crab Crab Scipy NumpyCrab w/ MapReduce

Page 42: Construindo Soluções Científicas com Big Data & MapReduce

Benchmarks

DatasetPure Python

w/ dictsPython w/ Scipy

and NumpyMapReduce(100 nodes small)

MovieLens 100k ~28 hrs ~12hrs ~= 5 hrs

http://www.grouplens.org/node/73

0 7.5 15 22.5 30

Time ellapsed ( Top-N similar items)

Pure python - Crab Crab Scipy NumpyCrab w/ MapReduce

Page 43: Construindo Soluções Científicas com Big Data & MapReduce

Benchmarks

DatasetPure Python

w/ dictsPython w/ Scipy

and NumpyMapReduce(100 nodes small)

MovieLens 100k ~28 hrs ~12hrs ~= 5 hrs

http://www.grouplens.org/node/73

0 7.5 15 22.5 30

Time ellapsed ( Top-N similar items)

Pure python - Crab Crab Scipy NumpyCrab w/ MapReduce

Page 44: Construindo Soluções Científicas com Big Data & MapReduce

A melhor parte!

Page 45: Construindo Soluções Científicas com Big Data & MapReduce

Projetos interessantes

Estrutura de dados para manipulação rápida - slicing - indexing - subseting

Handling missing dataAgregações, Séries Temporais

Pandas: a data analysis library for Python, poised to give R a run for its money… http://pandas.pydata.org/

Page 46: Construindo Soluções Científicas com Big Data & MapReduce

Projetos interessantes

Outro framework para computação distribuída com Python com MapReduce.

Criado pelo Instituto Nokia.

Backend dele é escrito em Erlang (funcional, concorrente e bem escalável!)

Não utiliza o FileSystem mais usado HDFS e sim um novo padrão por eles (DDFS).

http://discoproject.org/

Page 47: Construindo Soluções Científicas com Big Data & MapReduce

Projetos interessantes

http://api.mongodb.org/python/2.0/examples/map_reduce.html

Python & MongoDb

MongoDb - Banco de Dados Não relacional (NoSQL)

Possui suporte nativo built-in para fazer MapReduce.

Escrever o código em JS e não é muito legível e fica preso ao Mongo ...

>>> reduce = Code("function (key, values) {"... " var total = 0;"... " for (var i = 0; i < values.length; i++) {"... " total += values[i];"... " }"... " return total;"... "}")

Page 48: Construindo Soluções Científicas com Big Data & MapReduce

Projetos interessantes

https://github.com/klbostee/dumbo/wiki/Short-tutorial

Dumbo

Uma das primeiras bibliotecas em cima do MapReduce e Python.

Complicado para começar e está desatualizada :(

Page 49: Construindo Soluções Científicas com Big Data & MapReduce

Projetos interessantes

Um wrapper em Python em cima do Hadoop para computação distribuída.

http://pydoop.sourceforge.net/docs/index.html

Legal, mas dá um trabalho para configurar.

Page 50: Construindo Soluções Científicas com Big Data & MapReduce

Projetos interessantes

Mapreduce com Python na Google AppEngine

https://developers.google.com/appengine/docs/python/dataprocessing/

Ainda experimental e fica “preso” à plataformaAppEngine.

Page 51: Construindo Soluções Científicas com Big Data & MapReduce

Projetos interessantes

Algoritmos de aprendizagem de máquina

Supervisionados & Não supervisionados

Pré-processamento, extração de dados

Avaliação de classificadores, Pipeline,seleção de atributos.

http://scikit-learn.org/stable/

Page 52: Construindo Soluções Científicas com Big Data & MapReduce

Projetos interessantes

Processamento de linguagem natural

Várias ferramentas para tokenização,pos tagging, named entity recognition,classificadores, etc.

Vários corpus disponíveis!

http://nltk.org/

Page 53: Construindo Soluções Científicas com Big Data & MapReduce

Projetos interessantes

Processamento de linguagem natural

Várias ferramentas para tokenização,pos tagging, named entity recognition,classificadores, etc.

Vários corpus disponíveis!

http://nltk.org/

Fiquem de olho... Pipeline for distributed Natural Language Processing, made in Python

https://github.com/NAMD/pypln

Page 54: Construindo Soluções Científicas com Big Data & MapReduce

Projetos interessantes

Our Project’s Home Page

http://muricoca.github.com/crab

Page 55: Construindo Soluções Científicas com Big Data & MapReduce

Future Releases

Planned Release 0.13New home for python-recsys:

https://github.com/python-recsys/crab

Planned Release 0.14

Support to Item-Based Recommenders using MapReduce with MrJob

New commiters: vinnigracindo, ocelma, fcurella

Page 56: Construindo Soluções Científicas com Big Data & MapReduce

Join us!

1. Read our Wiki Pagehttps://github.com/muricoca/crab/wiki/Developer-Resources

2. Check out our current sprints and open issueshttps://github.com/muricoca/crab/issues

3. Forks, Pull Requests mandatory

4. Join us at irc.freenode.net #muricoca or at our discussion list

http://groups.google.com/group/scikit-crab

Page 57: Construindo Soluções Científicas com Big Data & MapReduce

Vários outros ...

Matplotlib

StatsModelsScipy

Numpy

Matplotlib

NetworkX

PyBrain

milk

Orange

Page 58: Construindo Soluções Científicas com Big Data & MapReduce

Livros recomendados

Page 59: Construindo Soluções Científicas com Big Data & MapReduce

Livros recomendados

http://shop.oreilly.com/product/0636920022640.do?cmp=il-radar-ebooks-big-data-now-radar

For free...

Page 60: Construindo Soluções Científicas com Big Data & MapReduce

Livros recomendados

For free...

http://infolab.stanford.edu/~ullman/mmds/book.pdf

Page 63: Construindo Soluções Científicas com Big Data & MapReduce

Construindo Soluções Científicas com Big Data & MapReduce

Marcel Caraciolo@marcelcaraciolo

[email protected]