HathawayLiu commited on
Commit
9ebbf2b
1 Parent(s): 72f33dc

Upload housing_dataset.py

Browse files
Files changed (1) hide show
  1. housing_dataset.py +165 -0
housing_dataset.py ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
+ # you may not use this file except in compliance with the License.
4
+ # You may obtain a copy of the License at
5
+ #
6
+ # http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS,
10
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ # See the License for the specific language governing permissions and
12
+ # limitations under the License.
13
+ # T0: Address all TODOs and remove all explanatory comments
14
+ """ TO: Add a description here.
15
+ """
16
+
17
+
18
+ import csv
19
+ import json
20
+ import os
21
+ from typing import List
22
+ import datasets
23
+ import logging
24
+ import pandas as pd
25
+ import torch
26
+
27
+ # TODO: Add BibTeX citation
28
+ # Find for instance the citation on arxiv or on the dataset repo/website
29
+ _CITATION = """
30
+ @InProceedings{huggingface:dataset,
31
+ title = {A great new dataset},
32
+ author={huggingface, Inc.
33
+ },
34
+ year={2020}
35
+ }
36
+ """
37
+
38
+ # TODO: Add description of the dataset here
39
+ # You can copy an official description
40
+ _DESCRIPTION = """
41
+ This typical dataset contains all the building permits issued or in progress
42
+ within the city of Seattle starting from 1990 to recent, and this dataset is
43
+ still updating as time flows. Information includes permit records urls,
44
+ detailed address, and building costs etc.
45
+ """
46
+
47
+ # TODO: Add a link to an official homepage for the dataset here
48
+ _HOMEPAGE = "https://data.seattle.gov/Permitting/Building-Permits/76t5-zqzr/about_data"
49
+
50
+ # TODO: Add the licence for the dataset here if you can find it
51
+ _LICENSE = " http://www.seattle.gov/sdci"
52
+
53
+ # TODO: Add link to the official dataset URLs here
54
+ # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
55
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
56
+ _URL = "https://data.seattle.gov/Permitting/Building-Permits/76t5-zqzr/about_data"
57
+ _URLS = {
58
+ "train": "https://github.com/HathawayLiu/Housing_dataset/raw/main/housing_train_dataset.csv",
59
+ "test": "https://github.com/HathawayLiu/Housing_dataset/raw/main/housing_test_dataset.csv",
60
+ }
61
+
62
+ # TODO: Name of the dataset usually matches the script name with CamelCase instead of snake_case
63
+ class HousingDataset(datasets.GeneratorBasedBuilder):
64
+ """This dataset contains all building permits issued or in progress within
65
+ the city of Seattle. It includes the original columns in the datasets, with
66
+ new added columns for corresponding neighborhood district and parking lot
67
+ near by each housing."""
68
+
69
+ _URLS = _URLS
70
+ VERSION = datasets.Version("1.1.0")
71
+
72
+ def _info(self):
73
+ return datasets.DatasetInfo(
74
+ description=_DESCRIPTION,
75
+ features=datasets.Features(
76
+ {
77
+ # columns from original dataset
78
+ "permitnum": datasets.Value("string"),
79
+ "permitclass": datasets.Value("string"),
80
+ "permitclassmapped": datasets.Value("string"),
81
+ "permittypemapped": datasets.Value("string"),
82
+ "permittypedesc": datasets.Value("string"),
83
+ "description": datasets.Value("string"),
84
+ "housingunits": datasets.Value("int64"),
85
+ "housingunitsremoved": datasets.Value("int64"),
86
+ "housingunitsadded": datasets.Value("int64"),
87
+ "estprojectcost": datasets.Value("float32"),
88
+ "applieddate": datasets.Value("string"),
89
+ "issueddate": datasets.Value("string"),
90
+ "expiresdate": datasets.Value("string"),
91
+ "completeddate": datasets.Value("string"),
92
+ "statuscurrent": datasets.Value("string"),
93
+ "relatedmup": datasets.Value("string"),
94
+ "originaladdress1": datasets.Value("string"),
95
+ "originalcity": datasets.Value("string"),
96
+ "originalstate": datasets.Value("string"),
97
+ "originalzip": datasets.Value("int64"),
98
+ "contractorcompanyname": datasets.Value("string"),
99
+ "link": datasets.Value("string"),
100
+ "latitude": datasets.Value("float32"),
101
+ "longitude": datasets.Value("float32"),
102
+ "location1": datasets.Value("string"),
103
+ # new added columns below
104
+ "neighbordistrict": datasets.Value("string")
105
+ }
106
+ ),
107
+ # No default supervised_keys (as we have to pass both question
108
+ # and context as input).
109
+ supervised_keys=None,
110
+ homepage=_HOMEPAGE,
111
+ citation=_CITATION,
112
+ )
113
+
114
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
115
+ urls = self._URLS
116
+ downloaded_files = dl_manager.download_and_extract(urls)
117
+
118
+ return [
119
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
120
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
121
+ ]
122
+
123
+ def _generate_examples(self, filepath):
124
+ """This function returns the examples in the raw (text) form."""
125
+ logging.info("generating examples from = %s", filepath)
126
+ with open(filepath) as f:
127
+ housing_df = pd.read_csv(f)
128
+
129
+ housing_df['EstProjectCost'] = housing_df["EstProjectCost"].replace('NA', 0)
130
+ housing_df.dropna(subset = ['Latitude'], inplace = True)
131
+ housing_df.dropna(subset = ['OriginalZip'], inplace = True)
132
+
133
+ housing_df['Latitude'] = housing_df['Latitude'].astype(float)
134
+ housing_df['Longitude'] = housing_df['Longitude'].astype(float)
135
+
136
+ # Iterating through each row to generate examples
137
+ for index, row in housing_df.iterrows():
138
+ yield index, {
139
+ "permitnum": row.get("PermitNum", ""),
140
+ "permitclass": row.get("PermitClass", ""),
141
+ "permitclassmapped": row.get("PermitClassMapped", ""),
142
+ "permittypemapped": row.get("PermitTypeMapped", ""),
143
+ "permittypedesc": row.get("PermitTypeDesc", ""),
144
+ "description": row.get("Description", ""),
145
+ "housingunits": int(row.get("HousingUnits", "")),
146
+ "housingunitsremoved": int(row.get("HousingUnitsRemoved", "")),
147
+ "housingunitsadded": int(row.get("HousingUnitsAdded", "")),
148
+ "estprojectcost": float(row.get("EstProjectCost", "")),
149
+ "applieddate": str(row.get("AppliedDate", "")),
150
+ "issueddate": str(row.get("IssuedDate", "")),
151
+ "expiresdate": str(row.get("ExpiresDate", "")),
152
+ "completeddate": str(row.get("CompletedDate", "")),
153
+ "statuscurrent": row.get("StatusCurrent", ""),
154
+ "relatedmup": row.get("RelatedMup", ""),
155
+ "originaladdress1": row.get("OriginalAddress1", ""),
156
+ "originalcity": row.get("OriginalCity", ""),
157
+ "originalstate": row.get("OriginalState", ""),
158
+ "originalzip": int(row.get("OriginalZip", "")),
159
+ "contractorcompanyname": row.get("ContractorCompanyName", ""),
160
+ "link": row.get("Link", ""),
161
+ "latitude": row["Latitude"],
162
+ "longitude": row["Longitude"],
163
+ "location1": str(row["Latitude"]) + ", " + str(row["Longitude"]),
164
+ "neighbordistrict": row.get("NeighborDistrict", "")
165
+ }