# Noobish question regarding yhat probabilities

**URL:** https://discourse.julialang.org/t/noobish-question-regarding-yhat-probabilities/73905
**Category:** Machine Learning
**Tags:** mlj
**Created:** [January 1, 2022, 8:15pm UTC](https://discourse.julialang.org/t/noobish-question-regarding-yhat-probabilities/73905 "2022-01-01T20:15:29Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![AdamWysokinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adamwysokinski/32/206422_2.png) [@AdamWysokinski](https://discourse.julialang.org/u/AdamWysokinski)
#### Post date: [January 1, 2022, 8:15pm UTC](https://discourse.julialang.org/t/noobish-question-regarding-yhat-probabilities/73905/1 "2022-01-01T20:15:29Z")

</div>

Hi,  
I’ve just started learning MLJ and I’m recreating a RandomForrect-based binary classification that I did in Python/Scikit. The MLJ version works fine, with one major exception.When I put new data through the trained model, all classification results (based on yhat probabilities) are reversed i.e. group 0 instead of 1 and 1 instead of 0. After subtracting yhat probabilities from 1, I get proper classification. Could someone please enlighten me how to interpret the yhat probabilities?

```julia
yhat = MLJ.predict(model_rf_final, x)
p = yhat[idx].prob_given_ref
# this gets proper classification
p_group0 = 1 - p[1]  
p_group1 = 1 - p[2]
# this gets reversed classification
p_group0 = p[1]  
p_group1 = p[2]

```

e.g. for case 1, which belongs to group 0:

```julia
julia> yhat[1]                                                                                                                                                                            
         UnivariateFinite{OrderedFactor{2}}     
     ┌ ┐ 
   0 ┤■■■■■■■■■ 0.21                            
   1 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 0.79   
     └ ┘ 

```

Thanks, Adam

---

<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: [January 2, 2022, 2:51am UTC](https://discourse.julialang.org/t/noobish-question-regarding-yhat-probabilities/73905/2 "2022-01-02T02:51:37Z")

</div>

Thanks for reporting. Be helpful if you include a complete minimum working example. In particular, which RandomForest classifier are you using? I think 3 different packages provide a model of that name.

---

<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: [January 2, 2022, 3:05am UTC](https://discourse.julialang.org/t/noobish-question-regarding-yhat-probabilities/73905/3 "2022-01-02T03:05:46Z")

</div>

Ah, I see you are using `prob_given_ref`, which is a private variable. This may be the problem, as the `ref`s are internal representations of the class, not necessarily the class labels you trained with (which don’t have to be integers.) To access the probabilities in MLJ you should use the `pdf` method (actually from Distributions.jl) as shown in the examples in [“Getting Started”](https://alan-turing-institute.github.io/MLJ.jl/dev/getting_started/#Fit-and-predict).

In ScikitLearn-learn classes are always integers with no tracking of the complete pool. For more on working with categorical data in MLJ see [here](https://alan-turing-institute.github.io/MLJ.jl/dev/working_with_categorical_data/).

---

<div class="post-metadata">

### Author: ![AdamWysokinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adamwysokinski/32/206422_2.png) [@AdamWysokinski](https://discourse.julialang.org/u/AdamWysokinski)
#### Post date: [January 2, 2022, 11:26am UTC](https://discourse.julialang.org/t/noobish-question-regarding-yhat-probabilities/73905/4 "2022-01-02T11:26:00Z")

</div>

Hi,  
Thank you, I did as instructed and learned about using pdf.  
The problem was however in another part of the program, where classes were incorrectly labeled in the training material 🤦‍♂️
