Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Toponym Geocoding
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jacques Fize
Toponym Geocoding
Commits
263c2537
Commit
263c2537
authored
4 years ago
by
Fize Jacques
Browse files
Options
Downloads
Patches
Plain Diff
Add evaluation script for baselines
parent
56a4ce79
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
evaluate_baseline.py
+40
-0
40 additions, 0 deletions
evaluate_baseline.py
with
40 additions
and
0 deletions
evaluate_baseline.py
0 → 100644
+
40
−
0
View file @
263c2537
from
joblib
import
load
import
pandas
as
pd
from
lib.utils_geo
import
haversine_pd
,
latlon2healpix
import
argparse
import
os
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"
model_file
"
)
parser
.
add_argument
(
"
vectorizer_file
"
)
parser
.
add_argument
(
"
geocoding_dataset
"
)
parser
.
add_argument
(
"
--healpix-nside
"
,
default
=
128
)
args
=
parser
.
parse_args
()
MODEL_FN
=
args
.
model_file
VECTORIZER_FN
=
args
.
vectorizer_file
GEOCODING_DATASET_FN
=
args
.
geocoding_dataset
HEALPIX_RES
=
args
.
healpix_nside
for
fn
in
[
MODEL_FN
,
VECTORIZER_FN
,
GEOCODING_DATASET_FN
]:
if
not
os
.
path
.
exists
(
fn
):
raise
FileNotFoundError
(
"
File {0} does not exists!
"
.
format
(
fn
))
# LOAD Model
model
=
load
(
MODEL_FN
)
vectorizer
=
load
(
VECTORIZER_FN
)
# LOAD Geocoding dataset
df
=
pd
.
read_csv
(
GEOCODING_DATASET_FN
,
sep
=
"
\t
"
)
# convert coordinates to Healpix Resolution used to trained the model
df
[
"
hp_split
"
]
=
df
.
apply
(
lambda
row
:
latlon2healpix
(
row
.
latitude
,
row
.
longitude
,
HEALPIX_RES
),
axis
=
1
)
# preprocess the input
df
[
"
input_
"
]
=
df
.
apply
(
lambda
row
:
row
.
toponym
+
"
"
+
row
.
toponym_context
,
axis
=
1
)
X_test
=
vectorizer
.
transform
(
df
.
input_
.
values
)
# predict the healpix cell for each pair in the input
df
[
"
hp_pred
"
]
=
model
.
predict
(
X_test
)
# return the accurracy
print
((
df
.
hp_pred
==
df
.
hp_split
).
sum
()
/
len
(
df
))
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment