Skip to content

Also save predictions in separate csv/geojson with 1 row per prediction #292

@rwood-97

Description

@rwood-97

For viewing results, would be good to save the predictions to a csv/geojson file with 1 row per prediction instead of aggregated at the article level.

Code for doing this using current csv:

import pandas as pd
from ast import literal_eval
import geopandas as gpd
from shapely import Point

preds = pd.read_csv("./UK_France_test_sample_pretrained-perfectmatch-reldisamb-predictpub-combined-nomicro.csv")
preds["predictions"] = preds["predictions"].apply(literal_eval) # apply literal_eval to ensure predictions column is interpreted as a list

predictions = preds["predictions"].tolist() # get predictions column
predictions = [
    pred for prediction in predictions for pred in prediction
] # flatten list

df = pd.DataFrame(predictions)
df["predicted_coordinates"] = df["predicted_coordinates"].apply(Point) # convert coords to shapely point
gdf = gpd.GeoDataFrame(df, geometry="predicted_coordinates") # create geodataframe

gdf.to_file("UK_France_test_sample_pretrained-perfectmatch-reldisamb-predictpub-combined-nomicro.geojson", driver="GeoJSON") # save to geojson

If you already have the predictions list, start from flattening.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions