Upload NC Crime Dateset.py
Browse files- NC Crime Dateset.py +94 -0
NC Crime Dateset.py
ADDED
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
2 |
+
#
|
3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
# you may not use this file except in compliance with the License.
|
5 |
+
# You may obtain a copy of the License at
|
6 |
+
#
|
7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
#
|
9 |
+
# Unless required by applicable law or agreed to in writing, software
|
10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
# See the License for the specific language governing permissions and
|
13 |
+
# limitations under the License.
|
14 |
+
# TODO: Address all TODOs and remove all explanatory comments
|
15 |
+
"""TODO: Add a description here."""
|
16 |
+
|
17 |
+
|
18 |
+
import csv
|
19 |
+
import json
|
20 |
+
import os
|
21 |
+
from typing import List
|
22 |
+
import datasets
|
23 |
+
import logging
|
24 |
+
|
25 |
+
# TODO: Add BibTeX citation
|
26 |
+
# Find for instance the citation on arxiv or on the dataset repo/website
|
27 |
+
_CITATION = """\
|
28 |
+
@InProceedings{huggingface:dataset,
|
29 |
+
title = {NC Crime Dataset},
|
30 |
+
author={huggingface, Inc.
|
31 |
+
},
|
32 |
+
year={2024}
|
33 |
+
}
|
34 |
+
"""
|
35 |
+
|
36 |
+
# TODO: Add description of the dataset here
|
37 |
+
# You can copy an official description
|
38 |
+
_DESCRIPTION = """\
|
39 |
+
The dataset, compiled from public police incident reports across various cities in North Carolina, covers a period from the early 2000s through to 2024. It is intended to facilitate the study of crime trends and patterns.
|
40 |
+
"""
|
41 |
+
|
42 |
+
class NCCrimeDataset(datasets.GeneratorBasedBuilder):
|
43 |
+
"""Dataset for North Carolina Crime Incidents."""
|
44 |
+
|
45 |
+
VERSION = datasets.Version("1.0.0")
|
46 |
+
|
47 |
+
def _info(self):
|
48 |
+
return datasets.DatasetInfo(
|
49 |
+
description=_DESCRIPTION,
|
50 |
+
features=datasets.Features(
|
51 |
+
{
|
52 |
+
"year": datasets.Value("int64"),
|
53 |
+
"city": datasets.Value("string"),
|
54 |
+
"crime_major_category": datasets.Value("string"),
|
55 |
+
"crime_detail": datasets.Value("string"),
|
56 |
+
"latitude": datasets.Value("float64"),
|
57 |
+
"longitude": datasets.Value("float64"),
|
58 |
+
"occurance_time": datasets.Value("string"),
|
59 |
+
"clear_status": datasets.Value("string"),
|
60 |
+
"incident_address": datasets.Value("string"),
|
61 |
+
"notes": datasets.Value("string"),
|
62 |
+
}),
|
63 |
+
citation=_CITATION
|
64 |
+
)
|
65 |
+
|
66 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
67 |
+
# Download and extract the data file
|
68 |
+
downloaded_file_path = dl_manager.download_and_extract(
|
69 |
+
"https://drive.google.com/uc?id=1Se-B8Y-SdU0caZzGJyX_0YW44TZwaq3l")
|
70 |
+
|
71 |
+
# Return a list of split generators
|
72 |
+
return [
|
73 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_file_path}),
|
74 |
+
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_file_path}),
|
75 |
+
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_file_path}),
|
76 |
+
]
|
77 |
+
|
78 |
+
def _generate_examples(self, filepath):
|
79 |
+
# Read the CSV file
|
80 |
+
df = pd.read_csv(filepath)
|
81 |
+
# Iterate over the rows and yield examples
|
82 |
+
for i, row in df.iterrows():
|
83 |
+
yield i, {
|
84 |
+
"year": int(row["year"]),
|
85 |
+
"city": row["city"],
|
86 |
+
"crime_major_category": row["crime_major_category"],
|
87 |
+
"crime_detail": row["crime_detail"],
|
88 |
+
"latitude": float(row["latitude"]),
|
89 |
+
"longitude": float(row["longitude"]),
|
90 |
+
"occurance_time": row["occurance_time"],
|
91 |
+
"clear_status": row["clear_status"],
|
92 |
+
"incident_address": row["incident_address"],
|
93 |
+
"notes": row["notes"],
|
94 |
+
}
|