# \[ANN\] BetaML v0.8: Model defininition, hyperparameters tuning and fitting in 2 lines

**URL:** <https://discourse.julialang.org/t/ann-betaml-v0-8-model-defininition-hyperparameters-tuning-and-fitting-in-2-lines/88119>\
**Category:** Machine Learning\
**Tags:** package, announcement, machine-learning\
**Created:** [October 2, 2022, 11:58am UTC](https://discourse.julialang.org/t/ann-betaml-v0-8-model-defininition-hyperparameters-tuning-and-fitting-in-2-lines/88119 "2022-10-02T11:58:03Z")\
**Posts on this page:** 5\
**Page:** 1

<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:** [October 2, 2022, 11:58am UTC](https://discourse.julialang.org/t/ann-betaml-v0-8-model-defininition-hyperparameters-tuning-and-fitting-in-2-lines/88119/1 "2022-10-02T11:58:04Z")

</div>

Dear all, I’m pleased to announce [BetaML](https://github.com/sylvaticus/BetaML.jl) v0.8.

The **Beta Machine Learning Toolkit** is a package including many algorithms and utilities to implement machine learning workflows in Julia, with a detailed tutorial on its usage [from Python](https://sylvaticus.github.io/BetaML.jl/stable/tutorials/Betaml_tutorial_getting_started.html#Use-BetaML-in-Python) or [R](https://sylvaticus.github.io/BetaML.jl/stable/tutorials/Betaml_tutorial_getting_started.html#Use-BetaML-in-R) (no wrapper packages are needed) and an extensive interface to [MLJ](https://github.com/alan-turing-institute/MLJ.jl).

Aside from the support of the standard `mod = Model([Options])`, `fit!(mod,X,[Y])`, `predict(mod,[X])` paradigm for 22 models (see list below) , this version brings the implementation of one of the easiest hyperparameter tuning functionality available on ML libraries. From model definition, to tuning, fitting and prediction in just 3 lines of code:

```julia
mod = ModelXX(autotune=true) # --> control autotune with the parameter `tunemethod`
fit!(mod,x,[y]) # --> autotune happens here together with final fitting
est = predict(mod,xnew)

```

Autotune is hyperthreaded with model-specific defaults. For example for Random Forests the defaults are:

```julia
tunemethod=SuccessiveHalvingSearch(
    hpranges = Dict("n_trees" => [10, 20, 30, 40],
                     "max_depth" => [5,10,nothing],
                     "min_gain" => [0.0, 0.1, 0.5],
                     "min_records" => [2,3,5],
                     "max_features" => [nothing,5,10,30],
                     "beta" => [0,0.01,0.1]),
    loss = l2loss_by_cv, # works for both regression and classification
    res_shares = [0.08, 0.1, 0.13, 0.15, 0.2, 0.3, 0.4]
    multithreads = false) # RF are already multi-threaded

```

For `SuccessiveHalvingSearch`, the number of models is reduced at each iteration in order to arrive at a single “best” model.  
Only supervised model autotuning is currently implemented, but GMM-based clustering autotuning is planned using `BIC` or `AIC`.

Aside from hyperparameters autotuning, the other release notes are:

- support for all models of the new “V2” API that implements a “standard” `mod = Model([Options])`, `fit!(mod,X,[Y])`, `predict(mod,[X])` workflow (details [here](https://sylvaticus.github.io/BetaML.jl/dev/Api_v2_user.html)). Classic API is now deprecated, with some of its functions be removed in the next BetaML 0.9 versions and some unexported.
- standardised function names to follow the Julia style guidelines and the new BetaML code style guidelines]([Style guide · BetaML.jl Documentation](https://sylvaticus.github.io/BetaML.jl/dev/StyleGuide_templates.html))
- new functions `model_load` and `model_save` to load/save trained models from the filesystem
- new `MinMaxScaler` (`StandardScaler` was already available as classical API functions `scale` and `getScalingFactors`)
- _many_ bugfixes/improvements on corner situations
- new MLJ interface models to `NeuralNetworkEstimator`

All models are coded in Julia and are part of the same package. Currently, `BetaML` includes [22 models implemented](https://sylvaticus.github.io/BetaML.jl/stable/#Available-models(@id-models_list)):

| BetaML name | MLJ Interface | Category |
| --- | --- | --- |
| PerceptronClassifier | LinearPerceptron | _Supervised regressor_ |
| KernelPerceptronClassifier | KernelPerceptron | _Supervised regressor_ |
| PegasosClassifier | Pegasos | _Supervised classifier_ |
| DecisionTreeEstimator | DecisionTreeClassifier, DecisionTreeRegressor | _Supervised regressor and classifier_ |
| RandomForestEstimator | RandomForestClassifier, RandomForestRegressor | _Supervised regressor and classifier_ |
| NeuralNetworkEstimator | NeuralNetworkRegressor, MultitargetNeuralNetworkRegressor, NeuralNetworkClassifier | _Supervised regressor and classifier_ |
| GMMRegressor1 | | _Supervised regressor_ |
| GMMRegressor2 | GaussianMixtureRegressor, MultitargetGaussianMixtureRegressor | _Supervised regressor_ |
| KMeansClusterer | KMeans | _Unsupervised hard clusterer_ |
| KMedoidsClusterer | KMedoids | _Unsupervised hard clusterer_ |
| GMMClusterer | GaussianMixtureClusterer | _Unsupervised soft clusterer_ |
| FeatureBasedImputer | SimpleImputer | _Unsupervised missing data imputer_ |
| GMMImputer | GaussianMixtureImputer | _Unsupervised missing data imputer_ |
| RFImputer | RandomForestImputer | _Unsupervised missing data imputer_ |
| UniversalImputer | GeneralImputer | _Unsupervised missing data imputer_ |
| MinMaxScaler | | _Data transformer_ |
| StandardScaler | | _Data transformer_ |
| Scaler | | _Data transformer_ |
| PCA | | _Data transformer_ |
| OneHotEncoder | | _Data transformer_ |
| OrdinalEncoder | | _Data transformer_ |
| ConfusionMatrix | | _Predictions assessment_ |

Predictions are quite good, often better than the leading packages, although the resource usage is still considerable. You have detailed BetaML tutorials on [classification](https://sylvaticus.github.io/BetaML.jl/stable/tutorials/Classification%20-%20cars/betaml_tutorial_classification_cars.html), [regression](https://sylvaticus.github.io/BetaML.jl/stable/tutorials/Regression%20-%20bike%20sharing/betaml_tutorial_regression_sharingBikes.html) and [clustering](https://sylvaticus.github.io/BetaML.jl/stable/tutorials/Clustering%20-%20Iris/betaml_tutorial_cluster_iris.html) in the [documentation](https://sylvaticus.github.io/BetaML.jl/stable/).

It would be very nice if you could help me in making BetaML more efficient, at least for the models you care about, although the focus remains to provide a tool that is easy to use for everyone.  
If useful, I am happy to transfer the package ownership to an appropriate organisation (this point was raised by @ **[logankilpatrick](https://github.com/logankilpatrick)** and I agree with him).

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [October 2, 2022, 7:49pm UTC](https://discourse.julialang.org/t/ann-betaml-v0-8-model-defininition-hyperparameters-tuning-and-fitting-in-2-lines/88119/2 "2022-10-02T19:49:03Z")

</div>

Great! I didn’t know of this (I guess new):

> Thanks to respectively [PyJulia](https://github.com/JuliaPy/pyjulia) and [JuliaCall](https://github.com/Non-Contradiction/JuliaCall), using BetaML in Python or R is almost as simple as using a native library. In both cases we need first to download and install the Julia binaries for our operating system from [JuliaLang.org](https://julialang.org/).

JuliaCall (of PythonCall.jl) is better since: [Redirecting to https://juliapy.github.io/PythonCall.jl/stable/juliacall/](https://cjdoris.github.io/PythonCall.jl/stable/juliacall/)

> It will automatically download a suitable version of Julia if required.

~~Maybe~~ it works already [EDIT: Of course it should, I believe JuliaCall works for all Julia code; what I had in mind was the other direction, when you make a wrapper for Python, JuliaCll.jl is preferred], or your package can be fixed to support it. It would be nice if RCall (or other package) had/added such auto-download.

---

<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:** [October 2, 2022, 7:57pm UTC](https://discourse.julialang.org/t/ann-betaml-v0-8-model-defininition-hyperparameters-tuning-and-fitting-in-2-lines/88119/4 "2022-10-02T19:57:17Z")

</div>

Gonna look in deepth on this topic as soon I’ll have a pc back on my hands 🙂  
Thanks

---

<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:** [October 2, 2022, 8:16pm UTC](https://discourse.julialang.org/t/ann-betaml-v0-8-model-defininition-hyperparameters-tuning-and-fitting-in-2-lines/88119/5 "2022-10-02T20:16:55Z")

</div>

argh, there is a name conflict here…  
What I tested, and I believe that the text in the tutorial is correct is:

Julia \<-\> Python

Python package PyJulia (“julia” in pip)

Julia \<-\> R

R package `JuliaCall`

Maybe you are right, it is time to test also the python package `JuliaCall`…

---

<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:** [October 3, 2022, 1:56pm UTC](https://discourse.julialang.org/t/ann-betaml-v0-8-model-defininition-hyperparameters-tuning-and-fitting-in-2-lines/88119/6 "2022-10-03T13:56:05Z")

</div>

I merged your pull request and added a section on how to use BetaML with the `JuliaCall` python package, even if it looks still a bit “unripe” to me…
