京都の学生向けアパート家賃の推定とお得な物件探し 再帰分割線形モデルを用いて Part1

今回は身近な京都の家賃データを用いた分析事例を紹介します。

データ収集から分析のコードはすでにGitHub上がっているので詳しいスクリプトに興味のある方は下記のリンクを参照してください。

github.com

分析準備

パッケージ・データ読み込み

library(tidyverse)
library(corrplot)
library(treemap)
library(GGally)
library(rpart)
library(rpart.plot)
rent = read.csv("data/cleaned_rent.csv")

クリーニング

names(rent)[14] = "maintenance"
rent = mutate(rent, year = substr(date, 0,4))
rent$year = as.numeric(rent$year)
rent = filter(rent, price <= 10)
rent = filter(rent, year != 1900)

データの中身

  • title: 物件名
  • zip_code: 郵便番号
  • address: 住所
  • station_type: 最寄駅のタイプ
  • station: 最寄駅
  • area: 面積
  • contract: 契約年数
  • date: 建設年月
  • direction: 部屋の向き
  • floor: 建物の階数
  • points: 不動産の推しポイント
  • price: 家賃
  • admin: 共益費、管理費
  • maintenance: 維持費
  • methods: 最寄駅までの手段
  • dis: 最寄駅までの時間
  • deposit: 敷金
  • key: 礼金
  • renewal: 更新料
  • year: 建設年

EDA

最寄りの駅

京大生と同志社生向けのリスティングデータを取ってきたのでこんな感じになっています。

rent = rent %>% 
  separate(address, into = c("ward", "town"), sep = "区") %>% 
  separate(ward, into = c("city", "ward"), sep = "市")
rent %>% 
  ggplot(aes(station, fill = ward)) +
  geom_bar() +
  theme_gray(base_family = "HiraKakuPro-W3") +
  coord_flip()

f:id:kokiando:20190428212829p:plain

station_dat = rent %>% 
  select(ward, station) %>% 
  group_by(ward) %>%
  count(station)
station_dat$ward = paste0(station_dat$ward, "区")
treemap(station_dat, index=c("ward","station"), vSize="n", 
    type="index",                            # How you color the treemap. type help(treemap) for more info
    palette = "Set1",                        # Select your color palette from the RColorBrewer presets or make your own.
    title="My Treemap",                      # Customize your title
    fontsize.title=12 # Size of the title
)

f:id:kokiando:20190428212301p:plain

掲載物件の多くは左京区上京区で占められています。その中でもダントツで多いのが今出川駅周辺です。やはりあの辺りは同志社生が多く需要がめちゃくちゃあるっぽそう。

家賃の分布

rent %>% 
  ggplot(aes(price)) +
  geom_histogram(binwidth = .2)

f:id:kokiando:20190428213224p:plain

4万円弱と5万円あたりに多くが分布していますが、中には3万を下回るものや、8万の外れ値も見受けられる。

相関係数

num_dat = select(rent, area, floor, price, admin, maintenance, dis, deposit, key, renewal, year)
ggpairs(num_dat)

f:id:kokiando:20190428213644p:plain

みづらいけども、価格(price)の列に注目すると、結構特徴がみえてきそう。

num_dat %>% 
  gather(key = "type", value = "value", -price) %>% 
  ggplot(aes(price, value)) +
  geom_point() +
  facet_wrap(~type, scale = "free") +
  geom_smooth(method = "lm")

f:id:kokiando:20190428213848p:plain

部屋の広さ(area)とかはくっきりとした関係性があることが見えます。

次回はモデリングパートをアップします。