# Package for multi label classification

**URL:** https://discourse.julialang.org/t/package-for-multi-label-classification/46156
**Category:** Machine Learning
**Tags:** package
**Created:** [September 6, 2020, 6:43pm UTC](https://discourse.julialang.org/t/package-for-multi-label-classification/46156 "2020-09-06T18:43:26Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Rajeev\_Gangal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rajeev_gangal/32/16467_2.png) [@Rajeev\_Gangal](https://discourse.julialang.org/u/Rajeev_Gangal)
#### Post date: [September 6, 2020, 6:43pm UTC](https://discourse.julialang.org/t/package-for-multi-label-classification/46156/1 "2020-09-06T18:43:26Z")

</div>

What’s the best ML package to use for multi-label classification in Julia? Hopefully, it will have multiple algorithms. Else, do suggest particular packages too. MLJ? Flux? or TensorFlow etc

---

<div class="post-metadata">

### Author: ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)
#### Post date: [September 15, 2021, 1:30pm UTC](https://discourse.julialang.org/t/package-for-multi-label-classification/46156/2 "2021-09-15T13:30:21Z")

</div>

It is now possible to implement multi-label classification in [BetaML](https://github.com/sylvaticus/BetaML.jl), my own ML library, in a easy way using the Neural network module:

```julia
using BetaML # min v0.5.5 due to the new weightless ScalarFunctionLayer

# Creating test data..
X = rand(2000,2)
# note Y is a (2000 x 3) matrix of 0.0/1.0 floats...
Y = hcat(round.(tanh.(0.5 .* X[:,1] + 0.8 .* X[:,2])),
         round.(tanh.(0.5 .* X[:,1] + 0.3 .* X[:,2])),
         round.(tanh.(max.(0.0,-3 .* X[:,1].^2 + 2 * X[:,1] + 0.5 .* X[:,2]))))
# Creating the NN model...
l1 = DenseLayer(2,10,f=relu)
l2 = DenseLayer(10,3,f=relu)
# Needed without weigths as I want to be sure that the input to tanh is positive:
l3 = ScalarFunctionLayer(3,f=tanh)
mynn = buildNetwork([l1,l2,l3],squaredCost,name="Multinomial multilabel regression Model")
# Train of the model...
train!(mynn,X,Y,epochs=100,batchSize=8)
# Predictions...
ŷ = round.(predict(mynn,X))
(nrec,ncat) = size(Y) 
# Just a basic accuracy measure. I could think to extend the ConfusionMatrix measures to multi-label classification if needed..
overallAccuracy = sum(ŷ .== Y)/(nrec*ncat) # 0.988

```

I initially thought on using softmax with a learnable `beta` parameter, but then I realised that such way is not possible: how would the model be able to distinguish between `Y = [0 0 0]` and `Y = [1 1 1]` ? So I ended up with a weighless `tanh` layer preceded by a `relu` function that guarantee me an output in the [0,1] range for each label “independently”, and setting the threshold on 0.5, the value that maximise the loss.

---

<div class="post-metadata">

### Author: ![ToucheSir](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/touchesir/32/14411_2.png) [@ToucheSir](https://discourse.julialang.org/u/ToucheSir)
#### Post date: [September 16, 2021, 5:11pm UTC](https://discourse.julialang.org/t/package-for-multi-label-classification/46156/3 "2021-09-16T17:11:35Z")

</div>

Have a look at [https://github.com/beacon-biosignals/Lighthouse.jl](https://github.com/beacon-biosignals/Lighthouse.jl) and its associated extension packages.
