Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SHIRE
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
mbd
SHIRE
Commits
966d8258
Commit
966d8258
authored
9 months ago
by
Ann-Kathrin Margarete Edrich
Browse files
Options
Downloads
Patches
Plain Diff
Fix categorical_classes for ordinal encoding
parent
b5441d0b
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/gui_version/RandomForest_gui.py
+30
-6
30 additions, 6 deletions
src/gui_version/RandomForest_gui.py
src/plain_scripts/RandomForest.py
+2
-2
2 additions, 2 deletions
src/plain_scripts/RandomForest.py
with
32 additions
and
8 deletions
src/gui_version/RandomForest_gui.py
+
30
−
6
View file @
966d8258
...
@@ -140,7 +140,7 @@ class prepare_data:
...
@@ -140,7 +140,7 @@ class prepare_data:
classes
.
append
([
f
.
split
(
'
_
'
)[
-
2
]
for
f
in
df_sub
.
columns
.
tolist
()
if
feat
in
f
])
classes
.
append
([
f
.
split
(
'
_
'
)[
-
2
]
for
f
in
df_sub
.
columns
.
tolist
()
if
feat
in
f
])
self
.
distibuish_encoding
[
feat
]
=
'
ohe
'
self
.
distibuish_encoding
[
feat
]
=
'
ohe
'
else
:
else
:
classes
.
append
(
li
s
t
(
set
(
df_sub
[
feat
+
'
_encode
'
].
tolist
()))
)
classes
.
append
(
[
f
.
sp
lit
(
'
_
'
)[
-
2
]
for
f
in
df_sub
.
columns
.
tolist
()
if
feat
in
f
]
)
self
.
distibuish_encoding
[
feat
]
=
'
ordinal
'
self
.
distibuish_encoding
[
feat
]
=
'
ordinal
'
self
.
categorical_classes
[
feat
]
=
{}
self
.
categorical_classes
[
feat
]
=
{}
self
.
categorical_classes
[
feat
][
'
classes
'
]
=
[
item
for
sublist
in
classes
for
item
in
sublist
]
self
.
categorical_classes
[
feat
][
'
classes
'
]
=
[
item
for
sublist
in
classes
for
item
in
sublist
]
...
@@ -197,7 +197,7 @@ class prepare_data:
...
@@ -197,7 +197,7 @@ class prepare_data:
if
cat_feat
.
count
(
feat
)
>
1
:
if
cat_feat
.
count
(
feat
)
>
1
:
classes
.
append
([
f
.
split
(
'
_
'
)[
-
2
]
for
f
in
df_sub
.
columns
.
tolist
()
if
feat
in
f
])
classes
.
append
([
f
.
split
(
'
_
'
)[
-
2
]
for
f
in
df_sub
.
columns
.
tolist
()
if
feat
in
f
])
else
:
else
:
classes
.
append
(
li
s
t
(
set
(
df_sub
[
feat
+
'
_encode
'
].
tolist
()))
)
classes
.
append
(
[
f
.
sp
lit
(
'
_
'
)[
-
2
]
for
f
in
df_sub
.
columns
.
tolist
()
if
feat
in
f
]
)
self
.
categorical_classes
[
feat
]
=
{}
self
.
categorical_classes
[
feat
]
=
{}
self
.
categorical_classes
[
feat
][
'
classes
'
]
=
[
item
for
sublist
in
classes
for
item
in
sublist
]
self
.
categorical_classes
[
feat
][
'
classes
'
]
=
[
item
for
sublist
in
classes
for
item
in
sublist
]
self
.
categorical_classes
[
feat
][
'
num_cols
'
]
=
cat_feat
.
count
(
feat
)
self
.
categorical_classes
[
feat
][
'
num_cols
'
]
=
cat_feat
.
count
(
feat
)
...
@@ -241,7 +241,13 @@ class prepare_data:
...
@@ -241,7 +241,13 @@ class prepare_data:
class
RandomForest
(
prepare_data
):
class
RandomForest
(
prepare_data
):
"""
This class conducts the training of the Random Forest model and the
generation of the landslide susceptibility and hazard map.
"""
def
__init__
(
self
,
master
,
aim
,
parallel
=
False
,
log
=
None
,
retrain
=
None
):
def
__init__
(
self
,
master
,
aim
,
parallel
=
False
,
log
=
None
,
retrain
=
None
):
super
().
__init__
(
master
,
aim
,
log
=
log
,
retrain
=
retrain
)
super
().
__init__
(
master
,
aim
,
log
=
log
,
retrain
=
retrain
)
self
.
aim
=
aim
self
.
aim
=
aim
self
.
logger
=
log
self
.
logger
=
log
...
@@ -372,6 +378,13 @@ class RandomForest(prepare_data):
...
@@ -372,6 +378,13 @@ class RandomForest(prepare_data):
"""
"""
Split a NumPy array into chunks without changing the number of columns.
Split a NumPy array into chunks without changing the number of columns.
Input:
pred: prediction dataset, varies depending on if the current run
is for model training or map generation
Output:
Nones
"""
"""
# Calculate the number of rows in each chunk
# Calculate the number of rows in each chunk
...
@@ -506,12 +519,22 @@ class RandomForest(prepare_data):
...
@@ -506,12 +519,22 @@ class RandomForest(prepare_data):
not included in the training dataset are either set to no_value or
not included in the training dataset are either set to no_value or
nevertheless considered in the prediction. The surplus additional
nevertheless considered in the prediction. The surplus additional
features are removed either way to achieve the same set of features
features are removed either way to achieve the same set of features
as in the training dataset
as in the training dataset.
The prediction dataset is furthermore assessed if all features
that are included in the training dataset also appear in the prediction
dataset. If that is not the case, the training process is relaunched
with an adapted training dataset where the feature(s) that is/are
not contrained in the training dataset are removed. The second
trained model will be stored in a seperate folder which is named
<old_folder_name>_retrain.
Input:
Input:
train_classes: dictionary containing for each categorical feature
train_classes: dictionary containing for each categorical feature
all classes and the number of total classes
all classes and the number of total classes
contained in the training dataset
contained in the training dataset
training_features: Complete feature names of the features
contained in the training dataset
Output:
Output:
None
None
...
@@ -539,6 +562,7 @@ class RandomForest(prepare_data):
...
@@ -539,6 +562,7 @@ class RandomForest(prepare_data):
self
.
master
.
update
()
self
.
master
.
update
()
self
.
logger
.
error
(
'
Error: Categorical feature
'
+
feat
+
'
not in prediction dataset
'
)
self
.
logger
.
error
(
'
Error: Categorical feature
'
+
feat
+
'
not in prediction dataset
'
)
self
.
logger
.
error
(
'
Error: cannot proceed with mapping
'
)
self
.
error
=
True
self
.
error
=
True
self
.
retrain
=
True
self
.
retrain
=
True
self
.
features_not_in_training
.
append
(
feat
)
self
.
features_not_in_training
.
append
(
feat
)
...
...
This diff is collapsed.
Click to expand it.
src/plain_scripts/RandomForest.py
+
2
−
2
View file @
966d8258
...
@@ -107,7 +107,7 @@ class prepare_data:
...
@@ -107,7 +107,7 @@ class prepare_data:
classes
.
append
([
f
.
split
(
'
_
'
)[
-
2
]
for
f
in
df_sub
.
columns
.
tolist
()
if
feat
in
f
])
classes
.
append
([
f
.
split
(
'
_
'
)[
-
2
]
for
f
in
df_sub
.
columns
.
tolist
()
if
feat
in
f
])
self
.
distibuish_encoding
[
feat
]
=
'
ohe
'
self
.
distibuish_encoding
[
feat
]
=
'
ohe
'
else
:
else
:
classes
.
append
(
li
s
t
(
set
(
df_sub
[
feat
+
'
_encoded
'
].
tolist
()))
)
classes
.
append
(
[
f
.
sp
lit
(
'
_
'
)[
-
2
]
for
f
in
df_sub
.
columns
.
tolist
()
if
feat
in
f
]
)
self
.
distibuish_encoding
[
feat
]
=
'
ordinal
'
self
.
distibuish_encoding
[
feat
]
=
'
ordinal
'
self
.
categorical_classes
[
feat
]
=
{}
self
.
categorical_classes
[
feat
]
=
{}
self
.
categorical_classes
[
feat
][
'
classes
'
]
=
[
item
for
sublist
in
classes
for
item
in
sublist
]
self
.
categorical_classes
[
feat
][
'
classes
'
]
=
[
item
for
sublist
in
classes
for
item
in
sublist
]
...
@@ -171,7 +171,7 @@ class prepare_data:
...
@@ -171,7 +171,7 @@ class prepare_data:
if
cat_feat
.
count
(
feat
)
>
1
:
if
cat_feat
.
count
(
feat
)
>
1
:
classes
.
append
([
f
.
split
(
'
_
'
)[
-
2
]
for
f
in
df_sub
.
columns
.
tolist
()
if
feat
in
f
])
classes
.
append
([
f
.
split
(
'
_
'
)[
-
2
]
for
f
in
df_sub
.
columns
.
tolist
()
if
feat
in
f
])
else
:
else
:
classes
.
append
(
li
s
t
(
set
(
df_sub
[
feat
+
'
_encoded
'
].
tolist
()))
)
classes
.
append
(
[
f
.
sp
lit
(
'
_
'
)[
-
2
]
for
f
in
df_sub
.
columns
.
tolist
()
if
feat
in
f
]
)
self
.
categorical_classes
[
feat
]
=
{}
self
.
categorical_classes
[
feat
]
=
{}
self
.
categorical_classes
[
feat
][
'
classes
'
]
=
[
item
for
sublist
in
classes
for
item
in
sublist
]
self
.
categorical_classes
[
feat
][
'
classes
'
]
=
[
item
for
sublist
in
classes
for
item
in
sublist
]
self
.
categorical_classes
[
feat
][
'
num_cols
'
]
=
cat_feat
.
count
(
feat
)
self
.
categorical_classes
[
feat
][
'
num_cols
'
]
=
cat_feat
.
count
(
feat
)
...
...
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