|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""TODO: Add a description here.""" |
|
|
|
|
|
import csv |
|
import json |
|
import os |
|
from typing import List |
|
import datasets |
|
import logging |
|
import pandas as pd |
|
|
|
|
|
|
|
_CITATION = """\ |
|
@InProceedings{huggingface:dataset, |
|
title = {NC Crime Dataset}, |
|
author={huggingface, Inc. |
|
}, |
|
year={2024} |
|
} |
|
""" |
|
|
|
|
|
|
|
_DESCRIPTION = """\ |
|
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. |
|
""" |
|
|
|
|
|
_HOMEPAGE = "" |
|
|
|
|
|
_LICENSE = "" |
|
|
|
|
|
|
|
|
|
_URL = "" |
|
_URLS = "" |
|
|
|
class NCCrimeDataset(datasets.GeneratorBasedBuilder): |
|
"""Dataset for North Carolina Crime Incidents.""" |
|
_URLS = _URLS |
|
|
|
VERSION = datasets.Version("1.0.0") |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features( |
|
{ |
|
"year": datasets.Value("int64"), |
|
"city": datasets.Value("string"), |
|
"crime_major_category": datasets.Value("string"), |
|
"crime_detail": datasets.Value("string"), |
|
"latitude": datasets.Value("float64"), |
|
"longitude": datasets.Value("float64"), |
|
"occurance_time": datasets.Value("string"), |
|
"clear_status": datasets.Value("string"), |
|
"incident_address": datasets.Value("string"), |
|
"notes": datasets.Value("string"), |
|
"crime_severity": datasets.Value("string"), |
|
}), |
|
citation=_CITATION, |
|
) |
|
|
|
|
|
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]: |
|
|
|
downloaded_file_path = dl_manager.download_and_extract( |
|
"https://raw.githubusercontent.com/zening-wang2023/NC-Crime-Dataset/main/NC_v1.csv.zip" |
|
|
|
) |
|
unzipped_file_path = os.path.join(downloaded_file_path, "NC_v1.csv") |
|
|
|
return [ |
|
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": unzipped_file_path}) |
|
] |
|
|
|
def _generate_examples(self, filepath): |
|
|
|
df = pd.read_csv(filepath) |
|
|
|
for i, row in df.iterrows(): |
|
yield i, { |
|
"year": int(row["year"]), |
|
"city": row["city"], |
|
"crime_major_category": row["crime_major_category"], |
|
"crime_detail": row["crime_detail"], |
|
"latitude": float(row["latitude"]), |
|
"longitude": float(row["longitude"]), |
|
"occurance_time": row["occurance_time"], |
|
"clear_status": row["clear_status"], |
|
"incident_address": row["incident_address"], |
|
"notes": row["notes"], |
|
"crime_severity": row["crime_severity"], |
|
} |
|
|