# Using measure in MLJ to evaluate binary classifier

**URL:** <https://discourse.julialang.org/t/using-measure-in-mlj-to-evaluate-binary-classifier/67025>\
**Category:** New to Julia\
**Tags:** machine-learning, mlj\
**Created:** [August 26, 2021, 9:50am UTC](https://discourse.julialang.org/t/using-measure-in-mlj-to-evaluate-binary-classifier/67025 "2021-08-26T09:50:37Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![CameronBieganek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cameronbieganek/32/6915_2.png) [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)\
**Post date:** [August 26, 2021, 4:33pm UTC](https://discourse.julialang.org/t/using-measure-in-mlj-to-evaluate-binary-classifier/67025/2 "2021-08-26T16:33:39Z")

</div>

You can make your categorical arrays ordered:

```julia
using MLJ

predStr = categorical(
    ["fast", "fast", "slow"];
    ordered = true,
    levels = ["slow", "fast"]
)

gtStr = categorical(
    ["slow", "fast", "slow"];
    ordered = true,
    levels = ["slow", "fast"]
)

```

```julia
julia> confusion_matrix(predStr, gtStr)
              ┌───────────────────────────┐
              │ Ground Truth │
┌─────────────┼─────────────┬─────────────┤
│ Predicted │ slow │ fast │
├─────────────┼─────────────┼─────────────┤
│ slow │ 1 │ 0 │
├─────────────┼─────────────┼─────────────┤
│ fast │ 1 │ 1 │
└─────────────┴─────────────┴─────────────┘

```

Note that according to the [docstring for ConfusionMatrix](https://alan-turing-institute.github.io/MLJ.jl/dev/performance_measures/#MLJBase.ConfusionMatrix), the first argument should be the predicted values and the second argument should be the true values.

Let’s compare the scientific types of an ordered and an unordered categorical array:

```julia
julia> scitype(predStr)
AbstractVector{OrderedFactor{2}}

julia> scitype(categorical(["a", "b"]))
AbstractVector{Multiclass{2}}

```

Also note that you can make categorical arrays with integers:

```julia
pred = categorical([1, 1, 0]; ordered=true)
gt = categorical([0, 1, 0]; ordered=true)

```

```julia
julia> confusion_matrix(pred, gt)
              ┌───────────────────────────┐
              │ Ground Truth │
┌─────────────┼─────────────┬─────────────┤
│ Predicted │ 0 │ 1 │
├─────────────┼─────────────┼─────────────┤
│ 0 │ 1 │ 0 │
├─────────────┼─────────────┼─────────────┤
│ 1 │ 1 │ 1 │
└─────────────┴─────────────┴─────────────┘

```

---

_[View the full topic](https://discourse.julialang.org/t/using-measure-in-mlj-to-evaluate-binary-classifier/67025)._
