-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzillow_1.Rmd
147 lines (107 loc) · 3.26 KB
/
zillow_1.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
---
title: "Zillow_1"
author: "Aishwarya Hariharan"
date: "9/28/2017"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(ggplot2)
library(tidyverse)
library(dplyr)
library(tidyr)
library(readr)
properties <- read_csv('properties_2016.csv')
transactions <- read_csv('train_2016_v2.csv')
```
```{r renaming}
# More descriptive names for properties data set
properties <- properties %>% rename(
id_parcel = parcelid,
build_year = yearbuilt,
area_basement = basementsqft,
area_patio = yardbuildingsqft17,
area_shed = yardbuildingsqft26,
area_pool = poolsizesum,
area_lot = lotsizesquarefeet,
area_garage = garagetotalsqft,
area_firstfloor_finished = finishedfloor1squarefeet,
area_total_calc = calculatedfinishedsquarefeet,
area_base = finishedsquarefeet6,
area_live_finished = finishedsquarefeet12,
area_liveperi_finished = finishedsquarefeet13,
area_total_finished = finishedsquarefeet15,
area_unknown = finishedsquarefeet50,
num_unit = unitcnt,
num_story = numberofstories,
num_room = roomcnt,
num_bathroom = bathroomcnt,
num_bedroom = bedroomcnt,
num_bathroom_calc = calculatedbathnbr,
num_bath = fullbathcnt,
num_75_bath = threequarterbathnbr,
num_fireplace = fireplacecnt,
num_pool = poolcnt,
num_garage = garagecarcnt,
region_county = regionidcounty,
region_city = regionidcity,
region_zip = regionidzip,
region_neighbor = regionidneighborhood,
tax_total = taxvaluedollarcnt,
tax_building = structuretaxvaluedollarcnt,
tax_land = landtaxvaluedollarcnt,
tax_property = taxamount,
tax_year = assessmentyear,
tax_delinquency = taxdelinquencyflag,
tax_delinquency_year = taxdelinquencyyear,
zoning_property = propertyzoningdesc,
zoning_landuse = propertylandusetypeid,
zoning_landuse_county = propertycountylandusecode,
flag_fireplace = fireplaceflag,
flag_tub = hashottuborspa,
quality = buildingqualitytypeid,
framing = buildingclasstypeid,
material = typeconstructiontypeid,
deck = decktypeid,
story = storytypeid,
heating = heatingorsystemtypeid,
aircon = airconditioningtypeid,
architectural_style= architecturalstyletypeid
)
transactions <- transactions %>% rename(
id_parcel = parcelid,
date = transactiondate
)
```
```{r combine both tables}
all_data <- transactions %>% left_join(properties,by = "id_parcel")
```
```{r divide into train and test}
n <- dim(all_data)[1]
# number of observations that go in the training st
n_tr <- floor(n * .8)
# randomly select n_tr numbers, without replacement, from 1...n
set.seed(42)
tr_indices <- sample(x=1:n, size=n_tr, replace=FALSE)
# break the data into a non-overlapping train and test set
train <- all_data[tr_indices, ]
test <- all_data[-tr_indices, ]
```
```{r}
missing_values <- all_data %>% summarize_each(funs(sum(is.na(.))/n()))
missing_values <- gather(missing_values, key="feature", value="missing_pct")
good_features <- filter(missing_values, missing_pct<0.75)
```
```{r}
#Num of properties with 0 bathrooms and 0 bedrooms
bath_0 <- all_data %>% filter(num_bathroom == 0 & num_bedroom == 0)
all_data <- all_data %>% mutate(b)
```
```{r}
head(all_data)
summary(all_data)
```
```{r}
ggplot(data = train_2016_v2_csv, aes(transactiondate, logerror)) +
geom_point()
```