# Learning Machine Learning (SVM) with Julia

**URL:** <https://discourse.julialang.org/t/learning-machine-learning-svm-with-julia/36083>\
**Category:** Machine Learning\
**Tags:** question, package\
**Created:** [March 17, 2020, 8:01am UTC](https://discourse.julialang.org/t/learning-machine-learning-svm-with-julia/36083 "2020-03-17T08:01:07Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fred](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fred/32/14175_2.png) [@Fred](https://discourse.julialang.org/u/Fred)\
**Post date:** [March 17, 2020, 8:01am UTC](https://discourse.julialang.org/t/learning-machine-learning-svm-with-julia/36083/1 "2020-03-17T08:01:07Z")

</div>

Hi !  
I would like to learn machine learning, SVM in particular. I am a complete newbie and I search few advices from experimented user before starting.  
1- Is it a good idea to learn SVM with Julia or it will be much more complicated than Python or R ?  
2- Do you know a good tutorial for beginner to learn SVM with Julia ?  
3- What SVM package should I choose ? Since I have a level=0 and I am not mathematician I do not have criteria to choose.  
Many thanks for any advice !  
Take care !

---

<div class="post-metadata">

**Author:** ![davidbp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidbp/32/463_2.png) [@davidbp](https://discourse.julialang.org/u/davidbp)\
**Post date:** [March 17, 2020, 8:06am UTC](https://discourse.julialang.org/t/learning-machine-learning-svm-with-julia/36083/2 "2020-03-17T08:06:29Z")

</div>

What do you mean by learn? Use an implementation or fully implement an SVM? If you only want to use an implementation python or R might be easier. If you want to implement it Julia will provide you better tools.

---

<div class="post-metadata">

**Author:** ![Fred](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fred/32/14175_2.png) [@Fred](https://discourse.julialang.org/u/Fred)\
**Post date:** [March 17, 2020, 8:09am UTC](https://discourse.julialang.org/t/learning-machine-learning-svm-with-julia/36083/3 "2020-03-17T08:09:08Z")

</div>

Hi @davidbp I want to use an implementation ready to use. I am unable to implement anything myself at this stage…

---

<div class="post-metadata">

**Author:** ![davidbp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidbp/32/463_2.png) [@davidbp](https://discourse.julialang.org/u/davidbp)\
**Post date:** [March 17, 2020, 8:11am UTC](https://discourse.julialang.org/t/learning-machine-learning-svm-with-julia/36083/4 "2020-03-17T08:11:17Z")

</div>

Probably [MLJ](https://github.com/alan-turing-institute/MLJ.jl) can be useful to you. It’s a package that allows you to use a lot of ML models, in particular you have SVM.

---

<div class="post-metadata">

**Author:** ![Fred](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fred/32/14175_2.png) [@Fred](https://discourse.julialang.org/u/Fred)\
**Post date:** [March 17, 2020, 8:12am UTC](https://discourse.julialang.org/t/learning-machine-learning-svm-with-julia/36083/5 "2020-03-17T08:12:31Z")

</div>

Thank you @davidbp, I will have a look at the tutorials 😉

---

<div class="post-metadata">

**Author:** ![pbayer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pbayer/32/11675_2.png) [@pbayer](https://discourse.julialang.org/u/pbayer)\
**Post date:** [March 17, 2020, 8:13am UTC](https://discourse.julialang.org/t/learning-machine-learning-svm-with-julia/36083/6 "2020-03-17T08:13:58Z")

</div>

did you check [JuliaAcademy](https://juliaacademy.com/courses/) ?

---

<div class="post-metadata">

**Author:** ![Fred](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fred/32/14175_2.png) [@Fred](https://discourse.julialang.org/u/Fred)\
**Post date:** [March 17, 2020, 8:15am UTC](https://discourse.julialang.org/t/learning-machine-learning-svm-with-julia/36083/7 "2020-03-17T08:15:16Z")

</div>

Hi @pbayer, not yet because I did not know what is the best Julia package for a beginner 😉

---

<div class="post-metadata">

**Author:** ![kmundnic](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@kmundnic](https://discourse.julialang.org/u/kmundnic)\
**Post date:** [March 18, 2020, 12:23am UTC](https://discourse.julialang.org/t/learning-machine-learning-svm-with-julia/36083/8 "2020-03-18T00:23:51Z")

</div>

Most implementations of SVM are a wrapper around [LIBSVM](https://www.csie.ntu.edu.tw/~cjlin/libsvm/) (for example, MLJ mentioned above uses [LIBSVM.jl](https://github.com/mpastell/LIBSVM.jl)). If you have experience with any of the languages you mentioned (Julia, Python, R) I would suggest going with that, so that your focus is on learning how to use SVM instead of learning how to use the language to use SVM.

Most importantly, [LIBSVM](https://www.csie.ntu.edu.tw/~cjlin/libsvm/) has a few nice indications on [how to start](https://www.csie.ntu.edu.tw/~cjlin/papers/guide/guide.pdf) (normalizing your data, setting the parameters and so forth), so I think anyways that will be the place to begin.

---

<div class="post-metadata">

**Author:** ![Fred](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fred/32/14175_2.png) [@Fred](https://discourse.julialang.org/u/Fred)\
**Post date:** [March 18, 2020, 7:39am UTC](https://discourse.julialang.org/t/learning-machine-learning-svm-with-julia/36083/9 "2020-03-18T07:39:34Z")

</div>

Thank you very much for your advices @kmundnic !

I use Julia since 0.4 and it is the language I prefer by far 😉 But Julia is also the youngest language compared to R/Python, that is why I asked if Julia is suited for beginner since it will be much more difficult to find tutorials.

I watched the course of Chris Rackauckas in Julia Academy, it is very good for newbies. I will have a look at LIBSVM and see if I understand something.

---

<div class="post-metadata">

**Author:** ![Fred](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fred/32/14175_2.png) [@Fred](https://discourse.julialang.org/u/Fred)\
**Post date:** [March 18, 2020, 2:31pm UTC](https://discourse.julialang.org/t/learning-machine-learning-svm-with-julia/36083/10 "2020-03-18T14:31:27Z")

</div>

This is a feeback of my first attempt to learn SVM  
I read the nice [guide](https://www.csie.ntu.edu.tw/~cjlin/papers/guide/guide.pdf) published in LIBSVM page. Then I tried the example published in LIBSVM.jl webpage and I obtained this result with julia 1.3.1 and LIBSVM v0.4.0 😕

```julia

julia> labels = convert(Vector, iris[:Species])
┌ Warning: `getindex(df::DataFrame, col_ind::ColumnIndex)` is deprecated, use `df[!, col_ind]` instead.
│ caller = top-level scope at REPL[9]:1
└ @ Core REPL[9]:1
150-element Array{CategoricalString{UInt8},1}:
 "setosa"   
 "setosa"       
 "setosa"   
 ⋮          
 "virginica"
 "virginica"
 "virginica"

julia> instances = convert(Array, iris[:, 1:4])'
4×150 LinearAlgebra.Adjoint{Float64,Array{Float64,2}}:
 5.1 4.9 4.7 4.6 5.0 5.4 4.6 5.0 4.4 4.9 … 6.9 5.8 6.8 6.7 6.7 6.3 6.5 6.2 5.9
 3.5 3.0 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 3.1 2.7 3.2 3.3 3.0 2.5 3.0 3.4 3.0
 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 5.1 5.1 5.9 5.7 5.2 5.0 5.2 5.4 5.1
 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 2.3 1.9 2.3 2.5 2.3 1.9 2.0 2.3 1.8

julia> model = svmtrain(instances[:, 1:2:end], labels[1:2:end]);
ERROR: MethodError: no method matching LIBSVM.SupportVectors(::Int32, ::Array{Int32,1}, ::CategoricalArray{String,1,UInt8,String,CategoricalString{UInt8},Union{}}, ::Array{Float64,2}, ::Array{Int32,1}, ::Array{LIBSVM.SVMNode,1})
Closest candidates are:
  LIBSVM.SupportVectors(::Int32, ::Array{Int32,1}, ::Array{T,1}, ::AbstractArray{U,2}, ::Array{Int32,1}, ::Array{LIBSVM.SVMNode,1}) where {T, U} at /home/fred/.julia/packages/LIBSVM/5Z99T/src/LIBSVM.jl:18
  LIBSVM.SupportVectors(::LIBSVM.SVMModel, ::Any, ::Any) at /home/fred/.julia/packages/LIBSVM/5Z99T/src/LIBSVM.jl:27

```

---

<div class="post-metadata">

**Author:** ![kmundnic](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@kmundnic](https://discourse.julialang.org/u/kmundnic)\
**Post date:** [March 18, 2020, 4:38pm UTC](https://discourse.julialang.org/t/learning-machine-learning-svm-with-julia/36083/11 "2020-03-18T16:38:42Z")

</div>

Neither of the examples work. I would recommend submitting an issue on GitHub to let them know.
