Skip to content

Commit ef707a8

Browse files
refactor: use sum in sql query
and set zero_devision to nan for report Closes #899
1 parent 4712e11 commit ef707a8

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

ohsome_quality_api/indicators/land_cover_thematic_accuracy/indicator.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from pathlib import Path
44
from string import Template
55

6+
import numpy
67
import plotly.graph_objects as pgo
78
from geojson import Feature
89
from sklearn.metrics import classification_report, confusion_matrix, f1_score
@@ -137,15 +138,12 @@ def calculate(self) -> None:
137138
f"{label_description} {self.templates.result_description}"
138139
)
139140

140-
# TODO: UdefinedMetricWarning
141-
# Recall is ill-defined and being set to 0.0 in labels with no
142-
# true samples. Use `zero_division` parameter to control this
143-
# behavior.
144141
# NOTE: For introspection/testing only
145142
self.report = classification_report(
146143
self.clc_classes_corine,
147144
self.clc_classes_osm,
148145
sample_weight=self.areas,
146+
zero_division=numpy.nan,
149147
)
150148

151149
def create_figure(self) -> None:

ohsome_quality_api/indicators/land_cover_thematic_accuracy/query-multi-classes.sql

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@ WITH bpoly AS (
66
SELECT
77
CLC_class as clc_class_corine,
88
osm_CLC_class as clc_class_osm,
9-
CASE WHEN ST_Within (o.geometry, b.geometry) THEN
10-
area
11-
ELSE
12-
ST_Area (ST_Intersection (o.geometry, b.geometry)::geography)
13-
END AS area
9+
SUM (
10+
CASE WHEN ST_Within (o.geometry, b.geometry) THEN
11+
area
12+
ELSE
13+
ST_Area (ST_Intersection (o.geometry, b.geometry)::geography)
14+
END) AS area
1415
FROM
1516
osm_corine_2021_deu_intersection o,
1617
bpoly b
1718
WHERE
18-
ST_Intersects (o.geometry, b.geometry);
19+
ST_Intersects (o.geometry, b.geometry)
20+
--AND osm_CLC_class != 0
21+
--AND osm_CLC_class != 50
22+
GROUP BY 1,2
23+
;
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
precision recall f1-score support
22

3-
0 0.00 0.00 0.00 0.0
3+
0 0.00 nan 0.00 0.0
44
11 0.94 0.86 0.90 13.681696054340627
55
12 0.84 0.87 0.85 4.868706606602494
6-
13 0.00 0.00 0.00 0.0
6+
13 0.00 nan 0.00 0.0
77
14 0.13 0.42 0.20 0.3617314972878062
88
21 0.86 0.91 0.89 15.526750634345152
99
22 0.64 0.76 0.70 2.2997486561073313
1010
23 0.75 0.44 0.55 6.712711587504546
11-
24 0.00 0.00 0.00 0.084999664294624
11+
24 nan 0.00 0.00 0.084999664294624
1212
31 0.82 0.92 0.87 10.490463269571688
1313
32 0.00 0.00 0.00 0.2576135038588164
14-
50 0.00 0.00 0.00 0.0
15-
51 0.00 0.00 0.00 0.033118424422509736
14+
50 0.00 nan 0.00 0.0
15+
51 nan 0.00 0.00 0.033118424422509736
1616

1717
accuracy 0.82 54.31753989833559
18-
macro avg 0.38 0.40 0.38 54.31753989833559
18+
macro avg 0.45 0.52 0.38 54.31753989833559
1919
weighted avg 0.84 0.82 0.82 54.31753989833559

0 commit comments

Comments
 (0)