Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
iamap
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
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
AMAP
iamap
Commits
2abd27e2
"git@forge.ird.fr:us191/TSG-QC.git" did not exist on "22d0258ec25bc602ed6fa1a44df15befdb81eb21"
Commit
2abd27e2
authored
5 months ago
by
paul.tresson_ird.fr
Browse files
Options
Downloads
Patches
Plain Diff
instantiate model with kwargs
parent
a2b5151e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ml.py
+32
-0
32 additions, 0 deletions
ml.py
with
32 additions
and
0 deletions
ml.py
+
32
−
0
View file @
2abd27e2
import
os
import
os
import
ast
import
numpy
as
np
import
numpy
as
np
from
pathlib
import
Path
from
pathlib
import
Path
from
typing
import
Dict
,
Any
from
typing
import
Dict
,
Any
...
@@ -58,6 +59,7 @@ class MLAlgorithm(SHPAlgorithm):
...
@@ -58,6 +59,7 @@ class MLAlgorithm(SHPAlgorithm):
DO_KFOLDS
=
'
DO_KFOLDS
'
DO_KFOLDS
=
'
DO_KFOLDS
'
FOLD_COL
=
'
FOLD_COL
'
FOLD_COL
=
'
FOLD_COL
'
NFOLDS
=
'
NFOLDS
'
NFOLDS
=
'
NFOLDS
'
SK_PARAM
=
'
SK_PARAM
'
TEMPLATE_TEST
=
'
TEMPLATE_TEST
'
TEMPLATE_TEST
=
'
TEMPLATE_TEST
'
METHOD
=
'
METHOD
'
METHOD
=
'
METHOD
'
TMP_DIR
=
'
iamap_ml
'
TMP_DIR
=
'
iamap_ml
'
...
@@ -85,6 +87,16 @@ class MLAlgorithm(SHPAlgorithm):
...
@@ -85,6 +87,16 @@ class MLAlgorithm(SHPAlgorithm):
)
)
)
)
self
.
addParameter
(
QgsProcessingParameterString
(
name
=
self
.
SK_PARAM
,
description
=
self
.
tr
(
'
Arguments for the initialisation of the algorithm. If empty this goes to sklearn default. It will overwrite cluster or components arguments.
'
),
defaultValue
=
''
,
optional
=
True
,
)
)
self
.
addParameter
(
self
.
addParameter
(
QgsProcessingParameterFile
(
QgsProcessingParameterFile
(
...
@@ -220,6 +232,13 @@ class MLAlgorithm(SHPAlgorithm):
...
@@ -220,6 +232,13 @@ class MLAlgorithm(SHPAlgorithm):
## If no test set is provided and the option to perform kfolds is true,
## If no test set is provided and the option to perform kfolds is true,
## we perform kfolds
## we perform kfolds
str_kwargs
=
self
.
parameterAsString
(
parameters
,
self
.
SK_PARAM
,
context
)
if
str_kwargs
!=
''
:
self
.
passed_kwargs
=
ast
.
literal_eval
(
str_kwargs
)
else
:
self
.
passed_kwargs
=
{}
## If a fold column is provided, this defines the folds. Otherwise, random split
## If a fold column is provided, this defines the folds. Otherwise, random split
if
self
.
test_gdf
==
None
and
self
.
do_kfold
:
if
self
.
test_gdf
==
None
and
self
.
do_kfold
:
if
fold_col
!=
''
:
if
fold_col
!=
''
:
...
@@ -227,8 +246,21 @@ class MLAlgorithm(SHPAlgorithm):
...
@@ -227,8 +246,21 @@ class MLAlgorithm(SHPAlgorithm):
else
:
else
:
self
.
gdf
[
'
fold
'
]
=
np
.
random
.
randint
(
1
,
nfolds
+
1
,
size
=
len
(
self
.
gdf
))
self
.
gdf
[
'
fold
'
]
=
np
.
random
.
randint
(
1
,
nfolds
+
1
,
size
=
len
(
self
.
gdf
))
print
(
self
.
gdf
)
print
(
self
.
gdf
)
method_idx
=
self
.
parameterAsEnum
(
parameters
,
self
.
METHOD
,
context
)
self
.
method_name
=
self
.
method_opt
[
method_idx
]
try
:
default_args
=
get_arguments
(
ensemble
,
self
.
method_name
)
except
AttributeError
:
default_args
=
get_arguments
(
neighbors
,
self
.
method_name
)
kwargs
=
self
.
update_kwargs
(
default_args
)
try
:
self
.
model
=
instantiate_sklearn_algorithm
(
ensemble
,
self
.
method_name
,
**
kwargs
)
except
AttributeError
:
self
.
model
=
instantiate_sklearn_algorithm
(
neighbors
,
self
.
method_name
,
**
kwargs
)
def
get_algorithms
(
self
):
def
get_algorithms
(
self
):
required_methods
=
[
'
fit
'
,
'
predict
'
]
required_methods
=
[
'
fit
'
,
'
predict
'
]
...
...
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