Successfully reported this slideshow.
Your SlideShare is downloading. ×

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

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Loading in …3
×

Check these out next

1 of 63 Ad

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

Download to read offline

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

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

Advertisement
Advertisement

More Related Content

Viewers also liked (20)

Advertisement

More from Marcel Caraciolo (20)

Recently uploaded (20)

Advertisement

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

  1. 1. Construindo Soluções Científicas com Big Data & MapReduce Marcel Caraciolo @marcelcaraciolo
  2. 2. Quem é Marcel ? Sergipano, porém recifense. Mestre em Ciência da Computação Co-founder Pingmind & PyCursos Cientista-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
  3. 3. Antes da Computação Da Computação Distribuída
  4. 4. Depois da Computação Da Computação Distribuída
  5. 5. Big Data, muitos dados. !"#$%"$#&'(')")( !"#$%&'(%$)*%+%),-+.),#$$) *#/(#*)01.#2%03) *$+,(!"#$%"$#&'(')")( !4'1-%$)*%+%5)6$'70)5)1$-18)0+9#%25) :%1.-(#)7#(#9%+#*5);2$)#+1<3)
  6. 6. !"#$%&'(')*"+$#"'' !"#$%*(.-.%'7/,( !"#$%$&'( 500%6&'216%./7%!.281&%0#.(1% ,"-./%('-0"&12%3/&124.(1% <$8(=.&.( )*+,"-.%(/%"01( !"#$%&'"()%*+% ;-(5*5"+'(/"5607-8( 91:.-/*1(9-.%'7/,( 9211/%7.&.%(1/&21% <#.6)%!1-'2=% :'(3.#%AB!% :'#37%6&.&1%723;1% ,>!?@% 2"-&*3&(.4.+*(/"5607-8(
  7. 7. !"#$%&'()#*+$ $ ,-.#(''/$ $ $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$
  8. 8. "<&!B',:+&*C! !"#$%&'! ! !())!*$++$,-!./&'/0!12)!*$++$,-!34$+5!6#&&6/! !789!:$++$,-!/&4';<!=.&'$&/!4!345! !>!"?!3464!@,'!4-4+5/$/!A&-&'46&3!34$+5! !!
  9. 9. "<&!B',:+&*C! !"#$%&'! ! !())!*$++$,-!./&'/0!12)!*$++$,-!34$+5!6#&&6/! !789!:$++$,-!/&4';<!=.&'$&/!4!345! !>!"?!3464!@,'!4-4+5/$/!A&-&'46&3!34$+5! !!
  10. 10. >,$!F(-G7$4H! !"#$%&''&(! ! !)*+!#,-.'&/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! !
  11. 11. !"#$%&'&$%"()*+",*+$-./0$ $ 12) .,12()$$ .& .& 12) $ .&3"'4$ .)1,5"'4$
  12. 12. Hadoop
  13. 13. !"#$%&'%(#)**+%,% !"#$%&"#'()*'(+(%"(&"#'(,-.%/#-/0,#'12,' "(,3#'4-("#'*%4/,%&0/#*'-#$."'5,2-#44%)3' 2)'(')#/62,7'21'-2882*%/9'.(,*6(,#:'
  14. 14. !"#$%&'()"'*&+&*'",)-&$(' !"#$%%!&'((#)&#&*!+)(,-%. .//'$)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'=#>))"'
  15. 15. !"#$%&'()*+),) !"##$%&'"()'*'+,-'.&/01&'*'23$'4,5%&6' ' '78193:&1:08&'5&93;/'"##$%&<=' ''''' ' ')&,819'>;$3;&' -&'./0&)01)2.(00$)$&03'4/)
  16. 16. !"#$%&"#"$'$()&*$+"$,&-../$0"#-$1.2$ 3+456.%+&7$-&*&$&8&79"+"$ :#;*$<+8+84=$/&>#28"$"#&2%)$ ?&%)+8#$7.4$&8&79"+"$ @#.A"/&%+B&7$&8&79"+"$ :2#8-$C8&79"+"$ @#8.<#$C8&79"+"$ D204$D+"%.E#29$ F2&0-$&8-$%.</7+&8%#$<&8&4#<#8*$ G+-#.$&8-$+<&4#$&8&79"+"$
  17. 17. !"#$%&'&$()*##+$,$-#./$-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.$$ $$ $
  18. 18. !"#$$%&'($)*)+',&-& <;;=%%(%:& /?+@%& A;B5%& C25::& 12+34#& 96:;& 0>;;(& !56%& 758& !"#$%& '#()%*+,%-!./0&
  19. 19. !"#$$%&#'()*'+,-$.&/&
  20. 20. !"#$%&'(& !""# $%&'()*+&,#-&.&/&010#
  21. 21. !"#$%&'()&& !""# !"#$$%&#'()*'+,)-#&./-&(0()-1&
  22. 22. !"#$$%&'$(%$)*)+,&-& !89:&&&& 5"%&6*#71*& .$/&+0"12*0& 3",2&30"12*0& 4"(*&4$#*&
  23. 23. MapReduce http://labs.google.com/papers/mapreduce.html
  24. 24. Exemplo de MapReduce from mrjob.job import MRJob import 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()
  25. 25. 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
  26. 26. Objetivos do MrJobs Se 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ê!
  27. 27. Passos importantes sudo easy_install mrjob
  28. 28. Vamos a uma demo... Texto da posse de Obama em 2009.
  29. 29. Desempenho MapReduce
  30. 30. Mais informações http://packages.python.org/mrjob/ https://github.com/Yelp/mrjob
  31. 31. Distributed Computing with mrJob https://github.com/Yelp/mrjob Elsayed et al: Pairwise Document Similarity in Large Collections with MapReduce
  32. 32. Distributed Computing with mrJob https://github.com/Yelp/mrjob Elsayed et al: Pairwise Document Similarity in Large Collections with MapReduce
  33. 33. Atepassar Recommendations http://atepassar.com Problema: Como recomendar novos amigos ?
  34. 34. Atepassar Recommendations http://atepassar.com
  35. 35. Atepassar Recommendations http://atepassar.com marcel;jonas,maria,jose,amanda "marcel" [["carol", 2], ["fabio", 1], ["fabiola", 1], ["patricia", 1], ["paula", 1]] maria;carol,fabiola,amanda,marcel "maria" [["jose", 2], ["patricia", 2], ["jonas", 1], ["paula", 1]] amanda;paula,patricia,maria,marcel "patricia" [["maria", 2], ["jose", 1], ["marcel", 1], ["paula", 1]] carol;maria,jose,patricia "paula" [["jonas", 1], ["marcel", 1], ["maria", 1], ["patricia", 1]] fabiola;maria "amanda" [["carol", 2], ["fabio", 1], ["fabiola", 1], ["jonas", 1], ["jose", 1]] paula;fabio,amanda "carol" [["amanda", 2], ["marcel", 2], ["fabiola", 1]] patricia;amanda,carol "fabio" [["amanda", 1], ["marcel", 1]] jose;marcel,carol "fabiola" [["amanda", 1], ["carol", 1], ["marcel", 1]] jonas;marcel,fabio "jonas" [["amanda", 1], ["jose", 1], ["maria", 1], ["paula", 1]] fabio;jonas,paula "jose" [["maria", 2], ["amanda", 1], ["jonas", 1], ["patricia", 1]] carla $python friends_recommender.py - r emr --num-ec2-instances 5 facebook_data.csv > output.dat
  36. 36. Atepassar Recommendations http://atepassar.com marcel;jonas,maria,jose,amanda "marcel" [["carol", 2], ["fabio", 1], ["fabiola", 1], ["patricia", 1], ["paula", 1]] maria;carol,fabiola,amanda,marcel "maria" [["jose", 2], ["patricia", 2], ["jonas", 1], ["paula", 1]] amanda;paula,patricia,maria,marcel "patricia" [["maria", 2], ["jose", 1], ["marcel", 1], ["paula", 1]] carol;maria,jose,patricia fabiola;maria marcel;jonas,maria,jose,amanda 1], ["patricia", 1]] "paula" [["jonas", 1], ["marcel", 1], ["maria", "amanda" [["carol", 2], ["fabio", 1], ["fabiola", 1], ["jonas", 1], ["jose", 1]] paula;fabio,amanda carol;maria,jose,patricia ["marcel", 2], ["fabiola", 1]] "carol" [["amanda", 2], patricia;amanda,carol jose;marcel,carol fabio;jonas,paula [["amanda", 1], ["marcel", 1]] "fabio" "fabiola" [["amanda", 1], ["carol", 1], ["marcel", 1]] jonas;marcel,fabio ... "jonas" [["amanda", 1], ["jose", 1], ["maria", 1], ["paula", 1]] fabio;jonas,paula "jose" [["maria", 2], ["amanda", 1], ["jonas", 1], ["patricia", 1]] carla $python friends_recommender.py - r emr --num-ec2-instances 5 facebook_data.csv > output.dat
  37. 37. Atepassar Recommendations http://atepassar.com fsim(u,i) = w1 f1(u,i) + w2 f2(u,i) + b, https://gist.github.com/3970945#file_atepassar_recommender.py
  38. 38. Atepassar Recommendations http://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.
  39. 39. Benchmarks Pure Python Python w/ Scipy MapReduce Dataset w/ dicts and Numpy (100 nodes small) MovieLens ~28 hrs ~12hrs ~= 5 hrs 100k http://www.grouplens.org/node/73 Pure python - Crab Crab Scipy Numpy Crab w/ MapReduce
  40. 40. Benchmarks Pure Python Python w/ Scipy MapReduce Dataset w/ dicts and Numpy (100 nodes small) MovieLens ~28 hrs ~12hrs ~= 5 hrs 100k http://www.grouplens.org/node/73 Pure python - Crab Crab Scipy Numpy Crab w/ MapReduce Time ellapsed ( Top-N similar items) 0 7.5 15 22.5 30
  41. 41. Benchmarks Pure Python Python w/ Scipy MapReduce Dataset w/ dicts and Numpy (100 nodes small) MovieLens ~28 hrs ~12hrs ~= 5 hrs 100k http://www.grouplens.org/node/73 Pure python - Crab Crab Scipy Numpy Crab w/ MapReduce Time ellapsed ( Top-N similar items) 0 7.5 15 22.5 30
  42. 42. Benchmarks Pure Python Python w/ Scipy MapReduce Dataset w/ dicts and Numpy (100 nodes small) MovieLens ~28 hrs ~12hrs ~= 5 hrs 100k http://www.grouplens.org/node/73 Pure python - Crab Crab Scipy Numpy Crab w/ MapReduce Time ellapsed ( Top-N similar items) 0 7.5 15 22.5 30
  43. 43. Benchmarks Pure Python Python w/ Scipy MapReduce Dataset w/ dicts and Numpy (100 nodes small) MovieLens ~28 hrs ~12hrs ~= 5 hrs 100k http://www.grouplens.org/node/73 Pure python - Crab Crab Scipy Numpy Crab w/ MapReduce Time ellapsed ( Top-N similar items) 0 7.5 15 22.5 30
  44. 44. A melhor parte!
  45. 45. Projetos interessantes Pandas: a data analysis library for Python, poised to give R a run for its money… http://pandas.pydata.org/ Estrutura de dados para manipulação rápida - slicing - indexing - subseting Handling missing data Agregações, Séries Temporais
  46. 46. Projetos interessantes http://discoproject.org/ 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).
  47. 47. Projetos interessantes Python & MongoDb http://api.mongodb.org/python/2.0/examples/ map_reduce.html 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;" ... "}")
  48. 48. Projetos interessantes Dumbo https://github.com/klbostee/dumbo/wiki/Short-tutorial Uma das primeiras bibliotecas em cima do MapReduce e Python. Complicado para começar e está desatualizada :(
  49. 49. Projetos interessantes http://pydoop.sourceforge.net/docs/index.html Um wrapper em Python em cima do Hadoop para computação distribuída. Legal, mas dá um trabalho para configurar.
  50. 50. Projetos interessantes https://developers.google.com/appengine/docs/python/ dataprocessing/ Mapreduce com Python na Google AppEngine Ainda experimental e fica “preso” à plataforma AppEngine.
  51. 51. Projetos interessantes http://scikit-learn.org/stable/ 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.
  52. 52. Projetos interessantes http://nltk.org/ Processamento de linguagem natural Várias ferramentas para tokenização, pos tagging, named entity recognition, classificadores, etc. Vários corpus disponíveis!
  53. 53. Projetos interessantes http://nltk.org/ Processamento de linguagem natural Fiquem de olho... Várias Pipeline for distributed Natural Language Processing, made in Python ferramentas para tokenização, https://github.com/NAMD/pypln pos tagging, named entity recognition, classificadores, etc. Vários corpus disponíveis!
  54. 54. Projetos interessantes Our Project’s Home Page http://muricoca.github.com/crab
  55. 55. Future Releases Planned Release 0.13 New home for python-recsys: https://github.com/python-recsys/crab New commiters: vinnigracindo, ocelma, fcurella Planned Release 0.14 Support to Item-Based Recommenders using MapReduce with MrJob
  56. 56. Join us! 1. Read our Wiki Page https://github.com/muricoca/crab/wiki/Developer-Resources 2. Check out our current sprints and open issues https://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
  57. 57. Vários outros ... Numpy milk NetworkX Orange Matplotlib Scipy StatsModels PyBrain
  58. 58. Livros recomendados
  59. 59. Livros recomendados For free... http://shop.oreilly.com/product/0636920022640.do?cmp=il-radar-ebooks-big-data-now-radar
  60. 60. Livros recomendados For free... http://infolab.stanford.edu/~ullman/mmds/book.pdf
  61. 61. Artigos recomendados For free... http://aimotion.blogspot.com.br/2012/10/atepassar- recommendations-recommending.html http://aimotion.blogspot.com.br/2012/08/introduction-to- recommendations-with.html
  62. 62. Artigos recomendados For free... http://aimotion.blogspot.com.br/2012/10/atepassar- recommendations-recommending.html http://aimotion.blogspot.com.br/2012/08/introduction-to- recommendations-with.html https://github.com/marcelcaraciolo/recsys-mapreduce-mrjob
  63. 63. Construindo Soluções Científicas com Big Data & MapReduce Marcel Caraciolo @marcelcaraciolo marcel@atepassar.com

×