SlideShare une entreprise Scribd logo
1  sur  60
Télécharger pour lire hors ligne
オープンデータを
まぜまぜHackしよう
db analytics showcase Sapporo 2017
2017/6/30
株式会社 Preferred Networks エンジニア
三好 邦彦 (@colspan)
三好 邦彦
● 経歴
○ 十勝地方幕別町出身
○ 2002年4月~2008年3月札幌にて大学生時代を送る
○ 2008年4月~2017年3月 : 精密機器メーカー研究開発
○ 2016年4月~現在 : 釧路公立大学皆月研究室 学術研究員(遠隔)
○ 2017年4月~現在 : 株式会社 Preferred Networks エンジニア
● 受賞歴
○ 2015年 北海道オープンデータハッカソン クリプトンフューチャーメディア賞
○ 2016年 アーバンデータチャレンジ 2015 ファイナル アプリケーション部門 金賞
○ 2016年 Mashup Awards Civil Tech部門 ファイナリスト
● その他
○ とかち東京クラブ 代表
■ 関東在住十勝出身者のゆるいコミュニティ、関東で北海道と十勝を発信中
私は
● 元組み込み機器ミドルウェアエンジニア
● データエンジニア
● 可視化エンジニア
● Webアプリ開発エンジニア
Seseki
アーバンデータチャレンジ2015 アプリ部門金賞
http://colspan.github.io/seseki_viewer/
PFNに興味がある方は
是非お声がけください!
では本題に入ります
オープンデータが身近になった
しかし、すぐに数字の羅列が行く手を阻む
そこで、まぜまぜHackしよう
合成可視化
事例紹介
北海道観光客統計データ可視化 QuadKeyを活用したメッシュ分析
事例紹介
北海道観光客統計データ可視化 QuadKeyを活用したメッシュ分析
オープンデータとの全面戦争と
「まぜまぜ」の大切さに
気づくきっかけ
事例紹介
北海道観光客統計データ可視化 QuadKeyを活用したメッシュ分析
オープンデータとの全面戦争と
「まぜまぜ」の大切さに
気づくきっかけ
より細かい「まぜまぜ」
事例1 : 北海道観光客統計データ可視化
2015年当時の私が全力投球したプロダクト
http://bit.ly/hkdtourismstat
なぜオープンデータ解析の趣味を始めたか
● 地元に対する理論武装が必要になったため(とかち東京クラブの幹事)
●
タダで手に入るオープンデータを知り、解析に着手
泥臭いクレンジング作業の先にある宝の山を目撃し、やる気MAX
http://bit.ly/hkdtourismstat
作品を具現化する
ためにやったこと
http://bit.ly/hkdtourismstat
作業フロー
元データ
収集済
データ
解析可能
データ
抽出
クレンジング
公開
可視化
http://bit.ly/hkdtourismstat
作業フロー
元データ
収集済
データ
解析可能
データ
抽出
クレンジング
公開
可視化
http://bit.ly/hkdtourismstat
残念ながら、近道はありませんでした。
オープンデータとの全面戦争
http://bit.ly/hkdtourismstat
年によってファイル名がバラバラ
http://bit.ly/hkdtourismstat
Excelファイルのバージョンがバラバラ
http://bit.ly/hkdtourismstat
CC BY 北海道
http://bit.ly/hkdtourismstat
改行による改ページ
(しかもズレてる)
セル結合
6 メトリクス列挙
うち1行は集計行
キング・オブ・セル結合
CC BY 北海道
http://bit.ly/hkdtourismstat
大量のワークシート
振興局の集計行
誤植
ここだけ結合拒否
CC BY 北海道
http://bit.ly/hkdtourismstat
まさに神エクセル
http://bit.ly/hkdtourismstat
情報が公開されることはとても素晴らしいのですが …
神によって隠されたデータを掘り出す
http://bit.ly/extract_hokkaido_irikomi
何とか抽出できました
http://bit.ly/extract_hokkaido_irikomi
可視化の闇
● 地図データを調達
○ shp??
○ 北海道の市町村境界を GeoJSONにしたら50MBになった
○ TopoJSONで簡略化・圧縮が必須 (GUNMA GIS GEEKの清水さんに感謝)
● CSVファイルを読み込みたい
○ ファイルサイズ・ファイル差し替え汎用性を考えると非同期読み込み必須
○ promise必須
● 地図を可視化したい
○ 地図の座標変換方法でトライアンドエラーを繰り返す
○ 塗り分け方法も手探り
■ 配色
■ 凡例
■ イベントハンドラの登録
http://bit.ly/extract_hokkaido_irikomi
shp
GeoJSON
TopoJSON
D3.js
自前コード
3000行
gdal
topojson
xls / xlsx
xls2csv
クレンジング
コード
700行
生csv
可視化用csv
50MB
3MB
しかし、アプリができても
すぐに行き詰った
何を可視化しても札幌が一等賞
でも、しばらくデータを眺めて閃いた
割り算すれば良い!
北海道には牛が人よりも多い
市町村が51もある
順位 市町村名 飼育頭数の人口
比
1 士幌町 10.94
2 別海町 7.00
3 標茶町 6.79
4 上士幌町 6.70
5 鶴居村 5.56
鹿追町, 清水町, 新得町, 大樹町, 豊頃町, 佐呂間町, 天塩町, 標津町,
浜中町, 陸別町, 幌延町, 豊富町, 足寄町, 猿払村, 興部町, 湧別町,
浦幌町, 雄武町, 白糠町, 本別町, 美深町, 更別村, 西興部村, 浜頓別町, 中
札内村, 置戸町, 広尾町, 中標津町, 中頓別町, 弟子屈町, 滝上町,
津別町, 厚岸町, 遠別町, 中川町, 大空町, 芽室町, 枝幸町, 池田町,
下川町, 訓子府町, 小清水町, 新冠町, 初山別村, 愛別町, 紋別市
権利元 : 独立行政法人家畜改良センター
観光客数 ÷ 人口
観光の基本は温泉とスキー
固有な観光地を有さない市町は
ほぼ人口の10~20倍に収束
全国に汎用化
Seseki
他の都市を評価できるようにもなった
まぜまぜHack
合成可視化
まぜまぜHack
合成可視化
事例2 : QuadKeyを活用したメッシュ分析
市町村単位の可視化をやり尽くした末に、もっと細かい粒度でまぜまぜし始めた
オープンデータの特徴
● 地理情報が多い
● 統計情報が多い
○ 人口
○ 収穫量
○ 経済指標
● 集計単位がバラバラ
○ 点
○ 市町村単位
○ メッシュ単位
発想の転換
単位がバラバラだから、まぜまぜした前例が少ない
究極的には自分の地元に振れば絶対にオリジナル作品
多くの人にとって身近なネタに化けやすい
作業フロー
元データ
収集済
データ
合成
解析可能
データ
抽出
クレンジング
公開
可視化
New!
実装方針
● すべてのデータの集計単位を統一する
具体的には
● 市町村単位よりも細かくしたメッシュ単位
● メッシュの符号化のためにQuadKeyを活用する
QuadKeyとは
● 緯度経度を2×2で4分割し、Z走査で名前をつけたもの
● 各領域が0〜3の文字列で表現される
● 階層的になっているので、必要な精度で止められる
● 釧路公立大学
(東経144. 396度, 北緯43. 018度)の
ハッシュコードは
1312233010103310
出典:https://msdn.microsoft.com/ja-jp/library/bb259689.aspx
QuadKey To ○○ に落とし込む
● 「各市町村の人口」を求めるなら
○ QuadKey to 人口
○ QuadKey to 市町村
● 「各市町村の傾斜地に住んでいる人口」を求めるなら
○ QuadKey to 人口
○ QuadKey to 市町村
○ QuadKey to 傾斜
JOINで様々な組み合わせの集計ができる!
データの変換
● 国勢調査・国土数値情報の3次メッシュ統計値をQuadKeyにリサンプリング
○ CSV入手 (クリック面倒くさすぎwwww )
○ 3次メッシュを2次元のnumpy arrayに展開
○ scipy.ndimageでQuadKey空間にリサイズ
○ 符号化してSQLiteにレコードを格納
● 国土数値情報の行政区域データから市町村とQuadKeyの対応表を作成
○ 国土数値情報の行政区域データ (ベクトル)をQuadKey空間にラスタライズ
○ 市町村名とQuadKeyの対応を総当りで取得し、 SQLiteにレコードを格納
実例 : 人は傾斜のない場所に住む
傾斜度ごとの人口
select q.commune, sum("0-5"), sum("5-10"), sum("10-15"), sum("15-20"), sum("20-25"), sum("25-30"), sum("30-") from
(select * from mesh_population join (select inclination.qkey,
case when inclination.value between 0 and 5 then mesh_population.value else 0 end as "0-5",
case when inclination.value between 5 and 10 then mesh_population.value else 0 end as "5-10",
case when inclination.value between 10 and 15 then mesh_population.value else 0 end as "10-15",
case when inclination.value between 15 and 20 then mesh_population.value else 0 end as "15-20",
case when inclination.value between 20 and 25 then mesh_population.value else 0 end as "20-25",
case when inclination.value between 25 and 30 then mesh_population.value else 0 end as "25-30" ,
case when inclination.value > 30 then mesh_population.value else 0 end as "30-"
from mesh_population join inclination on inclination.qkey = mesh_population.qkey) as inclination
on inclination.qkey = mesh_population.qkey) as mp
inner join (select * from commune_qkey as cq inner join communes as c on c.commune_id = cq.commune_id) as q
on mp.qkey = q.qkey
group by q.commune
全道の94%の住民が傾斜0~5度に住む
さらなるデータを求めて
各空港の人口カバー率を知りたい!
処理概要
● OSMの道路データベースを探索
○ フリーの探索エンジン OSRMをローカルに立てる
○ 全道各地から全13空港へ総当り計算(ただし直線距離で探索枝切り )
○ 結果をSQLiteに保存
● 上記をLuigiのパイプラインとして記述し、並列計算
○ レベル10の粒度でタイル分割し、 1タイル1タスクに(1571タイル)
■ 1タイルあたり64×64ピクセルで距離計算
■ 総問い合わせ回数は 8365万
○ Luigiで並列計算と計算進捗管理
■ CPUのコアを使い切る!
■ OSRMがたまに落ちるから進捗管理必須 !
■ 4世代Core i5で2日間、居住区域に限定すると 2時間
● 可視化・集計
計算実演
計算結果のDBに対するクエリ
select airport_id, sum(value) from (select a.qkey,
p.value, a.hospital_id from airports as a join
mesh_population as p on p.qkey = a.qkey and
ranking = 0) group by airport_id
可視化・集計結果
http://bit.ly/hokkaido_airport_time_distance
空港名 人口 カバー率
新千歳空港 3,226,286 58.4%
旭川空港 697,726 12.6%
函館空港 489,704 8.9%
帯広空港 346,665 6.3%
女満別空港 247,998 4.5%
釧路空港 242,926 4.4%
中標津空港 96,728 1.7%
紋別空港 89,059 1.6%
稚内空港 80,445 1.5%
利尻空港 5,259 0.1%
礼文空港 3,158 0.1%
奥尻空港 2,722 0.0%
まぜまぜHack
合成可視化
機械学習を活用した分析を個人的に挑戦中
統計データのクラスタリング モノクロ地図の着色
pix2pixを国土地理院タイルで学習する
発想と具現化のループ
着想 具現化
新たな応用に気づく
FBやTwitterでシェアされ、
キーマンと知り合える
キーマンからいろいろ教えてもらえる
スキルが増える
データを整理する
データをまぜまぜする
可視化する
公開する
増えた知識やスキルで
手数が増える
具現化物を想像すると
モチベーションが高まる
機会を下さったすべての皆様に感謝
● オープンデータ整備に携わった皆様
● 本日お集まり頂いた皆様
オープンデータを
まぜまぜHackしよう
db analytics showcase Sapporo 2017
2017/6/30
株式会社 Preferred Networks エンジニア
三好 邦彦

Contenu connexe

En vedette

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

En vedette (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

db analytics showcase sapporo 2017 発表資料