AirbnbのデータサイエンティストはなぜRが好きなのか?

今シリコンバレーで、もしくは世界中のスタートアップ業界で一番ホットな会社といえばAirbnbと言っても過言でないのでしょうか。日本では民泊のプラットフォームとして知られていますが、今や3兆円近い企業価値がついている超ユニコーン企業です。私も日本に行く時はホテルでなく、いつもAirbnbで普通のアパートを一週間ほど渋谷のあたりに借りますが、使いやすく、コストパフォーマンスもよく、出張をするときには欠かせないサービスです。

Airbnbnはシリコンバレーのスタートアップの中でも特にデータの使い方がうまい会社として有名で、いろいろとデータに関するツールをオープンソースとして公開もしています。そんなAirbnbのデータサイエンティストたちの間ではRというプログラミング言語が一番人気があるというのは以前から広く知られていることですが、今回、彼らがどう社内でRを使っているのか、どのようにプロダクトに関するインサイトを抽出し、A/Bテストなどの実験結果を評価し、予測モデルを作り、さらにどう社員のためのトレーニング、教育を行っているかなどに関してかなり詳しい情報を、こちらの方に公開していたので、以下に著者の許可を得た上で簡単に訳してみました。

訳の方は私がさらっと訳したものですので、ひょっとしたら間違いや抜けている箇所があるかもしれません。その場合は面倒ですがご指摘ください。

以下筆者による日本語訳


How R Helps Airbnb Make the Most of Its Data: Great overview of how R is used at Airbnb

Airbnbがデータを最大限活用するのにRがどう役立っているのか: AirbnbでのRの使われ方の詳細

オリジナルの記事

By Ricardo Bion (Ricardo.Bion@airbnb.com), Robert Chang (Robert.Chang@airbnb.com), Jason Goodman (Jason.Goodman@airbnb.com)

Introduction

Airbnb’s data science team relies on R every day to make sense of our data. While many of our teammates use Python, R is the most commonly used tool for data analysis at Airbnb. In a recent survey of our whole team, we found that 73% of our Data Scientists and Analysts rated themselves as closer to “Expert” than “Beginner” in using R, and 58% regularly use R as a language for data analysis. R comes into play at all stages of the analysis pipeline, from exploratory data analysis and predictive modeling, to sharing results with business partners. In this article, we highlight the role that R plays at Airbnb and share some practical insights for others who seek to use R to help their teams make the most of their data.

Airbnbのデータサイエンス・チームはデータを理解するために毎日Rを使っています。Pythonを使ってデータサイエンスしている人達も多いですが、AirBnBではRが一番良く使われているデータサイエンスのプログラミング言語です。最近の社内のデータサイエンス・チームに対してのアンケートでは、73%のデータサイエンティストとアナリストがRを使うことに関して自分たちをエキスパート(専門家)・レベルだと思っています。そして、58%の人たちがRを毎日のようにデータ分析に使います。

Rはデータ分析の一連のフローの中で全ての場面で使われます。例えば、探索的(Exploratory)データ分析、予測モデルの作成、ビジネス・パートナーと結果を共有するといった場面です。この記事の中ではRがどのように使われているか、さらに、これからRを使ってデータをもっと理解していきたいと考えている人たちへの実用的なアドバイスを共有したいと思います。

Data Science at Airbnb

Airbnb is a community marketplace that provides access to millions of unique accommodations in more than 65,000 cities and 191 countries. In addition to accommodations, with Experiences, Airbnb offers unprecedented access to local communities and interests, while Places lets people discover recommendations by the people that live there.

Airbnbは191カ国、65,000以上の町で泊まることのできる何百万もの泊まる場所を提供するコミュニティータイプのマーケットプレイスです。宿以外にもExcperienceというサービスは地域のコミュニティーや面白いことを体験することを可能にしますし、Placesというサービスはそれぞれの町に住むローカルのお気に入りを発見することを可能にします。

A huge part of our company’s success has been due to the data science team. The first member of our team was among the first 10 hires at Airbnb. Today, the team includes data scientists, data engineers, business analysts, machine learning engineers, and several product and infrastructure-focused data teams that touch almost every part of the Airbnb platform.

この会社の成功の大きな部分はデータサイエンスチームによるところが大きいです。データサイエンス・チームの最初のメンバーはこの会社の最初に雇われた社員10人のうちの一人です。現在はこのチームはデータサイエンティスト、データエンジニア、ビジネス・アナリスト、機械学習エンジニア、そしてプロダクトやIT基盤にフォーカスしたデータチームで、Airbnbのプラットフォームのほとんど全ての部分に関わっています。

To start, what do we mean by data science? Put simply, our team’s mandate is to use data to inform decisions.

それでは、データサイエンスとはそもそも何でしょうか?それは、要は、私達にとってはよりよい意思決定を支えるためにデータを使うということです。

Data scientists at Airbnb are responsible for many tasks to empower the company to be more data informed - we instrument logs, build data pipelines, define metrics, develop education resources, build internal data tools, and create reports and dashboards. However, we can categorize the core of our work into three main focus areas: Product Insights, Experimentation, and Predictive Modeling.

