# LIBSVM.jl with imbalanced dataset

**URL:** <https://discourse.julialang.org/t/libsvm-jl-with-imbalanced-dataset/94635>\
**Category:** Machine Learning\
**Tags:** question, machine-learning, libsvm\
**Created:** [February 14, 2023, 4:36pm UTC](https://discourse.julialang.org/t/libsvm-jl-with-imbalanced-dataset/94635 "2023-02-14T16:36:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [February 14, 2023, 4:36pm UTC](https://discourse.julialang.org/t/libsvm-jl-with-imbalanced-dataset/94635/1 "2023-02-14T16:36:47Z")

</div>

I am trying to use [LIBSVM.jl](https://github.com/JuliaML/LIBSVM.jl) with an imbalanced dataset.

Providing weights for each class doesn’t seem to affect the result:

```julia
using CSV
using DataFrames
using LIBSVM

df = CSV.read("svm.csv", DataFrame)

X = [df.x1 df.x2 df.x3]'
y = df.y
w = Dict(l => 1 / count(==(l), y) for l in unique(y))
svm = svmtrain(X, y, weights=w)

x1 = range(-0.5,0.5, length=100)
x2 = range(-0.5,0.5, length=100)
x3 = range(-0.5,0.5, length=100)
xs = [collect(x) for x in Iterators.product(x1,x2,x3)]
X̂ = reduce(hcat, xs)
ŷ, _ = svmpredict(svm, X̂)

```

Can you reproduce the issue? I’ve uploaded the dataset in this gist:

> <https://gist.github.com/juliohm/a0c98c0d386d297e2105818652faa076>
