Upgrade to Pro — share decks privately, control downloads, hide ads and more …

SciPyJapan2019: Let's Enjoy the Python World Us...

komo_fr
April 24, 2019

SciPyJapan2019: Let's Enjoy the Python World Using Network Analysis

komo_fr

April 24, 2019
Tweet

More Decks by komo_fr

Other Decks in Technology

Transcript

  1. 0VUMJOF  8IBUJTUIF3FGFSFODF3FMBUJPOTIJQPG1&1T   8IZBN*EPJOHUIJT  .PUJWBUJPO  

    )PX   /FUXPSL"OBMZTJT/FUXPSL9  1SFQBSFBOE4FF%BUB  %SBXUIFFOUJSFOFUXPSL  $PNNVOJUZ%FUFDUJPO 1&1ͷࢀরؔ܎ͬͯԿʁ ԿͰ΍ͬͯΔͷʁ ۩ମతʹͲ͏͢Μͷʁ
  2. 0VUMJOF  8IBUJTUIF3FGFSFODF3FMBUJPOTIJQPG1&1T   8IZBN*EPJOHUIJT  .PUJWBUJPO  

    )PX   /FUXPSL"OBMZTJT/FUXPSL9  1SFQBSFBOE4FF%BUB  %SBXUIFFOUJSFOFUXPSL  $PNNVOJUZ%FUFDUJPO 1&1ͷࢀরؔ܎ͬͯԿʁ ԿͰ΍ͬͯΔͷʁ ۩ମతʹͲ͏͢Μͷʁ
  3. 8IBUJT1&1 1ZUIPO&OIBODFNFOU1SPQPTBMT 1SPQPTBMTUPCFNBEFJOUIFFWFOUPGNBKPS DIBOHFTJO1ZUIPOGFBUVSF QSPDFTTFT BOE FOWJSPONFOUT 1&1T  

    :PVDBOTFFBMM1&1TPOQZUIPOPSH 1&1IUUQTXXXQZUIPOPSHEFWQFQT 1ZUIPOͷػೳ΍ϓϩηεɾ؀ڥͳͲʹ͍ͭͯେ͖ͳมߋ͕͋Δͱ͖ʹॻ͔ΕΔఏҊॻ
  4. 8IBUEPZPVLOPXGSPN1&1 1ZUIPO`TIJTUPSZ 8IBUQSPQPTBMTIBWFCFFONBEFTPGBS  8IBUXBTUIFEJTDVTTJPO  'JOBMMZ XBTJUBDDFQUFEPSSFKFDUFE  8IZXBTJUSFKFDUFE

     ʜʜ ʢࠓ·ͰͲͷΑ͏ͳఏҊ͕͋ͬͨͷ͔ʣ ʢͲͷΑ͏ͳ͜ͱ͕ٞ࿦͞Εͨͷ͔ʣ ࠷ऴతʹͦͷఏҊ͸"DDFQU͞Εͨͷ͔3FKFDU͞Εͨͷ͔ʣ ͳͥ3FKFDU͞Εͨͷ͔ʣ
  5. 3FGFSFODF3FMBUJPOTIJQPG1&1T 1&1 1&1 1&1 Style Guide for Python Code The

    Zen of Python Docstring Conventions The "Specification" text comes mostly verbatim from the Python Style Guide [4] essay by Guido van Rossum.
  6. 0VUMJOF  8IBUJTUIF3FGFSFODF3FSBUJPOTIJQPG1&1T   8IZBN*EPJOHUIJT  .PUJWBUJPO  

    )PX   /FUXPSL"OBMZTJT/FUXPSL9  1SFQBSFBOE4FF%BUB  %SBXUIFFOUJSFOFUXPSL  $PNNVOJUZ%FUFDUJPO
  7. 0VUMJOF  8IBUJTUIF3FGFSFODF3FMBUJPOTIJQPG1&1T   8IZBN*EPJOHUIJT  .PUJWBUJPO  

    )PX   /FUXPSL"OBMZTJT/FUXPSL9  1SFQBSFBOE4FF%BUB  %SBXUIFFOUJSFOFUXPSL  $PNNVOJUZ%FUFDUJPO
  8. "OBMZUJDBM.FUIPET5PPMT 1ZUIPO /FUXPSL9 QZUIPOJHSBQI 3 J(SBQI +BWB4DSJQU %KT POMZ WJTVBMJ[BUJPO

    (6*"QQT $ZUPTDBQF (FQIJ QBKFL 7JTVBMJ[BUJPO $FOUSBMJUZNFBTVSFT $PNNVOJUZ%FUFDUJPO FUDʜ .FUIPET 5PPMT ख๏΋πʔϧ΋৭ʑ͋ΔΑ
  9. /FUXPSL9 1ZUIPOQBDLBHFGPSDPNQMFYOFUXPSLT MBUFTU   5IJTWFSTJPOTVQQPSUTPOMZ1ZUIPO 5IFDPEFQSFTFOUFEJOUIJTTMJEFTIPVMECFSVOXJUI /FUXPSL9PSIJHIFS NetworkX is

    a Python package for the creation, manipulation, and study of the structure, dynamics, and functions of complex networks. IUUQTOFUXPSLYHJUIVCJP 1ZUIPOͰෳࡶωοτϫʔΫΛѻ͏ͨΊͷύοέʔδ ࠷৽൛͸ ͜ͷηογϣϯʹग़ͯ͘Δίʔυ͸ɺ1ZUIPOҎ্Ͱಈ͔ͯ͠Ͷ
  10. 0VUMJOF  8IBUJTUIF3FGFSFODF3FMBUJPOTIJQPG1&1T   8IZBN*EPJOHUIJT  .PUJWBUJPO  

    )PX   /FUXPSL"OBMZTJT/FUXPSL9  1SFQBSFBOE4FF%BUB  %SBXUIFFOUJSFOFUXPSL  $PNNVOJUZ%FUFDUJPO σʔλΛ༻ҙͯ͠ݟͯΈΑ͏
  11. MJOLJOGPSNBUJPO   )PXUP.BLF/FUXPSL4USVDUVSF !35    Style Guide

    for Python Code The Zen of Python Docstring Conventions 1&1 1&1 1&1 1&1    1&1    1&1    BEKBDFODZNBUSJY TUBSU FOE 1&1 1&1 1&1 1&1 1&1 1&1 FEHFMJTU ωοτϫʔΫߏ଄ͷ࡞Γํ ྡ઀ߦྻ ΤοδϦετ
  12. 1&1 1&1 1&1 1&1    1&1  

     1&1    MJOLJOGPSNBUJPO   &YUSBDUBUBHTXJUI#FBVUJGVM4PVQ
  13. MJOLJOGPSNBUJPO   OYGSPN@QBOEBT@BEKBDFODZ import pandas as pd import networkx

    as nx adj_df = pd.read_csv(‘adjacency_matrix.csv’) # NetworkX 2.2 pep_graph = nx.from_pandas_adjacency(adj_df, create_using=nx.DiGraph)
  14. MJOLJOGPSNBUJPO   $POpSN print(nx.info(pep_graph)) Name: Type: DiGraph Number of

    nodes: 486 Number of edges: 964 Average in degree: 1.9835 Average out degree: 1.9835 pep_graph[‘0001'] # Confirm about PEP 1 AtlasView({'0001': {'weight': 1.0}, '0002': {'weight': 1.0}, '0007': {'weight': 1.0}, …
  15. l5ZQFz 4UBOEBSET5SBDL EFTDSJCFTBOFXGFBUVSFPSJNQMFNFOUBUJPOGPS1ZUIPO FHʣ1&15ZQF)JOUT 1&15IFQBUIMJCNPEVMFPCKFDU PSJFOUFEpMFTZTUFNQBUIT *OGPSNBUJPOBM EFTDSJCFTB1ZUIPOEFTJHOJTTVF PSQSPWJEFTHFOFSBMHVJEFMJOFTPS JOGPSNBUJPOUPUIF1ZUIPODPNNVOJUZ

    CVUEPFTOPUQSPQPTFB OFXGFBUVSF FH 1&11ZUIPO3FMFBTF4DIFEVMF 1&15IF5IFPSZPG 5ZQF)JOUT 1SPDFTT EFTDSJCFTBQSPDFTTTVSSPVOEJOH1ZUIPO PSQSPQPTFTBDIBOHF UP PSBOFWFOUJO BQSPDFTT FH 1&11VSQPTFBOE(VJEFMJOFT 1&11ZUIPO %PDVNFOUBUJPO5SBOTMBUJPOT ৽͍͠ػೳʹؔ͢Δ΋ͷ ΨΠυϥΠϯͳͲɻ৽ػೳͷఏҊ͸͠ͳ͍ ϓϩηεʹؔ͢Δ΋ͷ
  16. 4UBUVT"QSJM'PPM 1&1Š#%'-3FUJSFNFOU KPLF1&1 Guido leaves Python in the good hands

    of its new leader and its vibrant community, in order to train for his lifelong dream of climbing Mount Everest.
  17. "EE)FBEFS%BUBBT/PEF`T"UUSJCVUF 5JUMF 4UZMF(VJEFGPS 1ZUIPO$PEF 4UBUVT "DUJWF 5ZQF 1SPDFTT $SFBUFE +VM

    5JUMF ʜ 4UBUVT ʜ 5ZQF ʜ $SFBUFE ʜ 5JUMF ʜ 4UBUVT ʜ 5ZQF ʜ $SFBUFE ʜ    ͜ΕΒͷϔομ৘ใΛɺϊʔυͷଐੑͱͯ͠෇༩͢Δ
  18. for column_name, series in header_df.iteritems(): nx.set_node_attributes(pep_graph, dict(series), column_name) # Confirm

    pep_graph.nodes[‘0001'] {'Created': '13-Jun-2000', 'Status': 'Active', 'Title': 'PEP Purpose and Guidelines', 'Type': 'Process', } 1&1`T)FBEFS OYTFU@OPEF@BUUSJCVUFT
  19. 0VUMJOF  8IBUJTUIF3FGFSFODF3FMBUJPOTIJQPG1&1T   8IZBN*EPJOHUIJT  .PUJWBUJPO  

    )PX   /FUXPSL"OBMZTJT/FUXPSL9  1SFQBSFBOE4FF%BUB  %SBXUIFFOUJSFOFUXPSL  $PNNVOJUZ%FUFDUJPO ωοτϫʔΫશମΛඳըͯ͠ΈΔ
  20. plt.figure(figsize=(110, 110)) # Calc Layout position_dict = nx.nx_agraph.graphviz_layout(pep_graph, prog='fdp') #

    Draw nx.draw_networkx_nodes(pep_graph, pos=position_dict, node_color="#ffa1a1", node_size=1200) nx.draw_networkx_labels(pep_graph, pos=position_dict, font_size=30, alpha=0.7) nx.draw_networkx_edges(pep_graph, pos=position_dict, alpha=0.7, arrowsize=30) plt.show() %SBXJOH IUUQTOFUXPSLYHJUIVCJPEPDVNFOUBUJPOTUBCMFSFGFSFODFESBXJOHIUNM /FUXPSL9͸؆୯ͳඳըͷػೳΛඋ͍͑ͯΔ
  21. 2VJ[ 8IJDI1&1IBTUIFIJHIFTUJOEFHSFF  " 1&14UZMF(VJEFGPS1ZUIPO$PEF
    # 1&11&11VSQPTFBOE(VJEFMJOFT


      $ 1&15ZQF)JOUT
   Ұ൪ೖ࣍਺͕ߴ͍ʢ୔ࢁͷ1&1͔Βࢀর͞Ε͍ͯΔ1&1ʣ͸Կʁ
  22. 0VUMJOF  8IBUJTUIF3FGFSFODF3FMBUJPOTIJQPG1&1T   8IZBN*EPJOHUIJT  .PUJWBUJPO  

    )PX   /FUXPSL"OBMZTJT/FUXPSL9  1SFQBSFBOE4FF%BUB  %SBXUIFFOUJSFOFUXPSL  $PNNVOJUZ%FUFDUJPO
  23. 4PNFUIJOHMJLFBNBQ • ݁ہͷͱ͜Ζɺ࣮ࡍͲ͏ͳͷ͔͸ݱ஍ʹ଍ΛӡͿʢ= PEPͷத਎ ΛͪΌΜͱಡΉʣ͜ͱൈ͖Ͱ͸Θ͔Βͳ͍ • Ͱ΋ཱྀ׳Ε͍ͯ͠ͳ͍΍͕ͭ஍ਤແ͠Ͱา͘ͷ͸ͭΒ͍ • ͳΜͱͳ͋͘ͷลʹࢁ΍઒ʢಛ௃తͳPEPʣ͕͋Δ •

    ͋ͷล͸ཱྀͷ೉౓ߴͦ͏͔ͩΒࠓ͸ආ͚Α͏ʢඃࢀর਺ଟ͍ͷ ʹԘ௮͚ʹͳͬͨPEPͱ͔ʣ • ͬ͘͟Γ͜͏͍͏஍Ҭʢαϒάϧʔϓʣ͕͋ΔΜͩͳ͊ • ʢ೔ʑߋ৽͞Ε͍ͯΔͷͰʣͨ·ʹ஍ܗͷେن໛มԽ͕ى͜Δ
  24. %BUB$PEF • PEP Map • https://github.com/komo-fr/pep_map_site • Network • https://komo-fr.github.io/pep_map_site/network.html

    • Clustering Result • https://komo-fr.github.io/pep_map_site/louvain.html • Jupyter Notebook • https://github.com/komo-fr/SciPyJapan_2019_talk