Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r.trees.mltrain crashing with error "TypeError: got an unexpected keyword argument 'fit_params'" #92

Closed
Revo2022 opened this issue Jan 14, 2025 · 1 comment · Fixed by #93
Labels
bug Something isn't working

Comments

@Revo2022
Copy link

Revo2022 commented Jan 14, 2025

Our paramaters:

r.trees.mltrain red_raster=top_red_02 green_raster=top_green_02 blue_raster=top_blue_02 nir_raster=top_nir_02 ndvi_raster=top_ndvi_02 ndsm=ndsm slope=ndsm_slope nearest=nearest_tree peaks=tree_peaks ndvi_threshold=130 nir_threshold=160 ndsm_threshold=4 slopep75_threshold=60 area_threshold=5 group=ml_input save_model=ml_trees_randomforest_testarea_2022.gz memory=1000

Our intermediate logs:


Preparing input data...
 100%
Pass 1 of 2...
 100%
Generating renumbering scheme...
 100%
Pass 2 of 2...
 100%
r.clump complete. 14774 clumps.
 100%
First pass
 100%
Writing output map
 100%
Removing raster <trees_pixel_filt_fill1_dbl>
 100%
Removing raster <trees_pixel_filt_fill2_dbl>
Pass 1 of 2...
 100%
Generating renumbering scheme...
 100%
Pass 2 of 2...
 100%
r.clump complete. 7236 clumps.
First pass
 100%
Writing output map
 100%
First pass
 100%
Writing output map
 100%
Computing histograms
 100%
Computing bins
Binning data
 100%
Sorting bins
 100%
Computing quantiles
Writing output maps
 100%
 100%
Extracting areas...
 100%
Writing areas...
 100%
Updating attributes...
 100%
Building topology for vector map <trees_object_filt_all@TestArea>...
Registering primitives...
Building areas...
 100%
Attaching islands...
 100%
Attaching centroids...
 100%
r.to.vect complete.
--------------------------------------------------
Tool: Threshold
Remove small areas: 5
--------------------------------------------------
Copying features...
 100%
Rebuilding parts of topology...
Building topology for vector map <trees_object_filt_large@TestArea>...
Registering primitives...
Building areas...
 100%
Attaching islands...
 100%
Attaching centroids...
 100%
--------------------------------------------------
Tool: Remove small areas
 100%
3419 areas of total size 4405.18 removed
--------------------------------------------------
Rebuilding topology for output vector map...
Building topology for vector map <trees_object_filt_large@TestArea>...
Registering primitives...
Building areas...
 100%
Attaching islands...
 100%
Attaching centroids...
 100%
Reading areas...
 100%
Writing raster map...
 100%
v.to.rast complete.
 100%
Collecting Stats...
 100%
Writing raster map <trees_trainpnts> ...
 100%
 100%
Collecting Stats...
 100%
Writing raster map <false_trees_trainpnts> ...
 100%
 100%
Collecting Stats...
 100%
Writing raster map <notrees_trainpnts> ...
 100%
 100%
Adding raster map <top_red_02@TestArea> to group
Adding raster map <top_green_02@TestArea> to group
Adding raster map <top_blue_02@TestArea> to group
Adding raster map <top_nir_02@TestArea> to group
Adding raster map <top_ndvi_02@TestArea> to group
Adding raster map <ndwi@TestArea> to group
Adding raster map <ndgb@TestArea> to group
Adding raster map <ndsm@TestArea> to group
Adding raster map <ndsm_slope@TestArea> to group
Extracting training data
 100%

Fitting model using RandomForestClassifier

Cross validation global performance measures......:

Our final error message:

Traceback (most recent call last):
  File "/usr/local/grass85/scripts/r.learn.train", line 892, in <module>
    main()
  File "/usr/local/grass85/scripts/r.learn.train", line 776, in main
    preds = cross_val_predict(
  File "/usr/local/lib/python3.10/dist-packages/sklearn/utils/_param_validation.py", line 194, in wrapper
    params = func_sig.bind(*args, **kwargs)
  File "/usr/lib/python3.10/inspect.py", line 3186, in bind
    return self._bind(args, kwargs)
  File "/usr/lib/python3.10/inspect.py", line 3175, in _bind
    raise TypeError(
TypeError: got an unexpected keyword argument 'fit_params'
Traceback (most recent call last):
  File "/usr/local/grass85/scripts/r.trees.mltrain", line 596, in <module>
    main()
  File "/usr/local/grass85/scripts/r.trees.mltrain", line 574, in main
    grass.run_command(
  File "/usr/local/grass85/etc/python/grass/script/core.py", line 494, in run_command
    return handle_errors(returncode, result=None, args=args, kwargs=kwargs)
  File "/usr/local/grass85/etc/python/grass/script/core.py", line 373, in handle_errors
    raise CalledModuleError(module=module, code=code, returncode=returncode)
grass.exceptions.CalledModuleError: Module run `r.learn.train -f group=ml_input training_map=ml_trainpnts save_model=ml_trees_randomforest_TestArea_2022.gz model_name=RandomForestClassifier cv=5 n_jobs=2 min_samples_leaf=5 n_estimators=100 max_depth=10` ended with an error.
The subprocess ended with a non-zero return code: 1. See errors above the traceback or in the error output.

Ive tried latest and 6.1.0

@neteler neteler added the bug Something isn't working label Jan 14, 2025
@metzm
Copy link
Contributor

metzm commented Jan 15, 2025

In sklearn.model_selection.cross_val_predict, the parameter fit_params has been removed and replaced by params in scikit learn 1.6, see https://scikit-learn.org/1.5/modules/generated/sklearn.model_selection.cross_val_predict.html

That means the GRASS addon r.learn.ml2 needs to be updated accordingly.

@metzm metzm mentioned this issue Jan 15, 2025
@metzm metzm closed this as completed in #93 Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants