Skip to content

Commit

Permalink
r.learn.ml2 bug fix to prediction when values in training map are not…
Browse files Browse the repository at this point in the history
… labelled
  • Loading branch information
stevenpawley committed May 29, 2020
1 parent 037e38d commit d033fe0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions grass7/raster/r.learn.ml2/r.learn.predict/r.learn.predict.py
Expand Up @@ -156,11 +156,11 @@ def main():
)

# assign categories for classification map
if class_labels is not None and prob_only is False:
if class_labels and prob_only is False:
rules = []

for val, lab in class_labels.items():
rules.append(",".join([str(val), lab]))
rules.append(",".join([str(val), str(lab)]))

rules = "\n".join(rules)
rules_file = string_to_rules(rules)
Expand Down
9 changes: 6 additions & 3 deletions grass7/raster/r.learn.ml2/r.learn.train/r.learn.train.py
Expand Up @@ -576,9 +576,12 @@ def main():
y = y.flatten()

with RasterRow(training_map) as src:
class_labels = {v: k for (k, v, m) in src.cats}

if "" in class_labels.values():

if mode == "classification":
src_cats = {v: k for (k, v, m) in src.cats}
class_labels = {k:k for k in np.unique(y)}
class_labels.update(src_cats)
else:
class_labels = None

elif training_points != "":
Expand Down
Empty file.

0 comments on commit d033fe0

Please sign in to comment.