Airbnbのデータサイエンティスト達は会社がよりデータをもとに意思決定を行えるための多くのタスクに責任をもっています。私達は、ユーザーの行動履歴などのログデータを取る、データの加工のパイプラインを作る、指標を定義する、教育のためのコンテンツや環境を作る、社内で使うデータ関連のツールを作る、レポートやダッシュボードを作る、といった作業をしています。しかし、そうした私達の仕事を、大きく3つのフォーカスしたカテゴリーに分けることができます。それは、プロダクト・インサイト、実験、予測モデルとなります。

Product Insight (プロダクト・インサイト)

Product insight work is exploratory in nature and usually somewhat open-ended. When we talk about “product,” we are referring mainly to the Airbnb website and mobile app, which currently includes homes, places, and experiences. You do not quite know what you are going to find before you start, but the goal is to find opportunities to make the product better. Questions such as ‘which types of guests are staying on Airbnb in these regions?’, ‘Why aren’t some new hosts getting booked?’, ‘Which cities are supply constrained?’ are all examples of product insights work. The insights gleaned from this work often lead directly to new product ideas and hypotheses about user behavior. Once we have these new product ideas, we can validate them in experiments.

プロダクト・インサイトは、特に終わりが決まっているわけではなく、基本的には探索的(Exploratory)な分析の仕事になります。プロダクトとは主に、ホーム、宿泊先、場所、体験を含むAirbnbのウェブサイトとモバイル・アップになります。始める前に特に何か特定の見つけ出したいものが決まっているわけではなく、逆にゴールはプロダクトをより良くするための機会を見つけ出すことです。

例えば、どういったタイプのゲストがある地域に泊まっているのか、なぜ新しホストはブッキングできてないのか、どの町で宿の供給が足りてないのか、といった質問をしてそれに答えていくことが、プロダクト・インサイトに関する仕事です。そしてこうした分析から得られたインサイトが新しいプロダクトのアイデアになったり、ユーザーの行動に関する仮定となったりします。そして、こうした仮定を検証するのが次の実験の仕事になります。

Experimentation (実験)

Experimentation (also commonly referred as A/B testing) plays an important role in data- informed product development. The goal of experimentation is to validate or dispute hypotheses that the team has in order to make the user experience better. If the hypothe- ses are validated, a live change to the app/site will take place to all users. Almost all hypotheses and promising ideas at Airbnb are validated through controlled experiments where assignments are randomized.

実験、つまり一般にはA/Bテストとして知られているもののことですが、これがデータドリブンなプロダクト開発の重要な部分を占めます。実験の目的はチームがユーザーエクスペリエンスの改善に役立つと思っている仮定をデータを使って統計的に検証することです。もしそういった仮定が正しいと実証されたら、それに基づく変更がウェブサイトやモバイル・アップを通してすべてのユーザーに届けられることになります。ほとんど全ての仮定やアイデアはこうしてコントロールされた実験を通して検証されます。

Before releasing new product features to the world, we verify that our new designs or data products impact key metrics such as bookings, customer service tickets, review scores, host churn, and dozens of other secondary metrics.

そして、新機能がどうブッキング、カスタマーサポート・チケット、ユーザーのレビューのスコア、宿を貸すホストの離脱率といった何十ものKPIにどう影響するのかをチェックします。

Additionally, experimentation is a way to attribute the gains to the team that worked hard to design, test, and implement the new feature, and to ensure that a product change is not hurting bookings or other key metrics.

さらに、こうした実験というのは実はそうした機能をデザイン、テスト、そして実装したチームにその成果に貢献したということを周りの目からもはっきりと認識されるようにするためであり、そうした変更がブッキングなどのような重要な指標が悪くならないようにするというためでもあります。

Data scientists are involved in all aspects of the experimentation cycle. Before experiments, we perform power analyses to determine how long the experiments should be run. We draft the experimental design which includes details on how the experiment should be run and what metrics to track in order to measure success. Finally, we often perform additional “deep-dives” beyond basic t-tests to better determine the impact of the product feature in question.

データサイエンティストはこうした実験の全ての段階に関わっています。実験を始める前にはパワー分析を行って、どれくらいの間実験をしなくてはいけないのかということを決めます。そして、どのように実験が実行されるべきか、最終的に成功しているといえるためにはどの指標を見ている必要があるのかという仕様を最初に決めます。

Predictive Modeling (予測モデル)

One well-known application of Machine Learning at Airbnb is our Smart Pricing feature. If you would like some help in choosing how to price your listing, we provide you with a suggestion of a price that we think will work well for you.

AirBnBでは、よく知られた機械学習を使ったアプリケーションとしてスマート・プライシング(価格)という、ホスト(物件の提供者)が最適な値段をレコメンドする機能を提供しています。

The suggestions are generated based on a machine learning algorithm that takes into account a variety of points of information, including the date for which you are setting the price, listing’s location, amenities, your booking history, and many others.

これは、どの日に値段をつけようとしているのか、物件の場所はどこか、どういった施設なのか、過去のブッキングデータなど、様々な属性から最適な値段を導き出します。

Pursuing an end-to-end machine learning project can often be costly and time consuming. This means that validating the ideas before fully investing in engineering and implementation is a high leverage activity. One of the ways in which data scientists would validate whether a modeling based solution would work is to build a prototype. R turns out to be an extremely powerful tool for this purpose because we can easily perform data wrangling and feature engineering once training data is loaded into an R session.

