dataset_preparation
predspot.dataset_preparation
¶
Dataset Preparation Module¶
Prepares crime event data together with the study area it belongs to.
Dataset validates the input, converts the events to a
GeoDataFrame
of points in WGS84 and offers simple plotting and splitting helpers.
Dataset
¶
Crime events plus the study area they occurred in.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
crimes
|
DataFrame
|
Crime events with at least the columns
|
required |
study_area
|
GeoDataFrame
|
Boundary of the study area. It must have a CRS set. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
crimes |
GeoDataFrame
|
Events as points in WGS84 with the
original columns preserved and |
study_area |
GeoDataFrame
|
The study area boundary. |
Source code in src/predspot/dataset_preparation.py
plot
¶
Plot the study area with a sample of the crime events.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Axes to draw on. |
None
|
crime_samples
|
int
|
Number of events to draw (random sample). |
1000
|
**kwargs
|
dict
|
|
{}
|
Returns:
| Type | Description |
|---|---|
Axes
|
The axes drawn on. |
Source code in src/predspot/dataset_preparation.py
train_test_split
¶
Randomly split the events into two datasets sharing the study area.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
test_size
|
float
|
Fraction of events in the test dataset (0-1). |
0.25
|
random_state
|
int
|
Seed for reproducibility. |
None
|
Returns:
| Type | Description |
|---|---|
tuple
|
|