wscode commited on
Commit
69dd106
1 Parent(s): a754b67

add initial version of airbnb dataset

Browse files
Files changed (2) hide show
  1. README.md +154 -0
  2. airbnb.py +174 -0
README.md CHANGED
@@ -1,3 +1,157 @@
1
  ---
2
  license: cc-by-4.0
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: cc-by-4.0
3
  ---
4
+ dataset_info:
5
+ - config_name: weekdays
6
+ features:
7
+ - name: _id
8
+ dtype: string
9
+ - name: city
10
+ dtype: string
11
+ - name: realSum
12
+ dtype: float64
13
+ - name: room_type
14
+ dtype: string
15
+ - name: room_shared
16
+ dtype: bool
17
+ - name: room_private
18
+ dtype: bool
19
+ - name: person_capacity
20
+ dtype: float64
21
+ - name: host_is_superhost
22
+ dtype: bool
23
+ - name: multi
24
+ dtype: int64
25
+ - name: biz
26
+ dtype: int64
27
+ - name: cleanliness_rating
28
+ dtype: float64
29
+ - name: guest_satisfaction_overall
30
+ dtype: float64
31
+ - name: bedrooms
32
+ dtype: int64
33
+ - name: dist
34
+ dtype: float64
35
+ - name: metro_dist
36
+ dtype: float64
37
+ - name: attr_index
38
+ dtype: float64
39
+ - name: attr_index_norm
40
+ dtype: float64
41
+ - name: rest_index
42
+ dtype: float64
43
+ - name: rest_index_norm
44
+ dtype: float64
45
+ - name: lng
46
+ dtype: float64
47
+ - name: lat
48
+ dtype: float64
49
+ splits:
50
+ - name: train
51
+ num_bytes: 3998764
52
+ num_examples: 25500
53
+ download_size: 5303928
54
+ dataset_size: 3998764
55
+ - config_name: weekends
56
+ features:
57
+ - name: _id
58
+ dtype: string
59
+ - name: city
60
+ dtype: string
61
+ - name: realSum
62
+ dtype: float64
63
+ - name: room_type
64
+ dtype: string
65
+ - name: room_shared
66
+ dtype: bool
67
+ - name: room_private
68
+ dtype: bool
69
+ - name: person_capacity
70
+ dtype: float64
71
+ - name: host_is_superhost
72
+ dtype: bool
73
+ - name: multi
74
+ dtype: int64
75
+ - name: biz
76
+ dtype: int64
77
+ - name: cleanliness_rating
78
+ dtype: float64
79
+ - name: guest_satisfaction_overall
80
+ dtype: float64
81
+ - name: bedrooms
82
+ dtype: int64
83
+ - name: dist
84
+ dtype: float64
85
+ - name: metro_dist
86
+ dtype: float64
87
+ - name: attr_index
88
+ dtype: float64
89
+ - name: attr_index_norm
90
+ dtype: float64
91
+ - name: rest_index
92
+ dtype: float64
93
+ - name: rest_index_norm
94
+ dtype: float64
95
+ - name: lng
96
+ dtype: float64
97
+ - name: lat
98
+ dtype: float64
99
+ splits:
100
+ - name: train
101
+ num_bytes: 4108612
102
+ num_examples: 26207
103
+ download_size: 5451150
104
+ dataset_size: 4108612
105
+ - config_name: all
106
+ features:
107
+ - name: _id
108
+ dtype: string
109
+ - name: city
110
+ dtype: string
111
+ - name: realSum
112
+ dtype: float64
113
+ - name: room_type
114
+ dtype: string
115
+ - name: room_shared
116
+ dtype: bool
117
+ - name: room_private
118
+ dtype: bool
119
+ - name: person_capacity
120
+ dtype: float64
121
+ - name: host_is_superhost
122
+ dtype: bool
123
+ - name: multi
124
+ dtype: int64
125
+ - name: biz
126
+ dtype: int64
127
+ - name: cleanliness_rating
128
+ dtype: float64
129
+ - name: guest_satisfaction_overall
130
+ dtype: float64
131
+ - name: bedrooms
132
+ dtype: int64
133
+ - name: dist
134
+ dtype: float64
135
+ - name: metro_dist
136
+ dtype: float64
137
+ - name: attr_index
138
+ dtype: float64
139
+ - name: attr_index_norm
140
+ dtype: float64
141
+ - name: rest_index
142
+ dtype: float64
143
+ - name: rest_index_norm
144
+ dtype: float64
145
+ - name: lng
146
+ dtype: float64
147
+ - name: lat
148
+ dtype: float64
149
+ - name: day_type
150
+ dtype: string
151
+ splits:
152
+ - name: train
153
+ num_bytes: 8738970
154
+ num_examples: 51707
155
+ download_size: 10755078
156
+ dataset_size: 8738970
157
+ ---
airbnb.py ADDED
@@ -0,0 +1,174 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datasets
2
+ from enum import Enum
3
+ from dataclasses import dataclass
4
+ from typing import List
5
+ import pandas as pd
6
+
7
+ logger = datasets.logging.get_logger(__name__)
8
+
9
+
10
+ _CITATION = """\
11
+ @dataset{gyodi_kristof_2021_4446043,
12
+ author = {Gyódi, Kristóf and
13
+ Nawaro, Łukasz},
14
+ title = {{Determinants of Airbnb prices in European cities:
15
+ A spatial econometrics approach (Supplementary
16
+ Material)}},
17
+ month = jan,
18
+ year = 2021,
19
+ note = {{This research was supported by National Science
20
+ Centre, Poland: Project number 2017/27/N/HS4/00951}},
21
+ publisher = {Zenodo},
22
+ doi = {10.5281/zenodo.4446043},
23
+ url = {https://doi.org/10.5281/zenodo.4446043}
24
+ }"""
25
+
26
+ _DESCRIPTION = """
27
+ """
28
+
29
+ _CITIES = [
30
+ "Amsterdam",
31
+ "Athens",
32
+ "Barcelona",
33
+ "Berlin",
34
+ "Budapest",
35
+ "Lisbon",
36
+ "London",
37
+ "Paris",
38
+ "Rome",
39
+ "Vienna"
40
+ ]
41
+
42
+ _BASE_URL = "https://zenodo.org/record/4446043/files/"
43
+ _URL_TEMPLATE = _BASE_URL + "{city}_{day_type}.csv"
44
+
45
+ class DayType(str, Enum):
46
+ WEEKDAYS = "weekdays"
47
+ WEEKENDS = "weekends"
48
+
49
+
50
+ @dataclass
51
+ class AirbnbFile:
52
+ """A file from the Airbnb dataset."""
53
+
54
+ city: str
55
+ day_type: DayType
56
+ @property
57
+ def url(self) -> str:
58
+ return _URL_TEMPLATE.format(city=self.city.lower(), day_type=self.day_type.value)
59
+
60
+
61
+
62
+ class AirbnbConfig(datasets.BuilderConfig):
63
+ """BuilderConfig for Airbnb."""
64
+
65
+ def __init__(self, files: List[AirbnbFile], **kwargs):
66
+ """BuilderConfig for Airbnb.
67
+ Args:
68
+ **kwargs: keyword arguments forwarded to super.
69
+ """
70
+ super(AirbnbConfig, self).__init__(**kwargs)
71
+ self.files = files
72
+
73
+ _WEEKDAY_FILES = [AirbnbFile(city=city, day_type=DayType.WEEKDAYS) for city in _CITIES]
74
+ _WEEKEND_FILES = [AirbnbFile(city=city, day_type=DayType.WEEKENDS) for city in _CITIES]
75
+
76
+ class Airbnb(datasets.GeneratorBasedBuilder):
77
+ """"""
78
+
79
+ BUILDER_CONFIGS = [
80
+ AirbnbConfig(
81
+ name=DayType.WEEKDAYS.value,
82
+ files=_WEEKDAY_FILES,
83
+ ),
84
+ AirbnbConfig(
85
+ name=DayType.WEEKENDS.value,
86
+ files=_WEEKEND_FILES,
87
+ ),
88
+ AirbnbConfig(
89
+ name="all",
90
+ files=_WEEKDAY_FILES + _WEEKEND_FILES,
91
+ ),
92
+ ]
93
+
94
+ def _info(self):
95
+ features = datasets.Features(
96
+ {
97
+ "_id": datasets.Value("string"),
98
+ "city": datasets.Value("string"),
99
+ "realSum": datasets.Value(dtype="float64"),
100
+ "room_type": datasets.Value(dtype="string"),
101
+ "room_shared": datasets.Value(dtype="bool"),
102
+ "room_private": datasets.Value(dtype="bool"),
103
+ "person_capacity": datasets.Value(dtype="float64"),
104
+ "host_is_superhost": datasets.Value(dtype="bool"),
105
+ "multi": datasets.Value(dtype="int64"),
106
+ "biz": datasets.Value(dtype="int64"),
107
+ "cleanliness_rating": datasets.Value(dtype="float64"),
108
+ "guest_satisfaction_overall": datasets.Value(dtype="float64"),
109
+ "bedrooms": datasets.Value(dtype="int64"),
110
+ "dist": datasets.Value(dtype="float64"),
111
+ "metro_dist": datasets.Value(dtype="float64"),
112
+ "attr_index": datasets.Value(dtype="float64"),
113
+ "attr_index_norm": datasets.Value(dtype="float64"),
114
+ "rest_index": datasets.Value(dtype="float64"),
115
+ "rest_index_norm": datasets.Value(dtype="float64"),
116
+ "lng": datasets.Value(dtype="float64"),
117
+ "lat": datasets.Value(dtype="float64")
118
+ })
119
+ if self.config.name == "all":
120
+ features["day_type"] = datasets.Value(dtype="string")
121
+
122
+ return datasets.DatasetInfo(
123
+ description=_DESCRIPTION,
124
+ features=features,
125
+ supervised_keys=None,
126
+ homepage="https://zenodo.org/record/4446043#.ZEV8d-zMI-R",
127
+ citation=_CITATION
128
+ )
129
+
130
+ def _split_generators(self, dl_manager):
131
+ config_files: List[AirbnbFile] = self.config.files
132
+ urls = [file.url for file in config_files]
133
+ downloaded_files = dl_manager.download_and_extract(urls)
134
+
135
+ return [
136
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"paths": downloaded_files})
137
+ ]
138
+
139
+ def _generate_examples(self, paths: List[str]):
140
+ _id = 0
141
+ config_files: List[AirbnbFile] = self.config.files
142
+ include_day_type = self.config.name == "all"
143
+ for file, path in zip(config_files, paths):
144
+ logger.info("generating examples from = %s", path)
145
+ df = pd.read_csv(path, index_col=0, header=0)
146
+ for row in df.itertuples():
147
+ city = file.city
148
+ data = {
149
+ "_id": _id,
150
+ "city": city,
151
+ "realSum": row.realSum,
152
+ "room_type": row.room_type,
153
+ "room_shared": row.room_shared,
154
+ "room_private": row.room_private,
155
+ "person_capacity": row.person_capacity,
156
+ "host_is_superhost": row.host_is_superhost,
157
+ "multi": row.multi,
158
+ "biz": row.biz,
159
+ "cleanliness_rating": row.cleanliness_rating,
160
+ "guest_satisfaction_overall": row.guest_satisfaction_overall,
161
+ "bedrooms": row.bedrooms,
162
+ "dist": row.dist,
163
+ "metro_dist": row.metro_dist,
164
+ "attr_index": row.attr_index,
165
+ "attr_index_norm": row.attr_index_norm,
166
+ "rest_index": row.rest_index,
167
+ "rest_index_norm": row.rest_index_norm,
168
+ "lng": row.lng,
169
+ "lat": row.lat
170
+ }
171
+ if include_day_type:
172
+ data["day_type"] = file.day_type.value
173
+ yield _id, data
174
+ _id += 1