機械学習のプロジェクトを最初から最後まで行うのはコストも時間もかかります。そしてこうした予測モデルを作る時に実験的にいろんなモデルを試す必要があるのですが、こうしたときにRはすごく便利です。なぜなら予測モデルの精度を上げるために、データの加工、属性の生成などを行う必要があるのですが、Rだとそれがものすごく簡単にできるからです。

For example, when our data scientists try to predict revenue at the listing and guest level, we built a wide variety of prototypes in R to validate that a model based prediction is worth pursuing (by comparing the RMSE of the challenger models with the incumbent model).

例えば、宿のリストとゲストのレベルに合わせて売上を予測するために、データサイエンティストはたくさんの予測モデルをプロトタイプとして作り、その中から最も使えるものをRMSE(二乗平均平方根)という指標を使って選びことで、そのプロトタイプが最も可能性がありそうだと判断していきます。

R at Airbnb

R, as a tool, does not exist in a vacuum. It is usually the last tool used in a long series of tools for capturing, processing, and analyzing data.

ツールとしてはRだけが存在するわけではありません。むしろ普通は、データを収集して、処理して、そして分析するという一連の長いプロセスの最後の方の段階で使われます。

The first step is logging. Whenever users interact with Airbnb, such as by making a search, contacting a host, or even calling customer support, both client-side and server- side event data is logged. Similarly, collections of stateful information such as listing characteristics or transaction details are recorded in MySQL databases (the most common open-source relational database management system). These two main sources of data, logs and stateful information, are ingested by our data warehouse on AWS (Amazon Web Services) and securely stored on HDFS (Hadoop Distributed File System) using S3 (Amazon Simple Storage System is an object storage system with a simple web service interface to store and retrieve any amount of data from anywhere on the web).

最初はログデータです。Airbnbでユーザーが行った行動、例えば検索したり、ホストに連絡したり、カスタマー・サポートに連絡したりといったイベントです。もう一つは物件の情報や、取引に関する詳細です。こちらはMySQLデータベースに保存されてます。こうしたデータは最終的にAWS上のデータウェアハウスに流し込み、S3と言うサービスを使ってHDFSに安全に保存されます。

Every night, a large number of ETL (Extract, Transform, and Load) jobs are kicked off in our open-source workflow manager Airflow (an open-source platform to programmatically author, schedule, and monitor data workflows), calculating useful metrics and aggregations from the raw logs for further analysis and predictive modeling. Output tables are organized in the star schema style so that any analyst can easily join fact tables with dimension tables to uncover insights.

そして、毎晩たくさんのETL(Extract, Transform, and Load) のタスク・ジョブが私達のオープンソースのワークフロー管理のツールであるAirflowを使って実行され、必要な指標の計算、生データからの集計などがその後で行われる詳細な分析、予測モデルの作成のために行われます。

Different data analysis tools are available for users of varying technical backgrounds. For visual analysis, users often leverage Tableau and our open-source data visualization tool Superset to understand the state of the business. Analysts who are comfortable with SQL use SQL Lab to interact with the data warehouse directly. Finally, data scientists use a wide variety of tools. Amongst the most important is the R language.

様々なデータ分析ツールがユーザーのスキルレベルによって用意されています。データの可視化にはTableau、そして私達のオープンソースのデータ可視化ツールであるSupersetといったツールがよく使われます。SQLに自信のある人たちはSQL Labを使ってデータウェアハウスに直接クエーリをかけてデータを取ってきます。データサイエンティストは様々なツールを使いますが、そのなかでも一番重要なのはRです。

R is essential for all three focus areas we mentioned above. For product insight work, packages such as dplyr (Wickham & Francois 2016) make it easy to slice-and-dice data extremely quickly. Combined with graphing package like ggplot2 (Wickham 2009), R allows data scientists to fly through a dataset in search of insights. For experimentation work, R’s pwr (Champely 2017) package make it easy to perform statistical tests, helping us to hold high standards of rigor in our experimentation. For machine learning, data scientists build proof-of-concepts predictive models as prototypes to prove that more sophisticated and intelligent product features are good investments before building them for production systems. Below, we go into more detail and provide some examples.

Rはすでに述べた3つのフォーカス領域のどれでも必須となるツールです。プロダクト・インサイトではdplyr等のパッケージを使ってデータを様々な角度からものすごい速さで集計して分析していきます。ggplot2のようなデータの可視化のパッケージと組み合わせることによって、Rはデータサイエンティストがデータの中を飛び抜けるかのように分析していくことを可能にします。

実験のフェーズでは、pwrというパッケージを使って統計のテストを行い、高いスタンダードを維持します。機械学習では、これから開発していく機能が投資に値するだけの正解を生み出すことができるのかを予測するためのプロトタイプとしての予測モデルを作ります。以下は一部の例です。

Product Insights

R enables product insight works at Airbnb in three main ways: Exploratory data analysis combining our internal packages with tidyr (Wickham 2017) and dplyr, data visualization with internal branded themes and packages such as ggplot2, and reproducible research with our internal Knowledge Repository and packages such as rmarkdown (Allaire et al. 2017).

Rは私達がプロダクト・インサイトに関する仕事をAirbnbで行うのに3つのエリアで可能にします。社内のパッケージに、tidyr、dplyrを組み合わせた探索的データ分析、社内のカスタムスタイルとggplot2などのパッケージを使ったデータの可視化、それから社内のKnowledge Repositoryとrmakrdownを使った再現可能なリサーチです。

Exploratory Data Analysis

Our data analysis workflow normally starts with data extraction. At Airbnb, we use Hive and Presto, two SQL-like languages, to extract data from HDFS to our local machines. Over the years, we have abstracted away the details of this operation so users can just type in a SQL query and get back the data in a R data.frame. Once data is in memory, we use magrittr pipes to chain operations together to perform data munging and analysis. The entire process of querying the database, manipulating data, graphing and predictive modeling building can happen in a few lines, allowing us to rapidly iterate through analyses and visualizations. We try to use a consistent style guide and set of packages for data exploration, relying mainly on tidyr, dplyr, broom (Robinson 2017), and purrr (Henry & Wickham 2017).

データ分析はまずデータの抽出から始まります。AirbnbではHiveやPresto経由でSQLを使ってHDFSからデータを取ってきます。私たちは、この作業に関する詳細を抽象化し、ユーザーが単純にSQLを使ってデータを簡単にRのデータフレームにインポートすることができるようにしました。データがメモリーに入ったら、magrittrのパイプを使ってデータの加工と分析に関わるオペレーションを一つのパイプラインとして実行していきます。データの抽出、加工、可視化、予測モデルの作成と言ったオペレーションはほんの数行でできますので、すばやく分析、可視化を繰り返しながら分析していくことができます。ここではdplyr、tidyr、broom、purrrなどのパッケージを使います。

Data Visualization

We use ggplot2 as our main package to create ad-hoc exploratory graphics as well as polishedlooking customized visualizations. When combined with tools to clean and transform data, ggplot2 allows analysts to quickly translate insights into high quality, compelling visualizations. In addition to the static graphics of ggplot2, we often make interactive visualizations or dashboards using R packages such as plotly (Sievert et al. 2017), leaflet (Cheng et al. 2017), dygraphs (Vanderkam et al. 2017), DiagrammeR (Sveidqvist et al. 2017), and shiny (Chang et al. 2017).

私たちはggplot2というRのパッケージを使ってアドホックで探索的な可視化を行い、公開に耐えるほどにカスタマイズされたグラフを作ります。前述したデータをきれいにして加工するためのパッケージと組み合わせることによって、分析者は素早くインサイトを質の高いグラフに変換することができます。静的なグラフをggplot2を使って作る以外にも、plotly、leaflet、dygraphs、DiagrammeR、shiny等のパッケージを使ってインタラクティブなグラフやダッシュボードを作ります。

Reproducible Research

At Airbnb, all R analyses are documented in rmarkdown, where code and visualizations are combined within a single written report. Posts are carefully reviewed by experts in the content area and techniques used, both in terms of methodologies and code style, before publishing and sharing with the business partners. The peer review process is often repeated until both the author and the reviewers are satisfied with the analysis. This careful code review process helps bring credibility to the team’s reports, reduces the number of bugs in analysis code, and often leads to more approachable insights and concrete recommendations.

Airbnbでは、全てのRを使った分析はコード、グラフとともにrmarkdownの形で一つのドキュメントして残されます。そうしたドキュメントは、ビジネスパートナーと共有される前に、手法やコードの書き方の点などからそれぞれの分析のエリアの専門家、または使われた技術の専門家によって注意深くレビューされます。

Once the report is ready, the code is merged and the final report is shared in an internal website called the Knowledge Repository (Sharma & Overgoor 2016). The Knowledge Repository is a Github-enabled internal web application powered by Python and Flask (a micro web framework for building websites) that has search, subscription, and tagging capabilities. Some of these reports eventually are featured in academic journals or external blog posts - see “How Airbnb uses Machine Learning to Detect Host Preferences” (Ifrach 2015) and “How well does NPS predict rebooking?” (Qian 2015) as examples. The Knowledge Repository attempts to incorporate best practices from software engineering (e.g., code review, reproducibility, version control), with best practices from academic research (e.g., peer review, clear hypothesis, review of the literature).

一度レポートの準備ができると、Rのコードはマージされ、レポートはKnowledge Repositoryと呼ばれる社内ウェブサイトにて共有されます。Knowledge RepositoryとはGithubをベースにしたPythonとFlaskで作られた社内ウェブアプリケーションで、検索、サブスクリプション、タグなどと言った機能がついてます。こうして共有された幾つかのレポートは最終的にアカデミック・ジャーナルや外部のブログに投稿されたりもします。こちらにそうした例があります。“How Airbnb uses Machine Learning to Detect Host Preferences” (Ifrach 2015) and “How well does NPS predict rebooking?” (Qian 2015) Knowledge Repositoryはソフトウェア開発とアカデミック・リサーチからのベストプラクティスを活かしています。

Housing analysis in this format offers many advantages. It makes it easy for anyone in the company, including non-technical business partners, to find analyses that might be relevant to their team. It allows data scientists to easily learn both context and new analytical techniques from previous work. It enables analysts to reuse code from past reports. It simplifies coordination across teams by keeping everyone in the loop on the latest research. None of this would be possible without the common usage of rmarkdown across the team.

こうして私達の分析をrmarkdownのフォーマットとしてKnowledge Repositoryに残すことにはたくさんの利点があります。まず、社内のテクニカルでない人も含めて誰もが、簡単に自分の興味のあることに関連したすでになされた分析を探すことができます。さらに、データサイエンティストが他の人達が行った分析から、新しい分析の手法などを学ぶことがでますし、以前使われたコードを使いまわすこともできます。そして、様々なチームが最新のリサーチにキャッチアップするためのプロセスを簡単にすることできます。こうしたことはrmarkdownという共通したフォーマットなしには成し遂げることができなかったでしょう。

Experimentation

In our team’s early days, we used R to perform experiment analyses manually. We would combine experiment assignment logs with data on bookings and other important metrics before performing statistical tests to evaluate our experiments. Eventually, we built a Shiny app that did these analyses for us at scale. It reported the results of dozens of experiments to data scientists, product managers and engineers. Over time, we began running hundreds of experiments simultaneously and Shiny could no longer scale to meet our needs. We needed a fully customized solution that could be supported by our core engineering team, and easily integrated into our data infrastructure, which runs mainly in Ruby and Python. The solution was to build a production pipeline and website to analyze experiments called Experiment Reporting Framework (Moss 2014) to display experiment status. This is a great example of how we use R to prototype and demonstrate the value of having a data tool, helping us understand the needs of those who might use it, which then prompted us to build out more scalable solutions.

最初の頃はRを使って実証的な分析をマニュアルでやっていました。私達の行っている実験を統計テストをして評価する前に、実験にアサインされているユーザーのログとブッキングデータ、他の重要な指標を一緒にします。そして、Shinyベースのアプリケーションを作ってこうした分析をたくさんの人ができるようにしてました。しかし時間が経つに連れて、何百もの実験テストを同時に行うようになるとShinyでは私達のニーズをスケールという観点で満たすことができなくなりました。ということで、こういったチャレンジを克服するために、RubyやPythonで作られているデータ・インフラストラクチャにインテグレートしやすく、さらに私達のエンジニアリングチームがサポートしやすいシステムを作る必要がありました。そうして、Experiment Reporting Frameworkと呼ばれるデータパイプラインと実験テストのステータスをモニターし分析するためのウェブサイトを作り上げました。これはRを使うことによって、素早くプロトタイプを作り上げることで、そうしたシステムを使うことになるであろうユーザーの要件を理解し、その価値を外のチームにデモンストレートし、そうしてもっとスケールするシステムをしっかりと作り上げていくことができるといういい例だと思います。

While today, much of our experimentation work is automated, R still plays a crucial role in more complex experiment analyses and deep dives. These analyses might, for instance, involve handling particularly complicated experimental setups that are not supported by our automated tools, target metrics that must be computed separately, or statistical analyses more sophisticated than t-tests (for more reference on experimentation at Airbnb, see Overgoor (2014)). Additionally, we use R to verify that experimental assignment is occurring properly. As with the move from our Shiny app to the production experiment tool, we try to automate our work whenever possible. If we find ourselves repeating the same ad-hoc experimental analyses in R, we try to build that functionality into our tooling. For example, we used to compute metrics that depended on the time since assignment to an experiment by hand. After a few times repeating these analyses, we wrote an R function to perform the computation. Finally, this capability was incorporated into our main experimental interface

今日では、ほとんどの実験テストは自動化されているとはいえ、Rはもっと複雑な実証的な分析や深い分析が必要なときなどに重要な役割を果たします。そういった分析は、特別に複雑は実験のセットアップや、別に計算する必要のある指標や、T検定よりもっと高度な統計分析といったものを含みます。他にも、Rを使って実験の割当てがちゃんと行われているかチェックしています。さらに、私たちは可能な限り作業を自動化することに余念がありません。もし自分たちが同じようなアドホックの実証的な分析を繰り返し行っていた場合はそれはツールのレイヤーに落とし込むようにしています。

例えば、実験にアサインされてからの時間を基に手動で計算していた指標がありましたが、何度か同じようなことを繰り返した後で、Rの関数を作ることで自動化しました。最終的にはこうした機能はメインの実験システムの方に統合されています。

Predictive Modeling

While R is an extremely effective tool for data cleaning and data munging, it is an even more powerful language for data modeling. Its power lies in the wide range of optimization, machine learning, and econometric techniques that the R community has built over the years. At Airbnb, many of our data scientists build models using these packages. Below, we describe three of our teammates’ projects that used R’s data predictive modeling capabilities.

もちろんRはデータをきれいにしたり加工したりすることに関してものすごく効果的で使いやすいツールでありますが、それ以上に予測のモデルを作ることに関してはとてもパワフルです。それは、Rのコミュニティーが作り上げてきた最適化、機械学習、経済指標のテクニックにその力を見ることができます。Airbnbではたくさんのデータサイエンティスト達がこうしたパッケージを使ってモデルを作っていきます。以下に3つほど私達のチームがどうやって予測モデルを作っているかの例を共有します。

Airbnb Guest Service Fee Optimization using NLopt package

When a reservation is confirmed, Airbnb charge guests a service fee between 5% and 15% of the reservation subtotal. These fees are calculated using a variety of factors, such as length of the reservation, and characteristics of the listing. One of the projects of the data science team is to optimize these fees, while keeping pricing policies that are fair to our guests and hosts. For example, Airbnb tends to charge lower guest service fee percentages to higher reservation subtotals, but we do not have surge service fees for high-demand dates such as New Years or holidays. In the past, we experimented with different service fee structures, which allowed us to learn the demand elasticity of guest bookings to service fees. Given this elasticity, we could then find the fee curve that maximized revenue on the platform. This exercise was entirely modeled as a nonlinear optimization problem using NLopt (Johnson 2017). The result of the model provided guidance on how we should set the guest fees. We ran a follow-up experiment to validate this new payout structure.

