# How to use StatsBase.modes correctly with MLJ?

**URL:** https://discourse.julialang.org/t/how-to-use-statsbase-modes-correctly-with-mlj/103721
**Category:** New to Julia
**Tags:** mlj
**Created:** [September 10, 2023, 2:11pm UTC](https://discourse.julialang.org/t/how-to-use-statsbase-modes-correctly-with-mlj/103721 "2023-09-10T14:11:56Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![roeya](https://avatars.discourse-cdn.com/v4/letter/r/ecb155/32.png) [@roeya](https://discourse.julialang.org/u/roeya)
#### Post date: [September 10, 2023, 2:11pm UTC](https://discourse.julialang.org/t/how-to-use-statsbase-modes-correctly-with-mlj/103721/1 "2023-09-10T14:11:56Z")

</div>

When trying to use **StatsBase.modes** of result of MLJ model fit I get error -  
`ERROR: MethodError: no method matching iterate(::UnivariateFinite{Multiclass{2}, String, UInt32, Float64})`  
However if I use **StatsBase.mode** everything works fine

`The input is the same input - UnivariateFiniteVector{Multiclass{2}, String, UInt32, Float64}`

---

<div class="post-metadata">

### Author: ![ablaom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ablaom/32/4889_2.png) [@ablaom](https://discourse.julialang.org/u/ablaom)
#### Post date: [September 11, 2023, 2:57am UTC](https://discourse.julialang.org/t/how-to-use-statsbase-modes-correctly-with-mlj/103721/2 "2023-09-11T02:57:26Z")

</div>

Indeed, `StatsBase.modes` is not overloaded for objects of type `CategoricalDistributions.UnivariateFinite` - only `mode` is.

I have opened a feature request here:

> <https://github.com/JuliaAI/CategoricalDistributions.jl/issues/58>
>
> Code can follow the pattern already established for \`mode\`, which is already imp…lemented:
> 
> \- \`mode\` is implemented here: https://github.com/JuliaAI/CategoricalDistributions.jl/blob/4be9db4197606d03480fe110f148aa1053b6eb1f/src/methods.jl#L161
> 
> \- And efficient broadcasting of \`mode\` for \`UnivariantFiniteArray\` is implemented here:
> https://github.com/JuliaAI/CategoricalDistributions.jl/blob/4be9db4197606d03480fe110f148aa1053b6eb1f/src/arrays.jl#L276