予約が完了すると、Airbnbはゲストにサービス料を予約料金の5%から15%の間でチャージします。このサービス料は、予約の期間の長さやリストのタイプなど様々な要素によって決まります。私達のデータサイエンティスト達がこの料金をゲストとホストによって公平になるようにしながらどう最適化すればいいかを調べるというプロジェクトを行いました。例えば、予約料金が大きいときにはサービス料のレートは低めに設定したりということです。ちなみに私たちは、需要の多いニューイヤー(新年)やクリスマスの時期に高くするといった、サーチャージと言うことはしません。過去にはいくつかのサービス料の体系を用意して、サービス料がブッキングの需要にどう関係してくるのかということを学びました。この関係性がわかると、われわれのプラットフォームの上での売上を最大限にするためのサービス料のカーブを描くことができます。この実験には、非線形の最適化の問題としてNLoptというRパッケージを使っています。この結果から私たちはどうやってサービス料を設定すればいいかというガイダンスを作ることができました。

Building A Marginal Returns Model in R

Where should we invest to attract new hosts to Airbnb? How much should we spend on these efforts? To better answer these questions, our data scientists built a Cobb Douglas like econometric matching model to estimate bookings by market as a function of supply and demand in that market.

どのようにして、Airbnbに宿をリストしてくれる新しいホストを増やすための投資をすればいいでしょうか。そして、いくらくらい投資すればいいでしょうか。こうした質問に応えるために私達のデータサイエンティストはCobb Douglasのような経済指標のモデルを作り、それぞれのマーケットにおける需要、供給から予約の数を導き出します。

Here, B represents nights booked in a particular, D and S represent demand and supply respectively. Furthermore, A stands for matching efficiency (i.e. how well the marketplace is matching supply and demand), the exponents alpha and gamma can be interpreted as the booking elasticity of supply and demand - for a one percent increase in demand/supply, alpha and gamma represent the percent increase in bookings.

Using historical supply (nights available to book) and demand (number of searchers), we were able to estimate the elasticities in R by taking the log of the equation on both side. With the fitted model and future forecasts for supply and demand, we are able to predict the marginal returns in bookings of adding an additional supply to the market (by taking the derivative of B with respect to S). Finally, the marginal returns of supply can help us to determine which market has the highest marginal returns, and we can prioritize our acquisition efforts accordingly.

過去の供給(予約することのできる泊の数)と需要(予約しようとしている人たちの数)のデータを使うことによって、両方からログを取り、Rの中で伸縮性の推測値を計算することができます。そして、この予測モデルと、将来の供給と需要のフォーキャストをもとに、ある特定のマーケットに宿を追加することによってどれだけの予約が成立する数としてのリターンがあるかを予測する事ができるわけです。こうして私たちはどのマーケットが一番リターンが大きくなるかを把握でき、それをもとに、どのマーケットから追加の宿の供給を増やしていくか効率的に決めていくことができるのです。

Causal Tree

Often, when experiments are run, data scientists often are asked questions such as which subset of users is most affected by the new feature. Many times, data scientists need to manually go through the different cohort cuts in order to identify the group that has the highest lift. More recently, we started experimenting with Susan Athey’s CausalTree (Athey & Im- bens 2015) method, which applies Machine Learning technique to Causal Inference problems. The premise of this package is that the algorithm will recursively partition the experiment data based on splits that give us the highest lift between control and treatment.

新しい機能の実験をする時、どのタイプのユーザーがもっとも影響を受けるかというのはデータサイエンティストがよく受ける質問です。これはよく手作業でデータと格闘しながら探していく作業になるのですが、最近はCausalTreeという機械学習を因果推論に適用する手法を試しています。このアルゴリズムは、コントロールグループとトリートメントグループの差が最も大きくなるように反復的に実験データをパーティションに区切ってくれるというものです。

The algorithm, along with many other new techniques, is often first implemented in R. We were able to leverage the open-sourced version of this algorithm and immediately integrate it with our offline analysis. This is a case where we did not build the model ourselves, but we are able to leverage on the work of other statisticians and academics to carry out novel analyses.

こうしたアルゴリズムや新しいやり方はまず最初にRで実装されることが多いので、私たちはオープンソース版のこのアルゴリズムを使ってすぐに私達の分析を行うことができました。これは、自分たちでそうしたアルゴリズムを一から作る必要なしに、他の統計学者やアカデミアの人たちの仕事を利用することで、素晴らしい分析を行っていくことができるといういい例です。

How We Support R Usage

Community (コミュニティー)

We help our team members develop as R programmers in a variety of ways. The most structured way is through teaching classes on R. Every new data scientist at Airbnb on- boards with a week of classes in a Data Bootcamp. The R Bootcamp classes are taught by experienced Airbnb data scientists who use R as their tool of choice. In the class, they help new team members set up their development environments and walk them through a series of hands-on tutorials demonstrating commonly-used R package with real Airbnb data.

他の企業と一緒で、AirBnBも社員にどうやってデータサイエンスを教育するかという様々な取り組みが行われていますが、最も体系立ててやっているのはRを教えるクラスです。新しく採用されたデータサイエンティストは一週間のデータブートキャンプのクラスに参加します。

Once on the job, team members mostly improve their skills by learning from one another. As detailed above, analyses are peer-reviewed by fellow data scientists before they are shared with external business partners. The process allows team members to give feedback not only on content and analysis but on the R coding itself. One of the best ways to improve is to read others’ code in the Knowledge Repository to see how they solved problems that resemble your own. Another way we learn from one another is through our R Slack channel (an enterprise instant message communication platform), where team members can ask one another for help or advice on using R.

現場に配属されるとスキルアップのために他の人達からどんどんと学んでいくことを期待されます。すでに述べたように、ピアレビューを通して他のデータサイエンティストたちから分析、リサーチに対するフィードバックが与えられます。さらにスキルアップしていくのに最も効果的なのは、 Knowledge Repository に共有されている他の人達のコードを見て、どうやって似たような問題を解決していったかを学ぶということでしょう。あとは、SlackにRのためのチャンネルがあるのでそこで自由に質問したりアドバイスを受けたりすることができます。

Internally, we actively run learning lunches, learning groups, and tutorials to showcase new packages and development in R. We allocate education funds and actively encourage our data scientists to learn from the best in the industry by attending R training courses such as DataCamp (a popular website for learning data science in the browser) and con- ferences such as UseR!.

社内では、勉強会ランチ、勉強グループ、チュートリアルなどの機会を使って、積極的にRに関する新しいパッケージや現在開発しているものに関する情報を共有します。さらに、教育のための予算を確保しているので、データサイエンティストはDataCamp(オンラインでデータサイエンスを学ぶことができるウェブサイト)のような外部のトレーニングコースやUseR!などのカンファレンスなどにどんどん参加することができます。

We recently also developed three R classes for our internal Data University, which is open to all Airbnb employees. These classes cover introduction to analyses in R, data visualization, and how to use and contribute to our internal R packages. They are taught in person by expert developers, and include custom-made online resources.

私たちは最近Rに関連したクラスを社内のデータ・ユニバーシティのために3つほど開発しました。これらのクラスは、Rを使った分析の始め方、データの可視化、社内のRパッケージの使い方と貢献の仕方です。

Externally, we also engage with the broader R community outside Airbnb. We par- ticipate in and sponsor rOpenSci, contribute to open source projects such as ggtech (Bion 2016a) and RPresto (Filiz & Goder 2017), and give talks at conferences such as the Shiny Developer Conference and UseR! We have been fortunate to have influential R developers visit our headquarters in San Francisco such as Hadley Wickham and Ramnath Vaidyanathan.

外部では、Airbnbの外のRコミュニティーと関わっています。最近ではrOpenSciをスポンサーしましたし、ggtech、RPrestoといったオープンソースのパッケージにも貢献していますし、Shiny Developer ConferenceやUseR!といったカンファレンスでも発表しています。さらにHadley Wickham、Ramnath Vaidyanathanといった有名なR開発者をゲスト・スピーカーとして招聘したりもしています。

Tooling (ツール)

In order to aid R analyses across the team, we developed an internal R package, Rbnb (Bion 2016b), full of useful functions and templates for data analysis specifically at Airbnb. The package is hosted on our internal Github instance, so that anyone on the team can see its contents and contribute. Updates are constantly being pushed out using the devtools (Wickham & Chang 2017) package. Rbnb’s primary purposes are twofold. First, it allows easy access to our infrastructure from R as we mentioned before. Without Rbnb, this process would be extremely time- consuming and inefficient. Second, it provides an Airbnb-styled theme to ggplot2, ensuring that our plots have a consistent look and feel across the team.

あらゆるチームでRを使いやすくするために、私たちはRbnbというデータ分析のために役立つ関数とテンプレートがつまったパッケージを開発しました。このパッケージは社内のGithubにホストされていてだれでもソースを見たり、貢献したりすることができます。

While these two aspects are by far the most commonly used features of the package, it contains over 90 functions contributed by more than 20 different members of the team. These functions perform a wide variety of operations, from statistical procedures like imputing data to producing customizable graphics. The concept is that anytime anyone on the team solves a problem that they think others might encounter, they can generalize their code, include it into Rbnb and now the whole team can access it.

20名以上の人たちから貢献された90以上の関数があります。データの統計的な推測からグラフのカスタマイゼーションまで様々な機能があります。コンセプトとしては、チームの誰でも何か問題を解決した時にそれが他の人にとっても役立つと思えばそれを一般的な関数としてRbnbに登録し、他の誰もが使えるようにするということです。

We recently launched a series of classes to teach any data scientist that is interested in how to develop for R packages. More than half of the team that uses R has participated, and Rbnb contributions are on the rise. We are also establishing a mailing list to distribute news of new contributions to the package to the team and give credit to those who create code that the whole team can use.

最近、データサイエンティストの誰もがRパッケージを作ることができるようにするためのクラスも開始しました。チームの中でRを使う半分以上の人達がすでに参加し、Rbnbパッケージにさっそく貢献し始めています。メーリングリストを使って新しい機能や貢献に関するニュースを発信し、貢献した人たちが評価されるようにも努めています。

For its first few years, Rbnb had relatively few contributors. The team was small, and thus the returns to writing generalizable code were low. Now that the team has grown much larger, scaling our work is more valuable. However, in reality, no team or person is solely responsible for the package’s maintenance, as it is a collective effort. Therefore, building the right incentives and rewards for others to continue contributing is a crucial and challenging task.

最初の数年はRbnbは比較的少ない貢献者しかいませんでした。チームは小さかったため、一般的に使える関数を開発することに対するリターンが少なかったためです。今ではチームはかなり大きくなったため、こうした仕事には大きな意味があります。ただ、一人の人がこうしたパッケージの開発に責任を持つというわけではなく、チームみんなでの努力の成果ということになりますので、さらなる貢献を促すためにどのように正しいインセンティブと報奨を与えるかというのが重要なチャレンジとなります。

Recently, we have begun exploring new ways to incentivize contributions, for instance, emphasizing the role of contributing beyond one’s product team in performance reviews and by developing special stickers that team members can display on their laptops for taking classes on how to contribute to Rbnb, and for actually contributing code. Ideally, team members can strike a middle-ground, where they spend a small amount of time learning how to contribute to the package, and then integrate contributing code the whole team can use as part of their normal workflow if they happen to solve a problem that can be easily generalized.

最近ではもっとこうした貢献にインセンティブを与えるようないくつかの仕組みを試しています。例えば社員のパフォーマンス評価にこうした貢献が与えるウェイトを大きくしたり、こうしたクラスに参加した人やRbnbに貢献した人たちに与えることのできる、ラップトップに貼るステッカーを作ったりしています。

For a more extensive discussion on tool building and education at Airbnb, see our external post on this topic: Using R packages and Education to Scale Data Science at Airbnb.

私達のAirbnbでのツール開発や教育に関するもっと詳しいディスカッションにかんしては”Using R packages and Education to Scale Data Science at Airbnb”という別のブログポストを参照して下さい。

Advice For Practitioners (修行者へのアドバイス)

We have come a long way as a team, and we have learned a lot from this journey. Here are a few recommendations to practitioners who are interested in using R to help their team make the most of its data: First, we recommend building helper functions to connect R to infrastructure containing data, such as production databases, as early as possible. In the early days, R is great for prototyping new data tools when building production- level data tools is costly or required evidence of usage. Once you have a sufficiently large team, create an internal R package to share code between analysts and encourage a culture of contribution and tool-building can enable the whole team for higher productivity. In that internal package, it’s useful to develop a standardized set of visualization themes to reinforce the brand of the data team. We suggest using Github, rmarkdown, and our newly open-sourced Knowledge Repository for peer-reviewing analysis and for making research reproducible. Consider investing in ongoing education and training for team members. Finally, remember that R is not the only language for data work, and that there is a great benefit in fostering a diverse team.

私たちはチームとして長い道のりを歩んできましたが、その途中でたくさんのことを学びました。ここに、これからRを使ってデータ分析をしていく、または学んでいくという方たちのためにいくつかの推薦できる方法をまとめてみました。 まず最初に、プロダクション・データベースのような基盤となるデータにRでアクセスできるようにする関数をなるべく早い時期に作ることをおすすめします。最初の時期は、Rは新しいデータツールのプロトタイプに適しています。その後十分に大きなチームになったら内部で使うRパッケージを作って、分析者同士がコードを共有できるようにするべきで、貢献を促すような文化を作り、さらにツールを作ることで全チームの生産性が上げていくべきです。内部で作るパッケージに関しては、社内の標準のチャートなどのためのスタイルを作ることが役立ちますし、データチームのブランドを再確認するのにも役立ちます。

ピア・レビューや分析をあとで再現することができるようにするためにも、Github、rmarkdown、そして私達がオープンソースとして公開したKnowledge Repositoryを使うことをおすすめします。チームのメンバーのための継続的な教育やトレーニングに投資することもおすすめします。最後に、データ関連の仕事をするにあたって、Rだけが唯一の言語ではありません。多様性のあるチームを育てることが長期的には大きな成果を生み出すことになります。

R is an essential part of the data scientist’s toolset at Airbnb. We are proud to support the language, and we would encourage any company that wants to make the most of its data to consider adopting R as its language of choice.

Rはデータサイエンティストのツールセットの中で欠かせない重要なものです。私たちは、この言語をサポートできることを誇りに思います。他のどんな企業も、データを使ってできるだけたくさんの成果を上げたいのであれば、Rをデータサイエンスの言語として採用することをおすすめします。


筆者による訳終わり。

以上です。ぜひ参考にしていただければと思います。もしすでにこういった取り組みを会社や組織のほうで始められている方は、ぜひ教えていただければと思います。

他にも何か質問があればこちら(kan@exploratory.io)までお気軽に連絡ください。


データサイエンスを本格的に学びたい方へ

手前味噌になりますが、この10月の終わりに、RのUIとして知られているExploratoryを作っている弊社がシリコンバレーで行っているトレーニングプログラムを日本向けにした、データサイエンス・ブートキャンプが東京で行われます。このシリーズでは最後の開催となりますので、データサイエンスの手法を基礎から体系的に、プログラミングなしで学んでみたい方、そういった手法を日々のビジネスに活かしてみたい方はぜひこの機会に、参加を検討してみてください。こちらに詳しい情報があります。